Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds method to create image v2 direct upload url #1308

Closed
wants to merge 10 commits into from
Closed

adds method to create image v2 direct upload url #1308

wants to merge 10 commits into from

Conversation

bbbshah
Copy link
Contributor

@bbbshah bbbshah commented Jun 14, 2023

This PR implements the missing feature to support images/v2/direct_upload
endpoint that lets client create direct upload url. The v2 version supports
metadata and requireSignedURLs as additional request parameters.

Description

Since the v2 request supports metadata and requireSignedURLs,
a new struct ImageDirectUploadURLV2Request is added to images.go.
This struct is then passed as a param to CreateImageDirectUploadURLV2

Closes #1248

Has your change been tested?

Added a unit test for the newly added function. Also tested against a golang
client to create direct upload url with metatadata and requireSignedURLs,
and verified the uploaded image was private and retained all the metadata.

Types of changes

What sort of change does your code introduce/modify?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • This change is using publicly documented in cloudflare/api-schemas
    and relies on stable APIs.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 14, 2023

changelog detected ✅

@bbbshah bbbshah marked this pull request as ready for review June 16, 2023 13:29
images.go Outdated
// CreateImageDirectUploadURLV2 creates an authenticated v2 direct upload url.
//
// API Reference: https://developers.cloudflare.com/api/operations/cloudflare-images-create-authenticated-direct-upload-url-v-2
func (api *API) CreateImageDirectUploadURLV2(ctx context.Context, accountID string, params ImageDirectUploadURLV2Request) (ImageDirectUploadURL, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update this to align with the library conventions (link)?

i don't love this method name but due to the version existing in the URL, we don't really have much else to offer here. i'll chat with the team internally and see what we can do here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...maybe a Version field on the params struct that toggles the URL and we roll this into the existing create method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CreateImageDirectUploadURLV2 method is significantly different from the existing method and may result into a series of if/else blocks and extracted private methods specific to each version. The request payload is also different between the two versions. The current proposed changes seems like the most clean way to do this. I'm open to other suggestions?

I've updated ImageDirectUploadURLV2Request with library conventions to use pointers for bool and time.Time. Was there anything else you wanted to change to meet the conventions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't want V1/V2/V3 as part of the method call since that should be abstracted from end users and they should just be able to configure/control the method as needed instead. i'm fine with private methods that we invoke from inside the shared method with a specific comment documenting it.

as for the library conventions, it looks like the only one missing is the second parameter should be ResourceContainer, not string accountID.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the input, i've made necessary changes. I ended up keeping all the implementation in the same function to keep it simple for now. Also updated the second parameter to by ResourceContainer instead of string. Let me know if there are other changes needed.

@codecov-commenter
Copy link

Codecov Report

Merging #1308 (9ca441b) into master (74e0b34) will decrease coverage by 0.53%.
The diff coverage is 73.10%.

@@            Coverage Diff             @@
##           master    #1308      +/-   ##
==========================================
- Coverage   48.95%   48.42%   -0.53%     
==========================================
  Files         135      133       -2     
  Lines       13180    12974     -206     
==========================================
- Hits         6452     6283     -169     
+ Misses       5212     5173      -39     
- Partials     1516     1518       +2     
Impacted Files Coverage Δ
access_audit_log.go 79.31% <0.00%> (ø)
device_posture_rule.go 61.80% <ø> (ø)
options.go 61.01% <ø> (-3.05%) ⬇️
teams_devices.go 52.63% <ø> (ø)
dns_firewall.go 7.69% <10.00%> (-13.74%) ⬇️
tunnel.go 42.41% <66.66%> (+1.01%) ⬆️
images.go 54.83% <70.73%> (+4.49%) ⬆️
access_policy.go 70.27% <73.33%> (-6.05%) ⬇️
access_application.go 72.72% <75.47%> (-3.80%) ⬇️
access_mutual_tls_certificates.go 68.86% <75.51%> (-3.36%) ⬇️
... and 9 more

... and 1 file with indirect coverage changes

@jacobbednarz
Copy link
Member

i moved this to #1322 because your fork didn't allow maintainers to make edits.

@bbbshah bbbshah deleted the feature/images-v2-direct-upload branch June 30, 2023 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image direct upload V2
3 participants