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

feat(storage): implement listLocations API and creation handler #13602

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 14 additions & 14 deletions packages/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
"name": "[Analytics] record (Pinpoint)",
"path": "./dist/esm/analytics/index.mjs",
"import": "{ record }",
"limit": "17.11 kB"
"limit": "17.14 kB"
},
{
"name": "[Analytics] record (Kinesis)",
Expand All @@ -311,13 +311,13 @@
"name": "[Analytics] record (Personalize)",
"path": "./dist/esm/analytics/personalize/index.mjs",
"import": "{ record }",
"limit": "49.50 kB"
"limit": "49.53 kB"
},
{
"name": "[Analytics] identifyUser (Pinpoint)",
"path": "./dist/esm/analytics/index.mjs",
"import": "{ identifyUser }",
"limit": "15.60 kB"
"limit": "15.64 kB"
},
{
"name": "[Analytics] enable",
Expand Down Expand Up @@ -353,13 +353,13 @@
"name": "[Auth] resetPassword (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ resetPassword }",
"limit": "12.44 kB"
"limit": "12.48 kB"
},
{
"name": "[Auth] confirmResetPassword (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ confirmResetPassword }",
"limit": "12.39 kB"
"limit": "12.42 kB"
},
{
"name": "[Auth] signIn (Cognito)",
Expand All @@ -371,7 +371,7 @@
"name": "[Auth] resendSignUpCode (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ resendSignUpCode }",
"limit": "12.40 kB"
"limit": "12.44 kB"
},
{
"name": "[Auth] confirmSignUp (Cognito)",
Expand All @@ -383,19 +383,19 @@
"name": "[Auth] confirmSignIn (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ confirmSignIn }",
"limit": "28.28 kB"
"limit": "28.32 kB"
},
{
"name": "[Auth] updateMFAPreference (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ updateMFAPreference }",
"limit": "11.74 kB"
"limit": "11.78 kB"
},
{
"name": "[Auth] fetchMFAPreference (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ fetchMFAPreference }",
"limit": "11.78 kB"
"limit": "11.81 kB"
},
{
"name": "[Auth] verifyTOTPSetup (Cognito)",
Expand All @@ -407,7 +407,7 @@
"name": "[Auth] updatePassword (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ updatePassword }",
"limit": "12.63 kB"
"limit": "12.67 kB"
},
{
"name": "[Auth] setUpTOTP (Cognito)",
Expand All @@ -431,7 +431,7 @@
"name": "[Auth] confirmUserAttribute (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ confirmUserAttribute }",
"limit": "12.61 kB"
"limit": "12.64 kB"
},
{
"name": "[Auth] signInWithRedirect (Cognito)",
Expand All @@ -443,19 +443,19 @@
"name": "[Auth] fetchUserAttributes (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ fetchUserAttributes }",
"limit": "11.69 kB"
"limit": "11.72 kB"
},
{
"name": "[Auth] Basic Auth Flow (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ signIn, signOut, fetchAuthSession, confirmSignIn }",
"limit": "30.07 kB"
"limit": "30.11 kB"
},
{
"name": "[Auth] OAuth Auth Flow (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ signInWithRedirect, signOut, fetchAuthSession }",
"limit": "21.49 kB"
"limit": "21.52 kB"
},
{
"name": "[Storage] copy (S3)",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export enum StorageAction {
GetProperties = '6',
GetUrl = '7',
GetDataAccess = '8',
ListCallerAccessGrants = '9',
}

interface ActionMap {
Expand Down
6 changes: 3 additions & 3 deletions packages/interactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@
"name": "Interactions (default to Lex v2)",
"path": "./dist/esm/index.mjs",
"import": "{ Interactions }",
"limit": "52.52 kB"
"limit": "52.55 kB"
},
{
"name": "Interactions (Lex v2)",
"path": "./dist/esm/lex-v2/index.mjs",
"import": "{ Interactions }",
"limit": "52.52 kB"
"limit": "52.55 kB"
},
{
"name": "Interactions (Lex v1)",
"path": "./dist/esm/lex-v1/index.mjs",
"import": "{ Interactions }",
"limit": "47.33 kB"
"limit": "47.37 kB"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

import { listCallerAccessGrants } from '../../../src/storageBrowser/apis/listCallerAccessGrants';
import { listCallerAccessGrants as listCallerAccessGrantsClient } from '../../../src/providers/s3/utils/client/s3control';

jest.mock('../../../src/providers/s3/utils/client/s3control');

const mockAccountId = '1234567890';
const mockRegion = 'us-foo-2';
const mockCredentialsProvider = jest.fn();
const mockNextToken = '123';
const mockPageSize = 123;

describe('listCallerAccessGrants', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('should invoke the listCallerAccessGrants client with expected parameters', async () => {
expect.assertions(1);
jest.mocked(listCallerAccessGrantsClient).mockResolvedValue({
NextToken: undefined,
CallerAccessGrantsList: [],
$metadata: {} as any,
});
await listCallerAccessGrants({
accountId: mockAccountId,
region: mockRegion,
credentialsProvider: mockCredentialsProvider,
nextToken: mockNextToken,
pageSize: mockPageSize,
});
expect(listCallerAccessGrantsClient).toHaveBeenCalledWith(
expect.objectContaining({
region: mockRegion,
credentials: expect.any(Function),
}),
expect.objectContaining({
AccountId: mockAccountId,
NextToken: mockNextToken,
MaxResults: mockPageSize,
}),
);
});

it('should set a default page size', async () => {
expect.assertions(1);
jest.mocked(listCallerAccessGrantsClient).mockResolvedValue({
NextToken: undefined,
CallerAccessGrantsList: [],
$metadata: {} as any,
});
await listCallerAccessGrants({
accountId: mockAccountId,
region: mockRegion,
credentialsProvider: mockCredentialsProvider,
});
expect(listCallerAccessGrantsClient).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
MaxResults: 1000,
}),
);
});

