From 05ef3d87ea39b1f4b0f1d13fe042af24eba7a062 Mon Sep 17 00:00:00 2001 From: AllanZhengYP Date: Thu, 17 Oct 2024 13:44:14 -0700 Subject: [PATCH] feat(storage): set allowedByApp to listCallerAccessGrants (#13934) --- eslint.config.mjs | 7 ++ .../apis/listCallerAccessGrants.test.ts | 1 + .../client/S3/cases/listCallerAccessGrants.ts | 6 +- .../internals/apis/listCallerAccessGrants.ts | 1 + .../s3control/listCallerAccessGrants.ts | 12 ++- .../s3/utils/client/s3control/types.ts | 98 ++++++++++++------- scripts/dts-bundler/README.md | 36 +++++-- scripts/dts-bundler/dts-bundler.config.js | 8 ++ scripts/dts-bundler/package.json | 4 +- scripts/dts-bundler/s3-control.d.ts | 13 +++ 10 files changed, 140 insertions(+), 46 deletions(-) create mode 100644 scripts/dts-bundler/s3-control.d.ts diff --git a/eslint.config.mjs b/eslint.config.mjs index 079c9406be4..4d4f9c7e3ac 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -12,6 +12,8 @@ import tsParser from '@typescript-eslint/parser'; import js from '@eslint/js'; import { FlatCompat } from '@eslint/eslintrc'; +import customClientDtsBundlerConfig from './scripts/dts-bundler/dts-bundler.config.js'; + const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({ @@ -19,6 +21,10 @@ const compat = new FlatCompat({ recommendedConfig: js.configs.recommended, allConfig: js.configs.all, }); +const customClientDtsFiles = customClientDtsBundlerConfig.entries + .map(clientBundlerConfig => clientBundlerConfig.outFile) + .filter(outFile => outFile?.length > 0) + .map(outFile => outFile.replace(__dirname + path.sep, '')) // Convert absolute path to relative path export default [ { @@ -39,6 +45,7 @@ export default [ 'packages/interactions/__tests__', 'packages/predictions/__tests__', 'packages/pubsub/__tests__', + ...customClientDtsFiles, ], }, ...fixupConfigRules( diff --git a/packages/storage/__tests__/internals/apis/listCallerAccessGrants.test.ts b/packages/storage/__tests__/internals/apis/listCallerAccessGrants.test.ts index f5067843129..ebe724e688c 100644 --- a/packages/storage/__tests__/internals/apis/listCallerAccessGrants.test.ts +++ b/packages/storage/__tests__/internals/apis/listCallerAccessGrants.test.ts @@ -50,6 +50,7 @@ describe('listCallerAccessGrants', () => { AccountId: mockAccountId, NextToken: mockNextToken, MaxResults: mockPageSize, + AllowedByApplication: true, }), ); const inputCredentialsProvider = jest.mocked(listCallerAccessGrantsClient) diff --git a/packages/storage/__tests__/providers/s3/utils/client/S3/cases/listCallerAccessGrants.ts b/packages/storage/__tests__/providers/s3/utils/client/S3/cases/listCallerAccessGrants.ts index 961ef27b3bf..63499b7234c 100644 --- a/packages/storage/__tests__/providers/s3/utils/client/S3/cases/listCallerAccessGrants.ts +++ b/packages/storage/__tests__/providers/s3/utils/client/S3/cases/listCallerAccessGrants.ts @@ -29,10 +29,11 @@ const listCallerAccessGrantsHappyCaseSingleGrant: ApiFunctionalTestCase< GrantScope: 's3://my-bucket/path/to/', MaxResults: 50, NextToken: 'mockToken', + AllowedByApplication: true, }, expect.objectContaining({ url: expect.objectContaining({ - href: 'https://accountid.s3-control.us-east-1.amazonaws.com/v20180820/accessgrantsinstance/caller/grants?grantscope=s3%3A%2F%2Fmy-bucket%2Fpath%2Fto%2F&maxResults=50&nextToken=mockToken', + href: 'https://accountid.s3-control.us-east-1.amazonaws.com/v20180820/accessgrantsinstance/caller/grants?grantscope=s3%3A%2F%2Fmy-bucket%2Fpath%2Fto%2F&maxResults=50&nextToken=mockToken&allowedByApplication=true', }), method: 'GET', headers: expect.objectContaining({ @@ -83,10 +84,11 @@ const listCallerAccessGrantsHappyCaseMultipleGrants: ApiFunctionalTestCase< GrantScope: 's3://my-bucket/path/to/', MaxResults: 50, NextToken: 'mockToken', + AllowedByApplication: true, }, expect.objectContaining({ url: expect.objectContaining({ - href: 'https://accountid.s3-control.us-east-1.amazonaws.com/v20180820/accessgrantsinstance/caller/grants?grantscope=s3%3A%2F%2Fmy-bucket%2Fpath%2Fto%2F&maxResults=50&nextToken=mockToken', + href: 'https://accountid.s3-control.us-east-1.amazonaws.com/v20180820/accessgrantsinstance/caller/grants?grantscope=s3%3A%2F%2Fmy-bucket%2Fpath%2Fto%2F&maxResults=50&nextToken=mockToken&allowedByApplication=true', }), method: 'GET', headers: expect.objectContaining({ diff --git a/packages/storage/src/internals/apis/listCallerAccessGrants.ts b/packages/storage/src/internals/apis/listCallerAccessGrants.ts index 3f8601fdaaa..c0da06b4f93 100644 --- a/packages/storage/src/internals/apis/listCallerAccessGrants.ts +++ b/packages/storage/src/internals/apis/listCallerAccessGrants.ts @@ -49,6 +49,7 @@ export const listCallerAccessGrants = async ( AccountId: accountId, NextToken: nextToken, MaxResults: pageSize ?? MAX_PAGE_SIZE, + AllowedByApplication: true, }, ); diff --git a/packages/storage/src/providers/s3/utils/client/s3control/listCallerAccessGrants.ts b/packages/storage/src/providers/s3/utils/client/s3control/listCallerAccessGrants.ts index 81b0e62a9c8..5c4b3b71d8c 100644 --- a/packages/storage/src/providers/s3/utils/client/s3control/listCallerAccessGrants.ts +++ b/packages/storage/src/providers/s3/utils/client/s3control/listCallerAccessGrants.ts @@ -29,7 +29,14 @@ import type { } from './types'; import { defaultConfig, parseXmlError } from './base'; -export type ListCallerAccessGrantsInput = ListCallerAccessGrantsCommandInput; +export type ListCallerAccessGrantsInput = Pick< + ListCallerAccessGrantsCommandInput, + | 'AccountId' + | 'AllowedByApplication' + | 'GrantScope' + | 'NextToken' + | 'MaxResults' +>; export type ListCallerAccessGrantsOutput = ListCallerAccessGrantsCommandOutput; @@ -44,11 +51,12 @@ const listCallerAccessGrantsSerializer = ( grantscope: input.GrantScope, maxResults: input.MaxResults, nextToken: input.NextToken, + allowedByApplication: input.AllowedByApplication, }); const url = new AmplifyUrl(endpoint.url.toString()); url.search = new AmplifyUrlSearchParams(query).toString(); - // Ref: NA + // Ref: https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_ListCallerAccessGrants.html url.pathname = '/v20180820/accessgrantsinstance/caller/grants'; return { diff --git a/packages/storage/src/providers/s3/utils/client/s3control/types.ts b/packages/storage/src/providers/s3/utils/client/s3control/types.ts index 088bfc8b3ba..612875980e4 100644 --- a/packages/storage/src/providers/s3/utils/client/s3control/types.ts +++ b/packages/storage/src/providers/s3/utils/client/s3control/types.ts @@ -1,15 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -/* -This file contains manually curated AWS service types that are not yet available via the AWS SDK and the `dts-bundler` -script. Once these APIs have been released to the AWS SDK, this file can be removed in favor of the `dts-bundler` -types. - -These types were harvested from Trebuchet. - -@TODO(jimblanc) Unify types & integrate with `dts-bundler` -*/ +/** + * Generated by scripts/dts-bundler/README.md + */ import { MetadataBearer as __MetadataBearer } from '@aws-sdk/types'; @@ -44,33 +38,20 @@ export interface Credentials { /** *

The Amazon Web Services STS temporary credential that S3 Access Grants vends to grantees and client applications.

* @public - * @public - * - * The input for {@link ListCallerAccessGrantsCommand}. - * @public - * - * The input for {@link ListCallerAccessGrantsCommand}. */ SessionToken?: string; /** *

The expiration date and time of the temporary credential that S3 Access Grants vends to grantees and client applications.

* @public - * @public - * - * The output of {@link ListCallerAccessGrantsCommand}. - * @public - * - * The output of {@link ListCallerAccessGrantsCommand}. */ Expiration?: Date; } - /** * @public * * The input for {@link GetDataAccessCommand}. */ -export type GetDataAccessCommandInput = GetDataAccessRequest; +export interface GetDataAccessCommandInput extends GetDataAccessRequest {} /** * @public * @@ -79,23 +60,20 @@ export type GetDataAccessCommandInput = GetDataAccessRequest; export interface GetDataAccessCommandOutput extends GetDataAccessResult, __MetadataBearer {} - /** * @public */ export interface GetDataAccessRequest { /** - *

The ID of the Amazon Web Services account that is making this request.

+ *

The Amazon Web Services account ID of the S3 Access Grants instance.

* @public */ AccountId?: string; - /** *

The S3 URI path of the data to which you are requesting temporary access credentials. If the requesting account has an access grant for this data, S3 Access Grants vends temporary access credentials in the response.

* @public */ Target: string | undefined; - /** *

The type of permission granted to your S3 data, which can be set to one of the following values:

*