-
Notifications
You must be signed in to change notification settings - Fork 199
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): Implementing support for multiple buckets #3817
Merged
ruisebas
merged 3 commits into
feature/multibucket-storage
from
ruisebas/storagebucket_apis
Aug 19, 2024
Merged
feat(Storage): Implementing support for multiple buckets #3817
ruisebas
merged 3 commits into
feature/multibucket-storage
from
ruisebas/storagebucket_apis
Aug 19, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruisebas
changed the title
Ruisebas/storagebucket apis
feat(Storage): Implementing support for multiple buckets
Aug 15, 2024
API Breakage Report✅ No Public API Breaking Change detected |
phantumcode
reviewed
Aug 16, 2024
AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/AWSS3StoragePlugin+StorageBucket.swift
Show resolved
Hide resolved
phantumcode
reviewed
Aug 16, 2024
AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/AWSS3StoragePlugin.swift
Show resolved
Hide resolved
phantumcode
reviewed
Aug 16, 2024
} | ||
|
||
/// The default bucket | ||
var defaultBucket: ResolvedStorageBucket! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to avoid unsafe unwrapping?
phantumcode
reviewed
Aug 16, 2024
AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/AWSS3StoragePlugin.swift
Show resolved
Hide resolved
phantumcode
reviewed
Aug 16, 2024
...Plugins/Storage/Sources/AWSS3StoragePlugin/Service/Storage/AWSS3StorageServiceBehavior.swift
Show resolved
Hide resolved
phantumcode
approved these changes
Aug 16, 2024
9 tasks
ruisebas
added a commit
that referenced
this pull request
Aug 27, 2024
ruisebas
added a commit
that referenced
this pull request
Sep 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR makes the main changes in order to add support for multiple buckets to our existing Storage implementation.
The main changes are the following:
AmplifyOutputsData
Added the new optional
buckets
array to the Storage configuration, plus a convenience initializer for testing purposes.AWSS3StoragePlugin
We have pretty much all of the service-related logic encapsulated inside the
AWSS3StorageServiceBehavior
protocol, which is implemented byAWSS3StorageService
. This implementation, along its many related objects, heavily relies on the assumption of only one bucket and region.To avoid a complete refactor, we will now have one storage service per bucket. S3 bucket names are globally unique, so we can store them in a dictionary using the bucket name as key for easy retrieval.
On plugin configuration we will only instantiate the "default" storage service, keeping the existing behaviour. We will only instantiate new services (and store them in the dictionary) when required, to prevent unnecessary memory usage if a customer has many buckets in their configuration but never attempts any Storage operation on most of them.
I've also added an optional
additionalBucketsByName
dictionary that is set when Amplify is configured withAmplifyOutputs
. This is needed because we need to be able to perform the bucket lookup when the customer provides aStorageBucket.fromOutputs(:)
bucket.Finally, i've changed the type of
authService
to beAWSAuthCredentialsProviderBehavior
. This was an oversight during theAmplifyCredentials
refactor, but it's not a breaking change becauseAWSAuthService
conforms to both.AWSS3Storage<*>Operation
The APIs for uploading and downloading do not directly throw errors, instead they return an
AmplifyTask
that can be used to monitor progress and completion.Since retrieving the storage service can throw (e.g. if a wrong bucket name is passed), and the operations need a service in order to execute, I've created the
AWSS3StorageServiceProvider
callback that can throw. We can invoke this provider when the operation is actually running, since we can report errors by then.StorageConfiguration
I've removed the
.default
static property and instead crated a new.init(forBucket:)
that just appends it to the defaultsessionIdentifier
in order for it to be unique. This was needed because otherwise the URLSession delegate methods were not being reported to the proper storage service, which made it impossible to properly propagate the results.General Checklist
Given When Then
inline code documentation and are named accordinglytestThing_condition_expectation()
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.