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): make access level optional for storage APIs #2793

Merged

Conversation

NikaHsn
Copy link
Contributor

@NikaHsn NikaHsn commented Mar 28, 2023

Issue #, if available:

Description of changes:

  • make access level optional for storage APIs
  • defaultAccessLevel can be set by Amplify.Amplify.configure(...) with fallback to guest.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@NikaHsn NikaHsn requested a review from a team as a code owner March 28, 2023 23:38
@@ -99,7 +96,7 @@ class StorageS3Service {
final resolvedPrefix = await getResolvedPrefix(
prefixResolver: _prefixResolver,
logger: _logger,
accessLevel: options.accessLevel,
accessLevel: options.accessLevel ?? _s3PluginConfig.defaultAccessLevel,
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand this ?? if null check is due to Storage<Operation>Options.accessLevel is nullable now, and its default value should be set by the plugin, but this default value has been set here in the StorageS3Dart implementation (where I think it's a proper location).

Hum we can't find a better way than accessLevel: options.accessLevel! we probably need to remove the default value setting from the StorageS3Dart implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using the default value here instead of accessLevel: options.accessLevel! makes the code more robust as we do not rely on callers to set value for nullable field.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. The storage options interface is not appropriate since it has a nullable access level. Either passing a non-null access level as an additional parameter to the service (e.g. resolvedAccessLevel) or handling it inline like this seems fine.

Since other S3 plugin options logic lives here, I think the current handling is appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dnys1 thanks for suggesting the resolvedAccessLevel. I'm more toward handling it inline as there is no logic than checking for null.

@@ -99,7 +96,7 @@ class StorageS3Service {
final resolvedPrefix = await getResolvedPrefix(
prefixResolver: _prefixResolver,
logger: _logger,
accessLevel: options.accessLevel,
accessLevel: options.accessLevel ?? _s3PluginConfig.defaultAccessLevel,
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. The storage options interface is not appropriate since it has a nullable access level. Either passing a non-null access level as an additional parameter to the service (e.g. resolvedAccessLevel) or handling it inline like this seems fine.

Since other S3 plugin options logic lives here, I think the current handling is appropriate.

});

final StorageAccessLevel accessLevel;
final StorageAccessLevel? accessLevel;
Copy link
Contributor

@dnys1 dnys1 Mar 29, 2023

Choose a reason for hiding this comment

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

I might recommend adding the following and using throughout.

StorageAccessLevel resolveAccessLevel({required StorageAccessLevel defaultAccessLevel}) =>
  accessLevel ?? defaultAccessLevel;

@@ -261,7 +263,7 @@ void main() {
});

test(
'should invoke S3Object.listObjectV2 with expected parameters and return expected results with listAll is set to true in the options',
'should invoke S3Object.listObjectV2 with expected parameters and return expected results with listAll and acess level is set to true in the options',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, will update

@@ -390,6 +392,47 @@ void main() {
);
});

test('should invoke S3Client.headObject with default access level',
Copy link
Contributor

Choose a reason for hiding this comment

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

Could update this description a bit, as the default access level actually is not a parameter of the headObject, but used in prefix resolving.

Copy link
Contributor Author

@NikaHsn NikaHsn Apr 3, 2023

Choose a reason for hiding this comment

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

I think the key passed to headObject is prefixed with access level, something like public#object-key, will update the description to make it more clear.

@NikaHsn NikaHsn force-pushed the storage/feat/next/optional-access-level branch from 9c34a1e to 93aa5a7 Compare April 3, 2023 23:52
@NikaHsn NikaHsn force-pushed the storage/feat/next/optional-access-level branch from 93aa5a7 to 31d6697 Compare April 4, 2023 17:57
@NikaHsn NikaHsn merged commit cc89780 into aws-amplify:next Apr 4, 2023
22 checks passed
@NikaHsn NikaHsn deleted the storage/feat/next/optional-access-level branch April 4, 2023 18:27
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.

None yet

3 participants