-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): internal GetProperties API (#13869)
--------- Co-authored-by: Jim Blanchard <jim.l.blanchard@gmail.com>
- Loading branch information
1 parent
1eab7e0
commit 287d0e5
Showing
9 changed files
with
172 additions
and
20 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
packages/storage/__tests__/internals/apis/getProperties.test.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { AmplifyClassV6 } from '@aws-amplify/core'; | ||
|
||
import { getProperties as advancedGetProperties } from '../../../src/internals'; | ||
import { getProperties as getPropertiesInternal } from '../../../src/providers/s3/apis/internal/getProperties'; | ||
|
||
jest.mock('../../../src/providers/s3/apis/internal/getProperties'); | ||
const mockedGetPropertiesInternal = jest.mocked(getPropertiesInternal); | ||
|
||
describe('getProperties (internal)', () => { | ||
beforeEach(() => { | ||
mockedGetPropertiesInternal.mockResolvedValue({ | ||
path: 'output/path/to/mock/object', | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should pass advanced option locationCredentialsProvider to internal getProperties', async () => { | ||
const useAccelerateEndpoint = true; | ||
const bucket = { bucketName: 'bucket', region: 'us-east-1' }; | ||
const locationCredentialsProvider = async () => ({ | ||
credentials: { | ||
accessKeyId: 'akid', | ||
secretAccessKey: 'secret', | ||
sessionToken: 'token', | ||
expiration: new Date(), | ||
}, | ||
}); | ||
const result = await advancedGetProperties({ | ||
path: 'input/path/to/mock/object', | ||
options: { | ||
useAccelerateEndpoint, | ||
bucket, | ||
locationCredentialsProvider, | ||
}, | ||
}); | ||
expect(mockedGetPropertiesInternal).toHaveBeenCalledTimes(1); | ||
expect(mockedGetPropertiesInternal).toHaveBeenCalledWith( | ||
expect.any(AmplifyClassV6), | ||
{ | ||
path: 'input/path/to/mock/object', | ||
options: { | ||
useAccelerateEndpoint, | ||
bucket, | ||
locationCredentialsProvider, | ||
}, | ||
}, | ||
); | ||
expect(result).toEqual({ | ||
path: 'output/path/to/mock/object', | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Amplify } from '@aws-amplify/core'; | ||
|
||
import { getProperties as getPropertiesInternal } from '../../providers/s3/apis/internal/getProperties'; | ||
import { GetPropertiesInput } from '../types/inputs'; | ||
import { GetPropertiesOutput } from '../types/outputs'; | ||
|
||
/** | ||
* Gets the properties of a file. The properties include S3 system metadata and | ||
* the user metadata that was provided when uploading the file. | ||
* @param input - The `GetPropertiesWithPathInput` object. | ||
* @returns Requested object properties. | ||
* @throws An `S3Exception` when the underlying S3 service returned error. | ||
* @throws A `StorageValidationErrorCode` when API call parameters are invalid. | ||
* | ||
* @internal | ||
*/ | ||
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>; | ||
} |
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
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
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
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
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
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
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