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): internal GetProperties API #13869

Conversation

AllanZhengYP
Copy link
Member

@AllanZhengYP AllanZhengYP commented Sep 30, 2024

Description of changes

Following changes are made as part of this PR:

  • Remove the locationCredentialsProvider option from the public API input options' common interface:
  • Add a separate getProperties API exported from @aws-amplify/storage/internals path that contains locationCredentialsProvider option. The resolving logic is unchanged.

Issue #, if available

Description of how you validated changes

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.

…Is and add it to separate internal API; Internal getProperties implementation
@AllanZhengYP AllanZhengYP changed the title feat(storage): remove locationCredentialsProvider option in public AP… feat(storage): remove locationCredsProvider option in public APIs Sep 30, 2024
@AllanZhengYP AllanZhengYP changed the title feat(storage): remove locationCredsProvider option in public APIs feat(storage): move locationCredsProvider option from public APIs Sep 30, 2024
Co-authored-by: Jim Blanchard <[email protected]>
@AllanZhengYP AllanZhengYP force-pushed the storage-browser/internal-get-properties branch from 3239e6b to 0c367c0 Compare October 1, 2024 17:10
@AllanZhengYP AllanZhengYP force-pushed the storage-browser/internal-get-properties branch from 5814597 to 7860519 Compare October 1, 2024 17:48
@AllanZhengYP AllanZhengYP marked this pull request as ready for review October 1, 2024 17:49
@AllanZhengYP AllanZhengYP changed the title feat(storage): move locationCredsProvider option from public APIs feat(storage): internal GetProperties API Oct 1, 2024
jimblanc
jimblanc previously approved these changes Oct 1, 2024
Co-authored-by: Jim Blanchard <[email protected]>
path: InputType['path'];
options?: PublicInputOptionsType & ExtendedOptionsType;
}
: InputType extends StorageCopyInputWithPath
Copy link
Member

Choose a reason for hiding this comment

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

It always falls back to check this Copy Input type StorageCopyInputWithPath? Isn't this type ExtendInputWithAdvancedOptions a generic one used for multiple APIs?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah copy API signature is different any other Storage APIs. That's why I check the copy input interface explicitly. Here copy is the only API that does not extend from StorageOperationInputWithPath

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 split the copy logic out and explicitly define it when it comes to copy? Will make the whole thing read much simpler IMO

jest.mock('../../../src/providers/s3/apis/internal/getProperties');
const mockedGetPropertiesInternal = jest.mocked(getPropertiesInternal);

describe('getProperties (internal)', () => {
Copy link
Member

Choose a reason for hiding this comment

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

this is getting confusing 😅

@@ -44,7 +58,7 @@ const storageBucketAssertion = (

export const copy = async (
amplify: AmplifyClassV6,
input: CopyInput | CopyWithPathInput,
input: CopyInput | InputWithPathAndAdvancedOptions,
Copy link
Member

Choose a reason for hiding this comment

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

why not CopyWithPathInputAndAdvancedOptions?

Copy link
Member

Choose a reason for hiding this comment

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

Same for other places as well.

/**
* @internal
*/
export type GetPropertiesInput = ExtendInputWithAdvancedOptions<
Copy link
Member

Choose a reason for hiding this comment

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

Im confused here. Why are we creating this and not using this type? but rather have a duplicate again here?

Copy link
Member

Choose a reason for hiding this comment

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

+1, we should keep types as simple as we can, and avoid type programming as much as we can 😅 when we deprecating the key use cases, it should just simple splitting and deleting.

Copy link
Member Author

@AllanZhengYP AllanZhengYP Oct 2, 2024

Choose a reason for hiding this comment

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

@ashika112 I think I was debating all the different conventions, GetPropertiesInput name cannot be referred as-is in the other places. I can change to use this definition everywhere.

path: InputType['path'];
options?: PublicInputOptionsType & ExtendedOptionsType;
}
: InputType extends StorageCopyInputWithPath
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 split the copy logic out and explicitly define it when it comes to copy? Will make the whole thing read much simpler IMO

packages/storage/src/internals/types/inputs.ts Outdated Show resolved Hide resolved
InputType extends StorageOperationInputWithPath &
StorageOperationOptionsInput<infer PublicInputOptionsType>
? {
path: InputType['path'];
Copy link
Member

Choose a reason for hiding this comment

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

What about key? Not supporting it here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, we only support Gen2 signature with extended option.

/**
* @internal
*/
export type GetPropertiesInput = ExtendInputWithAdvancedOptions<
Copy link
Member

Choose a reason for hiding this comment

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

+1, we should keep types as simple as we can, and avoid type programming as much as we can 😅 when we deprecating the key use cases, it should just simple splitting and deleting.

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

@@ -21,6 +25,16 @@ import { assertValidationError } from '../../../../errors/utils/assertValidation
import { copyObject } from '../../utils/client/s3data';
import { getStorageUserAgentValue } from '../../utils/userAgent';
import { logger } from '../../../../utils';
// TODO: Remove this interface when we move to public advanced APIs.
import { ExtendInputWithAdvancedOptions } from '../../../../internals/types/inputs';
Copy link
Member

Choose a reason for hiding this comment

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

thx love these TODO items

Comment on lines +20 to +33
export function getProperties(
input: GetPropertiesInput,
): Promise<GetPropertiesOutput> {
return getPropertiesInternal(Amplify, {
path: input.path,
options: {
useAccelerateEndpoint: input?.options?.useAccelerateEndpoint,
bucket: input?.options?.bucket,
locationCredentialsProvider: input?.options?.locationCredentialsProvider,
},
// Type casting is necessary because `getPropertiesInternal` supports both Gen1 and Gen2 signatures, but here
// given in input can only be Gen2 signature, the return can only ben Gen2 signature.
}) as Promise<GetPropertiesOutput>;
}
Copy link
Member

Choose a reason for hiding this comment

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

super nit,

Suggested change
export function getProperties(
input: GetPropertiesInput,
): Promise<GetPropertiesOutput> {
return getPropertiesInternal(Amplify, {
path: input.path,
options: {
useAccelerateEndpoint: input?.options?.useAccelerateEndpoint,
bucket: input?.options?.bucket,
locationCredentialsProvider: input?.options?.locationCredentialsProvider,
},
// Type casting is necessary because `getPropertiesInternal` supports both Gen1 and Gen2 signatures, but here
// given in input can only be Gen2 signature, the return can only ben Gen2 signature.
}) as Promise<GetPropertiesOutput>;
}
export const getProperties = (
input: GetPropertiesInput
): Promise<GetPropertiesOutput> =>
getPropertiesInternal(Amplify, {
path: input.path,
options: {
useAccelerateEndpoint: input?.options?.useAccelerateEndpoint,
bucket: input?.options?.bucket,
locationCredentialsProvider: input?.options?.locationCredentialsProvider,
},
// Type casting is necessary because `getPropertiesInternal` supports both Gen1 and Gen2 signatures, but here
// given in input can only be Gen2 signature, the return can only ben Gen2 signature.
}) as Promise<GetPropertiesOutput>;

@AllanZhengYP AllanZhengYP merged commit 287d0e5 into aws-amplify:storage-browser/integrity Oct 2, 2024
28 checks passed
@AllanZhengYP AllanZhengYP deleted the storage-browser/internal-get-properties branch October 2, 2024 20:44
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.

7 participants