From ec28f6bdeb3997d454ca02e2621e43826cf52553 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Mon, 5 Aug 2024 17:01:27 -0700 Subject: [PATCH 1/4] chore(storage-browser): expose additional internal types --- packages/storage/src/storageBrowser/apis/types.ts | 4 ++-- packages/storage/src/storageBrowser/index.ts | 8 ++++++++ .../storageBrowser/locationCredentialsStore/create.ts | 8 ++++---- packages/storage/src/storageBrowser/types.ts | 10 ++++++++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/storage/src/storageBrowser/apis/types.ts b/packages/storage/src/storageBrowser/apis/types.ts index c97a7c4bbdd..c4640dd65e1 100644 --- a/packages/storage/src/storageBrowser/apis/types.ts +++ b/packages/storage/src/storageBrowser/apis/types.ts @@ -5,7 +5,7 @@ import { AccessGrant, CredentialsProvider, ListLocationsInput, - ListLocationsOutput, + ListLocationsOutputS3, LocationCredentials, Permission, PrefixType, @@ -18,7 +18,7 @@ export interface ListCallerAccessGrantsInput extends ListLocationsInput { region: string; } -export type ListCallerAccessGrantsOutput = ListLocationsOutput; +export type ListCallerAccessGrantsOutput = ListLocationsOutputS3; export interface GetDataAccessInput { accountId: string; diff --git a/packages/storage/src/storageBrowser/index.ts b/packages/storage/src/storageBrowser/index.ts index 72878852a09..b5af870caeb 100644 --- a/packages/storage/src/storageBrowser/index.ts +++ b/packages/storage/src/storageBrowser/index.ts @@ -14,4 +14,12 @@ export { GetLocationCredentials, ListLocations, LocationCredentialsStore, + CreateLocationCredentialsStoreInput, + LocationCredentials, + ListLocationsInput, + ListLocationsOutput, + GetLocationCredentialsInput, + GetLocationCredentialsOutput, + Permission as AccessGrantPermission, } from './types'; +export { AWSTemporaryCredentials } from '../providers/s3/types/options'; diff --git a/packages/storage/src/storageBrowser/locationCredentialsStore/create.ts b/packages/storage/src/storageBrowser/locationCredentialsStore/create.ts index ce4e9126612..05d68004f43 100644 --- a/packages/storage/src/storageBrowser/locationCredentialsStore/create.ts +++ b/packages/storage/src/storageBrowser/locationCredentialsStore/create.ts @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { + CreateLocationCredentialsStoreInput, CredentialsLocation, - GetLocationCredentials, LocationCredentialsStore, } from '../types'; import { StorageValidationErrorCode } from '../../errors/types/validation'; @@ -12,9 +12,9 @@ import { LocationCredentialsProvider } from '../../providers/s3/types/options'; import { createStore, getValue, removeStore } from './registry'; -export const createLocationCredentialsStore = (input: { - handler: GetLocationCredentials; -}): LocationCredentialsStore => { +export const createLocationCredentialsStore = ( + input: CreateLocationCredentialsStoreInput, +): LocationCredentialsStore => { const storeSymbol = createStore(input.handler); const store = { diff --git a/packages/storage/src/storageBrowser/types.ts b/packages/storage/src/storageBrowser/types.ts index 1199cf0e851..cd9b823d78c 100644 --- a/packages/storage/src/storageBrowser/types.ts +++ b/packages/storage/src/storageBrowser/types.ts @@ -84,10 +84,12 @@ export interface AccessGrant extends LocationAccess { /** * @internal */ -export interface ListLocationsOutput { + +export interface ListLocationsOutputS3 { locations: T[]; nextToken?: string; } +export type ListLocationsOutput = ListLocationsOutputS3; /** * @internal @@ -99,7 +101,7 @@ export interface ListLocationsInput { export type ListLocations = ( input?: ListLocationsInput, -) => Promise>; +) => Promise; export type GetLocationCredentialsInput = CredentialsLocation; export type GetLocationCredentialsOutput = LocationCredentials; @@ -108,6 +110,10 @@ export type GetLocationCredentials = ( input: GetLocationCredentialsInput, ) => Promise; +export interface CreateLocationCredentialsStoreInput { + handler: GetLocationCredentials; +} + export interface LocationCredentialsStore { /** * Get location-specific credentials. It uses a cache internally to optimize performance when From a3dbbf26bd25479bed17125f64c03743517465dd Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Tue, 6 Aug 2024 17:01:33 -0700 Subject: [PATCH 2/4] address feedback --- .../apis/listCallerAccessGrants.ts | 6 +++--- .../storage/src/storageBrowser/apis/types.ts | 5 ++--- packages/storage/src/storageBrowser/index.ts | 2 +- packages/storage/src/storageBrowser/types.ts | 21 ++++--------------- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts b/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts index 12836d59880..8caf948a9bd 100644 --- a/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts +++ b/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts @@ -6,7 +6,7 @@ import { CredentialsProviderOptions } from '@aws-amplify/core/internals/aws-clie import { logger } from '../../utils'; import { listCallerAccessGrants as listCallerAccessGrantsClient } from '../../providers/s3/utils/client/s3control'; -import { AccessGrant, LocationType, Permission } from '../types'; +import { LocationAccess, LocationType, Permission } from '../types'; import { StorageError } from '../../errors/StorageError'; import { getStorageUserAgentValue } from '../../providers/s3/utils/userAgent'; @@ -51,7 +51,8 @@ export const listCallerAccessGrants = async ( }, ); - const accessGrants: AccessGrant[] = + // TODO: return `applicationArn` if required + const accessGrants: LocationAccess[] = CallerAccessGrantsList?.map(grant => { // These values are correct from service mostly, but we add assertions to make TSC happy. assertPermission(grant.Permission); @@ -60,7 +61,6 @@ export const listCallerAccessGrants = async ( return { scope: grant.GrantScope, permission: grant.Permission, - applicationArn: grant.ApplicationArn, type: parseGrantType(grant.GrantScope!), }; }) ?? []; diff --git a/packages/storage/src/storageBrowser/apis/types.ts b/packages/storage/src/storageBrowser/apis/types.ts index c4640dd65e1..d0892c42b52 100644 --- a/packages/storage/src/storageBrowser/apis/types.ts +++ b/packages/storage/src/storageBrowser/apis/types.ts @@ -2,10 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 import { - AccessGrant, CredentialsProvider, ListLocationsInput, - ListLocationsOutputS3, + ListLocationsOutput, LocationCredentials, Permission, PrefixType, @@ -18,7 +17,7 @@ export interface ListCallerAccessGrantsInput extends ListLocationsInput { region: string; } -export type ListCallerAccessGrantsOutput = ListLocationsOutputS3; +export type ListCallerAccessGrantsOutput = ListLocationsOutput; export interface GetDataAccessInput { accountId: string; diff --git a/packages/storage/src/storageBrowser/index.ts b/packages/storage/src/storageBrowser/index.ts index b5af870caeb..94c741b857c 100644 --- a/packages/storage/src/storageBrowser/index.ts +++ b/packages/storage/src/storageBrowser/index.ts @@ -20,6 +20,6 @@ export { ListLocationsOutput, GetLocationCredentialsInput, GetLocationCredentialsOutput, - Permission as AccessGrantPermission, + Permission, } from './types'; export { AWSTemporaryCredentials } from '../providers/s3/types/options'; diff --git a/packages/storage/src/storageBrowser/types.ts b/packages/storage/src/storageBrowser/types.ts index cd9b823d78c..94d0c1f6eac 100644 --- a/packages/storage/src/storageBrowser/types.ts +++ b/packages/storage/src/storageBrowser/types.ts @@ -71,31 +71,18 @@ export interface LocationCredentials extends Partial { readonly credentials: AWSTemporaryCredentials; } -export interface AccessGrant extends LocationAccess { - /** - * The Amazon Resource Name (ARN) of an AWS IAM Identity Center application - * associated with your Identity Center instance. If the grant includes an - * application ARN, the grantee can only access the S3 data through this - * application. - */ - readonly applicationArn: string | undefined; -} - /** * @internal */ - -export interface ListLocationsOutputS3 { - locations: T[]; +export interface ListLocationsInput { + pageSize?: number; nextToken?: string; } -export type ListLocationsOutput = ListLocationsOutputS3; - /** * @internal */ -export interface ListLocationsInput { - pageSize?: number; +export interface ListLocationsOutput { + locations: LocationAccess[]; nextToken?: string; } From 550b1b5c7fea1fb0819893a477f476cc5ddbb12e Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Tue, 6 Aug 2024 17:15:21 -0700 Subject: [PATCH 3/4] remove 'applicationArn' from listCallerAccessGrant unit test --- .../storageBrowser/apis/listCallerAccessGrants.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/storage/__tests__/storageBrowser/apis/listCallerAccessGrants.test.ts b/packages/storage/__tests__/storageBrowser/apis/listCallerAccessGrants.test.ts index bff4b4e07bd..54a90d66206 100644 --- a/packages/storage/__tests__/storageBrowser/apis/listCallerAccessGrants.test.ts +++ b/packages/storage/__tests__/storageBrowser/apis/listCallerAccessGrants.test.ts @@ -117,19 +117,16 @@ describe('listCallerAccessGrants', () => { scope: 's3://bucket/*', type: 'BUCKET', permission: 'READ', - applicationArn: undefined, }, { scope: 's3://bucket/path/*', type: 'PREFIX', permission: 'READWRITE', - applicationArn: undefined, }, { scope: 's3://bucket/path/to/object', type: 'OBJECT', permission: 'READ', - applicationArn: 'arn:123', }, ]); expect(nextToken).toBeUndefined(); From d518aad2984f96a83a3c65533b4a9de9f44dbe62 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Wed, 7 Aug 2024 09:16:04 -0700 Subject: [PATCH 4/4] Update packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts Co-authored-by: Caleb Pollman --- .../storage/src/storageBrowser/apis/listCallerAccessGrants.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts b/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts index 8caf948a9bd..157657b09d4 100644 --- a/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts +++ b/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts @@ -51,7 +51,6 @@ export const listCallerAccessGrants = async ( }, ); - // TODO: return `applicationArn` if required const accessGrants: LocationAccess[] = CallerAccessGrantsList?.map(grant => { // These values are correct from service mostly, but we add assertions to make TSC happy.