Skip to content

Commit

Permalink
chore(storage-browser): expose additional input output types (#13682)
Browse files Browse the repository at this point in the history
* chore(storage-browser): expose additional internal types

* address feedback

* remove 'applicationArn' from listCallerAccessGrant unit test

* Update packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts

Co-authored-by: Caleb Pollman <cpollman1@gmail.com>

---------

Co-authored-by: Ashwin Kumar <ashwsrir@amazon.com>
Co-authored-by: Caleb Pollman <cpollman1@gmail.com>
  • Loading branch information
3 people authored Aug 7, 2024
1 parent 08ef01b commit d69c58b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -51,7 +51,7 @@ export const listCallerAccessGrants = async (
},
);

const accessGrants: AccessGrant[] =
const accessGrants: LocationAccess[] =
CallerAccessGrantsList?.map(grant => {
// These values are correct from service mostly, but we add assertions to make TSC happy.
assertPermission(grant.Permission);
Expand All @@ -60,7 +60,6 @@ export const listCallerAccessGrants = async (
return {
scope: grant.GrantScope,
permission: grant.Permission,
applicationArn: grant.ApplicationArn,
type: parseGrantType(grant.GrantScope!),
};
}) ?? [];
Expand Down
3 changes: 1 addition & 2 deletions packages/storage/src/storageBrowser/apis/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import {
AccessGrant,
CredentialsProvider,
ListLocationsInput,
ListLocationsOutput,
Expand All @@ -18,7 +17,7 @@ export interface ListCallerAccessGrantsInput extends ListLocationsInput {
region: string;
}

export type ListCallerAccessGrantsOutput = ListLocationsOutput<AccessGrant>;
export type ListCallerAccessGrantsOutput = ListLocationsOutput;

export interface GetDataAccessInput {
accountId: string;
Expand Down
8 changes: 8 additions & 0 deletions packages/storage/src/storageBrowser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ export {
GetLocationCredentials,
ListLocations,
LocationCredentialsStore,
CreateLocationCredentialsStoreInput,
LocationCredentials,
ListLocationsInput,
ListLocationsOutput,
GetLocationCredentialsInput,
GetLocationCredentialsOutput,
Permission,
} from './types';
export { AWSTemporaryCredentials } from '../providers/s3/types/options';
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import {
CreateLocationCredentialsStoreInput,
CredentialsLocation,
GetLocationCredentials,
LocationCredentialsStore,
} from '../types';
import { StorageValidationErrorCode } from '../../errors/types/validation';
Expand All @@ -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 = {
Expand Down
25 changes: 9 additions & 16 deletions packages/storage/src/storageBrowser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,24 @@ export interface LocationCredentials extends Partial<LocationScope> {
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 ListLocationsOutput<T extends LocationAccess> {
locations: T[];
export interface ListLocationsInput {
pageSize?: number;
nextToken?: string;
}

/**
* @internal
*/
export interface ListLocationsInput {
pageSize?: number;
export interface ListLocationsOutput {
locations: LocationAccess[];
nextToken?: string;
}

export type ListLocations = (
input?: ListLocationsInput,
) => Promise<ListLocationsOutput<LocationAccess>>;
) => Promise<ListLocationsOutput>;

export type GetLocationCredentialsInput = CredentialsLocation;
export type GetLocationCredentialsOutput = LocationCredentials;
Expand All @@ -108,6 +97,10 @@ export type GetLocationCredentials = (
input: GetLocationCredentialsInput,
) => Promise<GetLocationCredentialsOutput>;

export interface CreateLocationCredentialsStoreInput {
handler: GetLocationCredentials;
}

export interface LocationCredentialsStore {
/**
* Get location-specific credentials. It uses a cache internally to optimize performance when
Expand Down

0 comments on commit d69c58b

Please sign in to comment.