-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(storage): add new internal remove api #13880
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
Merged
ashwinkumar6
merged 1 commit into
aws-amplify:storage-browser/integrity
from
ashwinkumar6:storage-browser/internal/remove
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,59 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { AmplifyClassV6 } from '@aws-amplify/core'; | ||
|
||
import { remove as advancedRemove } from '../../../src/internals'; | ||
import { remove as removeInternal } from '../../../src/providers/s3/apis/internal/remove'; | ||
|
||
jest.mock('../../../src/providers/s3/apis/internal/remove'); | ||
const mockedRemoveInternal = jest.mocked(removeInternal); | ||
|
||
describe('remove (internal)', () => { | ||
beforeEach(() => { | ||
mockedRemoveInternal.mockResolvedValue({ | ||
path: 'output/path/to/mock/object', | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should pass advanced option locationCredentialsProvider to internal remove', 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 advancedRemove({ | ||
path: 'input/path/to/mock/object', | ||
options: { | ||
useAccelerateEndpoint, | ||
bucket, | ||
locationCredentialsProvider, | ||
}, | ||
}); | ||
|
||
expect(mockedRemoveInternal).toHaveBeenCalledTimes(1); | ||
expect(mockedRemoveInternal).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 hidden or 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,30 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Amplify } from '@aws-amplify/core'; | ||
|
||
import { remove as removeInternal } from '../../providers/s3/apis/internal/remove'; | ||
import { RemoveInput } from '../types/inputs'; | ||
import { RemoveOutput } from '../types/outputs'; | ||
|
||
/** | ||
* Remove a file from your S3 bucket. | ||
* @param input - The `RemoveWithPathInput` object. | ||
* @return Output containing the removed object path. | ||
* @throws service: `S3Exception` - S3 service errors thrown while while removing the object. | ||
* @throws validation: `StorageValidationErrorCode` - Validation errors thrown | ||
* when there is no path or path is empty or path has a leading slash. | ||
* | ||
* @internal | ||
*/ | ||
export const remove = (input: RemoveInput): Promise<RemoveOutput> => | ||
removeInternal(Amplify, { | ||
path: input.path, | ||
options: { | ||
useAccelerateEndpoint: input?.options?.useAccelerateEndpoint, | ||
bucket: input?.options?.bucket, | ||
locationCredentialsProvider: input?.options?.locationCredentialsProvider, | ||
}, | ||
// Type casting is necessary because `removeInternal` 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<RemoveOutput>; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.