Skip to content
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

chore(storage-browser): expose additional input output types #13682

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 @@ export const listCallerAccessGrants = async (
},
);

const accessGrants: AccessGrant[] =
// TODO: return `applicationArn` if required
ashwinkumar6 marked this conversation as resolved.
Show resolved Hide resolved
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 +61,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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

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
Loading