it('should set response location type correctly', async () => {
expect.assertions(2);
jest.mocked(listCallerAccessGrantsClient).mockResolvedValue({
NextToken: undefined,
CallerAccessGrantsList: [
{
GrantScope: 's3://bucket/*',
Permission: 'READ',
},
{
GrantScope: 's3://bucket/path/*',
Permission: 'READWRITE',
},
{
GrantScope: 's3://bucket/path/to/object',
Permission: 'READ',
ApplicationArn: 'arn:123',
},
],
$metadata: {} as any,
});
const { locations, nextToken } = await listCallerAccessGrants({
accountId: mockAccountId,
region: mockRegion,
credentialsProvider: mockCredentialsProvider,
});

expect(locations).toEqual([
{
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();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { createListLocationsHandler } from '../../../src/storageBrowser/managedAuthConfigAdapter/createListLocationsHandler';
import { listCallerAccessGrants } from '../../../src/storageBrowser/apis/listCallerAccessGrants';

jest.mock('../../../src/storageBrowser/apis/listCallerAccessGrants');

jest.mocked(listCallerAccessGrants).mockResolvedValue({
locations: [],
});

describe('createListLocationsHandler', () => {
it('should parse the underlying API with right parameters', async () => {
const mockAccountId = '1234567890';
const mockRegion = 'us-foo-1';
const mockCredentialsProvider = jest.fn();
const mockNextToken = '123';
const mockPageSize = 123;
const handler = createListLocationsHandler({
accountId: mockAccountId,
region: mockRegion,
credentialsProvider: mockCredentialsProvider,
});
await handler({ nextToken: mockNextToken, pageSize: mockPageSize });
expect(listCallerAccessGrants).toHaveBeenCalledWith({
accountId: mockAccountId,
region: mockRegion,
credentialsProvider: mockCredentialsProvider,
nextToken: mockNextToken,
pageSize: mockPageSize,
});
});
});
1 change: 1 addition & 0 deletions packages/storage/src/storageBrowser/apis/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// SPDX-License-Identifier: Apache-2.0

export const DEFAULT_CRED_TTL = 15 * 60; // 15 minutes
export const MAX_PAGE_SIZE = 1000;
Loading
Loading