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): getProperties API #11378

Merged
merged 24 commits into from
May 22, 2023

Conversation

kvramyasri7
Copy link
Contributor

Description of changes

This api enables users to retrieve properties of object from storage.

Issue #, if available

#6830
#1550

Description of how you validated changes

Tested with a sample app and added unit test cases

Checklist

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

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

@codecov-commenter
Copy link

codecov-commenter commented May 16, 2023

Codecov Report

Merging #11378 (eea6590) into main (58a26dc) will increase coverage by 0.00%.
The diff coverage is 91.66%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@           Coverage Diff           @@
##             main   #11378   +/-   ##
=======================================
  Coverage   82.99%   82.99%           
=======================================
  Files         240      240           
  Lines       20163    20179   +16     
  Branches     4355     4358    +3     
=======================================
+ Hits        16734    16748   +14     
- Misses       3142     3144    +2     
  Partials      287      287           
Impacted Files Coverage Δ
packages/storage/src/providers/AWSS3Provider.ts 91.41% <85.71%> (-0.48%) ⬇️
packages/storage/src/Storage.ts 97.97% <100.00%> (-0.16%) ⬇️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@kvramyasri7 kvramyasri7 marked this pull request as ready for review May 17, 2023 15:13
@kvramyasri7 kvramyasri7 requested a review from a team as a code owner May 17, 2023 15:13
Copy link
Contributor

@jimblanc jimblanc left a comment

Choose a reason for hiding this comment

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

Looks good! One comment below about SSE support.

packages/storage/src/providers/AWSS3Provider.ts Outdated Show resolved Hide resolved
const s3 = this._createNewS3Client(opt, emitter);
logger.debug('getProperties ' + key + ' from ' + final_key);

const params: HeadObjectCommandInput = {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this API should support SSE to align with the other APIs (HeadObject command supports it it looks like). It would be strange if you can upload/download SSE-enabled objects but can't get the meta-data for them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added SSE support!

packages/storage/src/Storage.ts Outdated Show resolved Hide resolved
packages/storage/src/Storage.ts Outdated Show resolved Hide resolved
packages/storage/src/types/AWSS3Provider.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

It looks good to me generally and have minor comments in for the test. I think we need to confirm whether SSE parameters can be omitted before merging it.

AllanZhengYP
AllanZhengYP previously approved these changes May 17, 2023
Copy link
Contributor

@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.

🚀🚀🚀

config?: StorageGetPropertiesConfig<T>
): StorageGetPropertiesOutput<T> {
const provider = config?.provider || DEFAULT_PROVIDER;
const prov = this._pluggables.find(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: prov can be made more descriptive? Also there seems to be a util function to get the provider.

AllanZhengYP
AllanZhengYP previously approved these changes May 18, 2023
Copy link
Contributor

@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.

🚢🚢🚢

Comment on lines 746 to 748
await storage.put('key', 'test upload');
} catch (err) {
expect(err).toEqual('No plugin found in Storage for the provider');
expect(err).toEqual(new Error('No plugin found with providerName'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It would be a little cleaner (here and elsewhere) to test failure modes like this:

await expect(storage.put('key', 'test upload')).rejects.toThrow(new Error('No plugin found with providerName'));

return null;
throw new Error('No plugin found with providerName');
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach makes sense and is cleaner, but I'm just worried if this might constitute a breaking change on a public API surface for folks who may have implemented their own providers or be using this method directly in some non-standard ward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's a valid point. Thanks.

Comment on lines 251 to 259
const prov = this._pluggables.find(
pluggable => pluggable.getProviderName() === provider
);
if (prov === undefined) {
logger.debug('No plugin found with providerName', provider);
return Promise.reject(
'No plugin found in Storage for the provider'
) as StorageCopyOutput<T>;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for cleaning this up!

Copy link
Contributor

@jimblanc jimblanc left a comment

Choose a reason for hiding this comment

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

LGTM, nice work

@kvramyasri7 kvramyasri7 merged commit 3bed12b into aws-amplify:main May 22, 2023
2 checks passed
jimblanc added a commit to jimblanc/amplify-js that referenced this pull request May 26, 2023
erinleigh90 added a commit that referenced this pull request May 26, 2023
* chore(release): Publish [ci skip]

 - aws-amplify@5.2.3
 - @aws-amplify/datastore-storage-adapter@2.0.33
 - @aws-amplify/datastore@4.4.0
 - @aws-amplify/predictions@5.2.0
 - @aws-amplify/storage@5.3.0

* chore(release): update API docs [ci skip]

* fix(notifications): Add babel plugins to devDependencies (#11414)

* fix(storage): make getProperties param optional (#11413)

* Revert "fix(storage): make getProperties param optional (#11413)"

This reverts commit 5d00b1f.

* Revert "feat(storage): getProperties API (#11378)"

This reverts commit 3bed12b.

---------

Co-authored-by: israx <70438514+israx@users.noreply.github.com>
Co-authored-by: aws-amplify-bot <aws@amazon.com>
Co-authored-by: Chris F <5827964+cshfang@users.noreply.github.com>
Co-authored-by: Jim Blanchard <jablanch@amazon.com>
Co-authored-by: Jim Blanchard <jim.l.blanchard@gmail.com>
erinleigh90 added a commit that referenced this pull request May 29, 2023
* chore(release): Publish [ci skip]

 - aws-amplify@5.2.3
 - @aws-amplify/datastore-storage-adapter@2.0.33
 - @aws-amplify/datastore@4.4.0
 - @aws-amplify/predictions@5.2.0
 - @aws-amplify/storage@5.3.0

* chore(release): update API docs [ci skip]

* fix(notifications): Add babel plugins to devDependencies (#11414)

* fix(storage): make getProperties param optional (#11413)

* Revert "fix(storage): make getProperties param optional (#11413)"

This reverts commit 5d00b1f.

* Revert "feat(storage): getProperties API (#11378)"

This reverts commit 3bed12b.

* fix(core): bundle react-native-url-polyfill to unblock jest test failure (#11422)

* fix(core): bundle react-native-url-polyfill to unblock jest test failure

* Revert "test(notification): unblock unit test failure of rn url polyfill"

This reverts commit dbacebc.

* chore: remove unused code

* chore: remove unused polyfills/URL/package.json

* chore(release): Publish [ci skip]

 - @aws-amplify/analytics@6.1.1
 - @aws-amplify/api-graphql@3.2.1
 - @aws-amplify/api-rest@3.1.1
 - @aws-amplify/api@5.1.1
 - @aws-amplify/auth@5.3.7
 - aws-amplify@5.2.4
 - @aws-amplify/cache@5.0.33
 - @aws-amplify/core@5.3.1
 - @aws-amplify/datastore-storage-adapter@2.0.34
 - @aws-amplify/datastore@4.4.1
 - @aws-amplify/geo@2.0.33
 - @aws-amplify/interactions@5.0.33
 - @aws-amplify/notifications@1.1.7
 - @aws-amplify/predictions@5.2.1
 - @aws-amplify/pubsub@5.1.16
 - @aws-amplify/pushnotification@5.0.33
 - @aws-amplify/storage@5.3.1

* chore(release): update API docs [ci skip]

---------

Co-authored-by: israx <70438514+israx@users.noreply.github.com>
Co-authored-by: aws-amplify-bot <aws@amazon.com>
Co-authored-by: Chris F <5827964+cshfang@users.noreply.github.com>
Co-authored-by: Jim Blanchard <jablanch@amazon.com>
Co-authored-by: Jim Blanchard <jim.l.blanchard@gmail.com>
Co-authored-by: AllanZhengYP <zheallan@amazon.com>
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

6 participants