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): Adding subpath strategy to the List operation #3775

Merged
merged 3 commits into from
Jul 18, 2024

Conversation

sebaland
Copy link
Member

@sebaland sebaland commented Jul 11, 2024

Description

This PR introduces the subpathStrategy parameter to StorageListRequest.Options and its corresponding SubpathStrategy enum type.

Using this field will affect the results included in the response:

  • subpathStrategy: .include: Objects that are included in nested subpaths will be included in the response. This is the default behaviour
  • subpathStrategy: .exclude: Objects that are included in nested subpaths are not included in the response, instead their subpaths are included in the excludedSubpaths list.
  • subpathStrategy: .exclude(delimitedBy:): Same as above, but it allows to set a custom character as delimiter for subpaths. The delimiter parameter defaults to "/", which is the same as .exclude.

General Checklist

  • Added new tests to cover change, if needed
  • Build succeeds with all target using Swift Package Manager
  • All unit tests pass
  • All integration tests pass
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Documentation update for the change if required
  • PR title conforms to conventional commit style
  • New or updated tests include Given When Then inline code documentation and are named accordingly testThing_condition_expectation()
  • If breaking change, documentation/changelog update with migration instructions

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

@sebaland sebaland marked this pull request as ready for review July 16, 2024 20:08
@sebaland sebaland requested a review from a team as a code owner July 16, 2024 20:08
@sebaland sebaland temporarily deployed to IntegrationTest July 17, 2024 15:22 — with GitHub Actions Inactive
@sebaland sebaland temporarily deployed to IntegrationTest July 17, 2024 15:22 — with GitHub Actions Inactive
@sebaland sebaland temporarily deployed to IntegrationTest July 17, 2024 15:22 — with GitHub Actions Inactive
Copy link
Member

@harsh62 harsh62 left a comment

Choose a reason for hiding this comment

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

LGTM


// Upload data
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "-test"), data: data, options: nil).value
_ = try await Amplify.Storage.uploadData(path: .fromString(uniqueStringPath + "-subpath-test"), data: data, options: nil).value
Copy link
Member

Choose a reason for hiding this comment

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

what happens when the subpath is --subpath-test ?

Copy link
Member Author

@sebaland sebaland Jul 18, 2024

Choose a reason for hiding this comment

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

In that case, the excluded subpath will be public/[UUID]--


From the S3 perspective, here's how it works. You have these objects:

public/[UUID]-test
public/[UUID]--subpath-test

You filter everything that starts with the prefix public/[UUID]-, and both objects still match:

public/[UUID]-test
public/[UUID]--subpath-test 

But since you set the delimiter to -, any object that contains it after the given prefix is gets rolled up until that character. So public/[UUID]--subpath-test is rolled up to the public/[UUID]-- common prefix, because the - character is the very next character after the prefix.
This value is then reported as an excludedSubpath by Amplify.

Copy link
Member

@thisisabhash thisisabhash left a comment

Choose a reason for hiding this comment

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

minor comment

@sebaland sebaland merged commit bd5e6bf into main Jul 18, 2024
85 checks passed
@sebaland sebaland deleted the ruisebas/storage-delimiter-list branch July 18, 2024 17:42
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.

3 participants