From 2a9053f797decf58798d2a101970e906241f249a Mon Sep 17 00:00:00 2001 From: Jim Blanchard Date: Thu, 17 Oct 2024 11:56:01 -0500 Subject: [PATCH] feat: Add expectedBucketOwner to remaining internal APIs (#13932) feat: Add expectedBucketOwner to remaining internal APIs. --- .../__tests__/internals/apis/copy.test.ts | 2 ++ .../internals/apis/downloadData.test.ts | 3 ++ .../internals/apis/getProperties.test.ts | 3 ++ .../__tests__/internals/apis/getUrl.test.ts | 3 ++ .../__tests__/internals/apis/list.test.ts | 3 ++ .../__tests__/internals/apis/remove.test.ts | 3 ++ .../internals/apis/uploadData.test.ts | 3 ++ packages/storage/src/internals/apis/copy.ts | 2 ++ .../src/internals/apis/downloadData.ts | 30 +------------------ .../src/internals/apis/getProperties.ts | 7 ----- packages/storage/src/internals/apis/getUrl.ts | 1 + packages/storage/src/internals/apis/list.ts | 1 + packages/storage/src/internals/apis/remove.ts | 8 +---- .../storage/src/internals/apis/uploadData.ts | 1 + 14 files changed, 27 insertions(+), 43 deletions(-) diff --git a/packages/storage/__tests__/internals/apis/copy.test.ts b/packages/storage/__tests__/internals/apis/copy.test.ts index ad1b0d43da4..f7fc957cae7 100644 --- a/packages/storage/__tests__/internals/apis/copy.test.ts +++ b/packages/storage/__tests__/internals/apis/copy.test.ts @@ -31,10 +31,12 @@ describe('copy (internals)', () => { bucket: 'bucket', eTag: 'eTag', notModifiedSince: new Date(), + expectedBucketOwner: '012345678901', }, destination: { path: 'path/to/object', bucket: 'bucket', + expectedBucketOwner: '212345678901', }, options: { locationCredentialsProvider, diff --git a/packages/storage/__tests__/internals/apis/downloadData.test.ts b/packages/storage/__tests__/internals/apis/downloadData.test.ts index 4e27e68a1a4..6175e91e7d0 100644 --- a/packages/storage/__tests__/internals/apis/downloadData.test.ts +++ b/packages/storage/__tests__/internals/apis/downloadData.test.ts @@ -29,6 +29,7 @@ describe('downloadData (internal)', () => { it('should pass advanced option locationCredentialsProvider to internal downloadData', async () => { const useAccelerateEndpoint = true; + const expectedBucketOwner = '012345678901'; const bucket = { bucketName: 'bucket', region: 'us-east-1' }; const locationCredentialsProvider = async () => ({ credentials: { @@ -49,6 +50,7 @@ describe('downloadData (internal)', () => { locationCredentialsProvider, onProgress, bytesRange, + expectedBucketOwner, }, }); @@ -61,6 +63,7 @@ describe('downloadData (internal)', () => { locationCredentialsProvider, onProgress, bytesRange, + expectedBucketOwner, }, }); diff --git a/packages/storage/__tests__/internals/apis/getProperties.test.ts b/packages/storage/__tests__/internals/apis/getProperties.test.ts index 4b58d4cc8e1..97e85210e36 100644 --- a/packages/storage/__tests__/internals/apis/getProperties.test.ts +++ b/packages/storage/__tests__/internals/apis/getProperties.test.ts @@ -21,6 +21,7 @@ describe('getProperties (internal)', () => { it('should pass advanced option locationCredentialsProvider to internal getProperties', async () => { const useAccelerateEndpoint = true; + const expectedBucketOwner = '012345678901'; const bucket = { bucketName: 'bucket', region: 'us-east-1' }; const locationCredentialsProvider = async () => ({ credentials: { @@ -35,6 +36,7 @@ describe('getProperties (internal)', () => { options: { useAccelerateEndpoint, bucket, + expectedBucketOwner, locationCredentialsProvider, }, }); @@ -46,6 +48,7 @@ describe('getProperties (internal)', () => { options: { useAccelerateEndpoint, bucket, + expectedBucketOwner, locationCredentialsProvider, }, }, diff --git a/packages/storage/__tests__/internals/apis/getUrl.test.ts b/packages/storage/__tests__/internals/apis/getUrl.test.ts index 5ec4909fa16..d1b83149b7a 100644 --- a/packages/storage/__tests__/internals/apis/getUrl.test.ts +++ b/packages/storage/__tests__/internals/apis/getUrl.test.ts @@ -27,6 +27,7 @@ describe('getUrl (internal)', () => { it('should pass through advanced options to the internal getUrl', async () => { const useAccelerateEndpoint = true; const validateObjectExistence = false; + const expectedBucketOwner = '012345678901'; const expiresIn = 300; // seconds const contentDisposition = 'inline; filename="example.jpg"'; const contentType = 'image/jpeg'; @@ -48,6 +49,7 @@ describe('getUrl (internal)', () => { expiresIn, contentDisposition, contentType, + expectedBucketOwner, locationCredentialsProvider, }, }); @@ -63,6 +65,7 @@ describe('getUrl (internal)', () => { expiresIn, contentDisposition, contentType, + expectedBucketOwner, locationCredentialsProvider, }, }, diff --git a/packages/storage/__tests__/internals/apis/list.test.ts b/packages/storage/__tests__/internals/apis/list.test.ts index f34b3d2db9e..d72b95ad0bd 100644 --- a/packages/storage/__tests__/internals/apis/list.test.ts +++ b/packages/storage/__tests__/internals/apis/list.test.ts @@ -18,6 +18,7 @@ describe('list (internals)', () => { it('should pass advanced option locationCredentialsProvider to internal list', async () => { const useAccelerateEndpoint = true; + const expectedBucketOwner = '012345678901'; const bucket = { bucketName: 'bucket', region: 'us-east-1' }; const locationCredentialsProvider = async () => ({ credentials: { @@ -32,6 +33,7 @@ describe('list (internals)', () => { options: { useAccelerateEndpoint, bucket, + expectedBucketOwner, locationCredentialsProvider, }, }); @@ -43,6 +45,7 @@ describe('list (internals)', () => { options: { useAccelerateEndpoint, bucket, + expectedBucketOwner, locationCredentialsProvider, }, }, diff --git a/packages/storage/__tests__/internals/apis/remove.test.ts b/packages/storage/__tests__/internals/apis/remove.test.ts index df3a5d7d58a..2f67997e10c 100644 --- a/packages/storage/__tests__/internals/apis/remove.test.ts +++ b/packages/storage/__tests__/internals/apis/remove.test.ts @@ -21,6 +21,7 @@ describe('remove (internal)', () => { it('should pass advanced option locationCredentialsProvider to internal remove', async () => { const useAccelerateEndpoint = true; + const expectedBucketOwner = '012345678901'; const bucket = { bucketName: 'bucket', region: 'us-east-1' }; const locationCredentialsProvider = async () => ({ credentials: { @@ -36,6 +37,7 @@ describe('remove (internal)', () => { options: { useAccelerateEndpoint, bucket, + expectedBucketOwner, locationCredentialsProvider, }, }); @@ -48,6 +50,7 @@ describe('remove (internal)', () => { options: { useAccelerateEndpoint, bucket, + expectedBucketOwner, locationCredentialsProvider, }, }, diff --git a/packages/storage/__tests__/internals/apis/uploadData.test.ts b/packages/storage/__tests__/internals/apis/uploadData.test.ts index c28347139e4..642e4776e74 100644 --- a/packages/storage/__tests__/internals/apis/uploadData.test.ts +++ b/packages/storage/__tests__/internals/apis/uploadData.test.ts @@ -19,6 +19,7 @@ describe('uploadData (internal)', () => { it('should pass advanced option locationCredentialsProvider to internal remove', async () => { const useAccelerateEndpoint = true; + const expectedBucketOwner = '012345678901'; const bucket = { bucketName: 'bucket', region: 'us-east-1' }; const locationCredentialsProvider = async () => ({ credentials: { @@ -44,6 +45,7 @@ describe('uploadData (internal)', () => { contentType: 'text/html', onProgress, metadata, + expectedBucketOwner, }, }); @@ -60,6 +62,7 @@ describe('uploadData (internal)', () => { contentType: 'text/html', onProgress, metadata, + expectedBucketOwner, }, }); expect(result).toEqual(mockedUploadTask); diff --git a/packages/storage/src/internals/apis/copy.ts b/packages/storage/src/internals/apis/copy.ts index 66964cb67fe..eb53241e89e 100644 --- a/packages/storage/src/internals/apis/copy.ts +++ b/packages/storage/src/internals/apis/copy.ts @@ -17,10 +17,12 @@ export const copy = (input: CopyInput) => bucket: input.source.bucket, eTag: input.source.eTag, notModifiedSince: input.source.notModifiedSince, + expectedBucketOwner: input.source.expectedBucketOwner, }, destination: { path: input.destination.path, bucket: input.destination.bucket, + expectedBucketOwner: input.destination.expectedBucketOwner, }, options: { // Advanced options diff --git a/packages/storage/src/internals/apis/downloadData.ts b/packages/storage/src/internals/apis/downloadData.ts index 9c05dd525b4..8f097f82bb6 100644 --- a/packages/storage/src/internals/apis/downloadData.ts +++ b/packages/storage/src/internals/apis/downloadData.ts @@ -6,35 +6,6 @@ import { DownloadDataInput } from '../types/inputs'; import { DownloadDataOutput } from '../types/outputs'; /** - * Download S3 object data to memory - * - * @param input - The `DownloadDataInput` object. - * @returns A cancelable task exposing result promise from `result` property. - * @throws service: `S3Exception` - thrown when checking for existence of the object - * @throws validation: `StorageValidationErrorCode` - Validation errors - * - * @example - * ```ts - * // Download a file from s3 bucket - * const { body, eTag } = await downloadData({ path, options: { - * onProgress, // Optional progress callback. - * } }).result; - * ``` - * @example - * ```ts - * // Cancel a task - * const downloadTask = downloadData({ path }); - * //... - * downloadTask.cancel(); - * try { - * await downloadTask.result; - * } catch (error) { - * if(isCancelError(error)) { - * // Handle error thrown by task cancelation. - * } - * } - *``` - * * @internal */ export const downloadData = (input: DownloadDataInput): DownloadDataOutput => @@ -46,6 +17,7 @@ export const downloadData = (input: DownloadDataInput): DownloadDataOutput => locationCredentialsProvider: input?.options?.locationCredentialsProvider, bytesRange: input?.options?.bytesRange, onProgress: input?.options?.onProgress, + expectedBucketOwner: input?.options?.expectedBucketOwner, }, // Type casting is necessary because `downloadDataInternal` supports both Gen1 and Gen2 signatures, but here // given in input can only be Gen2 signature, the return can only ben Gen2 signature. diff --git a/packages/storage/src/internals/apis/getProperties.ts b/packages/storage/src/internals/apis/getProperties.ts index 6d651f54635..54e03c6d60b 100644 --- a/packages/storage/src/internals/apis/getProperties.ts +++ b/packages/storage/src/internals/apis/getProperties.ts @@ -8,13 +8,6 @@ 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 `GetPropertiesInput` 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 const getProperties = ( diff --git a/packages/storage/src/internals/apis/getUrl.ts b/packages/storage/src/internals/apis/getUrl.ts index 85bc2be50bd..3c19b922e17 100644 --- a/packages/storage/src/internals/apis/getUrl.ts +++ b/packages/storage/src/internals/apis/getUrl.ts @@ -20,6 +20,7 @@ export const getUrl = (input: GetUrlInput) => expiresIn: input?.options?.expiresIn, contentDisposition: input?.options?.contentDisposition, contentType: input?.options?.contentType, + expectedBucketOwner: input?.options?.expectedBucketOwner, // Advanced options locationCredentialsProvider: input?.options?.locationCredentialsProvider, diff --git a/packages/storage/src/internals/apis/list.ts b/packages/storage/src/internals/apis/list.ts index 9fb00cc348a..4ce0a72eb3f 100644 --- a/packages/storage/src/internals/apis/list.ts +++ b/packages/storage/src/internals/apis/list.ts @@ -32,6 +32,7 @@ export function list(input: ListInput): Promise { subpathStrategy: input.options?.subpathStrategy, useAccelerateEndpoint: input.options?.useAccelerateEndpoint, listAll: input.options?.listAll, + expectedBucketOwner: input.options?.expectedBucketOwner, // Pagination options nextToken: (input as ListPaginateInput).options?.nextToken, diff --git a/packages/storage/src/internals/apis/remove.ts b/packages/storage/src/internals/apis/remove.ts index 8ac90197f7d..22864c3156b 100644 --- a/packages/storage/src/internals/apis/remove.ts +++ b/packages/storage/src/internals/apis/remove.ts @@ -8,13 +8,6 @@ import { RemoveInput } from '../types/inputs'; import { RemoveOutput } from '../types/outputs'; /** - * Remove a file from your S3 bucket. - * @param input - The `RemoveInput` 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 => @@ -23,6 +16,7 @@ export const remove = (input: RemoveInput): Promise => options: { useAccelerateEndpoint: input?.options?.useAccelerateEndpoint, bucket: input?.options?.bucket, + expectedBucketOwner: input?.options?.expectedBucketOwner, locationCredentialsProvider: input?.options?.locationCredentialsProvider, }, // Type casting is necessary because `removeInternal` supports both Gen1 and Gen2 signatures, but here diff --git a/packages/storage/src/internals/apis/uploadData.ts b/packages/storage/src/internals/apis/uploadData.ts index ad7a3eb33a7..58b04ac2211 100644 --- a/packages/storage/src/internals/apis/uploadData.ts +++ b/packages/storage/src/internals/apis/uploadData.ts @@ -23,6 +23,7 @@ export const uploadData = (input: UploadDataInput) => { contentType: options?.contentType, metadata: options?.metadata, preventOverwrite: options?.preventOverwrite, + expectedBucketOwner: options?.expectedBucketOwner, // Advanced options locationCredentialsProvider: options?.locationCredentialsProvider,