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

feat(storage): introduce preventOverwrite option to uploadData via HeadObject #13640

Conversation

eppjame
Copy link

@eppjame eppjame commented Jul 24, 2024

Description of changes

  • Create common validation for checking if target key already exists (via HeadObject)
  • Introduce new uploadData option preventOverwrite, and invoke above validation when it is enabled

Issue #, if available

  • No associated issue

Description of how you validated changes

  • Using StorageManager component in a sample app

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@eppjame eppjame requested review from a team as code owners July 24, 2024 16:12
AllanZhengYP
AllanZhengYP previously approved these changes Jul 24, 2024
Copy link
Member

@AllanZhengYP AllanZhengYP left a comment

Choose a reason for hiding this comment

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

Thank you @eppjame!
The change looks good to me. I just have a few sanity check questions.

@@ -107,6 +109,13 @@ export const getMultipartUploadHandlers = (
resolvedAccessLevel = resolveAccessLevel(accessLevel);
}

if (preventOverwrite) {
Copy link
Member

@AllanZhengYP AllanZhengYP Jul 24, 2024

Choose a reason for hiding this comment

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

Does it make more sense to be called right before calling complete MPU API?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that has a better chance of catching recent uploads. Updated.

try {
await headObject(s3Config, input);

throw new StorageError({
Copy link
Member

Choose a reason for hiding this comment

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

so this error gets thrown only when target key is already present? Can we be more clear on the error message? or is there more than that we check for here?

Copy link
Member

Choose a reason for hiding this comment

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

I'll defer this quetion to @eppjame but one advantage of making the message generic is to prevent users to enumerate the resources and gain knowledge about the bucket.

await headObject(s3Config, input);

throw new StorageError({
name: 'PreconditionFailed',
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 get this value as const value? — In case we are unit testing this specific error we would refer to the variable instead of the plain text.

@AllanZhengYP AllanZhengYP merged commit 0b1ec2e into aws-amplify:storage-browser/integrity Jul 24, 2024
28 checks passed
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.

4 participants