Skip to content

Commit

Permalink
feat(storage): Added getDataAccess & listCallerAccessGrant clients (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblanc authored Jul 15, 2024
1 parent 16e3c52 commit bcd8c9d
Show file tree
Hide file tree
Showing 55 changed files with 814 additions and 100 deletions.
4 changes: 2 additions & 2 deletions packages/storage/__tests__/providers/s3/apis/copy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Amplify, StorageAccessLevel } from '@aws-amplify/core';

import { StorageError } from '../../../../src/errors/StorageError';
import { StorageValidationErrorCode } from '../../../../src/errors/types/validation';
import { copyObject } from '../../../../src/providers/s3/utils/client';
import { copyObject } from '../../../../src/providers/s3/utils/client/s3data';
import { copy } from '../../../../src/providers/s3/apis';
import {
CopyInput,
Expand All @@ -16,7 +16,7 @@ import {
} from '../../../../src/providers/s3/types';
import './testUtils';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('../../../../src/providers/s3/utils/client/s3data');
jest.mock('@aws-amplify/core', () => ({
ConsoleLogger: jest.fn().mockImplementation(function ConsoleLogger() {
return { debug: jest.fn() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
import { Amplify, StorageAccessLevel } from '@aws-amplify/core';

import { getObject } from '../../../../src/providers/s3/utils/client';
import { getObject } from '../../../../src/providers/s3/utils/client/s3data';
import { downloadData } from '../../../../src/providers/s3';
import {
createDownloadTask,
Expand All @@ -25,7 +25,7 @@ import {
} from '../../../../src/providers/s3/types/outputs';
import './testUtils';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('../../../../src/providers/s3/utils/client/s3data');
jest.mock('../../../../src/providers/s3/utils');
jest.mock('@aws-amplify/core', () => ({
ConsoleLogger: jest.fn().mockImplementation(function ConsoleLogger() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
import { Amplify, StorageAccessLevel } from '@aws-amplify/core';

import { headObject } from '../../../../src/providers/s3/utils/client';
import { headObject } from '../../../../src/providers/s3/utils/client/s3data';
import { getProperties } from '../../../../src/providers/s3';
import {
GetPropertiesInput,
Expand All @@ -14,7 +14,7 @@ import {
} from '../../../../src/providers/s3/types';
import './testUtils';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('../../../../src/providers/s3/utils/client/s3data');
jest.mock('@aws-amplify/core', () => ({
ConsoleLogger: jest.fn().mockImplementation(function ConsoleLogger() {
return { debug: jest.fn() };
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/__tests__/providers/s3/apis/getUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getUrl } from '../../../../src/providers/s3/apis';
import {
getPresignedGetObjectUrl,
headObject,
} from '../../../../src/providers/s3/utils/client';
} from '../../../../src/providers/s3/utils/client/s3data';
import {
GetUrlInput,
GetUrlOutput,
Expand All @@ -17,7 +17,7 @@ import {
} from '../../../../src/providers/s3/types';
import './testUtils';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('../../../../src/providers/s3/utils/client/s3data');
jest.mock('@aws-amplify/core', () => ({
ConsoleLogger: jest.fn().mockImplementation(function ConsoleLogger() {
return { debug: jest.fn() };
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/__tests__/providers/s3/apis/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
import { Amplify, StorageAccessLevel } from '@aws-amplify/core';

import { listObjectsV2 } from '../../../../src/providers/s3/utils/client';
import { listObjectsV2 } from '../../../../src/providers/s3/utils/client/s3data';
import { list } from '../../../../src/providers/s3';
import {
ListAllInput,
Expand All @@ -18,7 +18,7 @@ import {
} from '../../../../src/providers/s3/types';
import './testUtils';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('../../../../src/providers/s3/utils/client/s3data');
jest.mock('@aws-amplify/core', () => ({
ConsoleLogger: jest.fn().mockImplementation(function ConsoleLogger() {
return { debug: jest.fn() };
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/__tests__/providers/s3/apis/remove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
import { Amplify, StorageAccessLevel } from '@aws-amplify/core';

import { deleteObject } from '../../../../src/providers/s3/utils/client';
import { deleteObject } from '../../../../src/providers/s3/utils/client/s3data';
import { remove } from '../../../../src/providers/s3/apis';
import { StorageValidationErrorCode } from '../../../../src/errors/types/validation';
import {
Expand All @@ -15,7 +15,7 @@ import {
} from '../../../../src/providers/s3/types';
import './testUtils';

jest.mock('../../../../src/providers/s3/utils/client');
jest.mock('../../../../src/providers/s3/utils/client/s3data');
jest.mock('@aws-amplify/core', () => ({
ConsoleLogger: jest.fn().mockImplementation(function ConsoleLogger() {
return { debug: jest.fn() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
headObject,
listParts,
uploadPart,
} from '../../../../../src/providers/s3/utils/client';
} from '../../../../../src/providers/s3/utils/client/s3data';
import { getMultipartUploadHandlers } from '../../../../../src/providers/s3/apis/uploadData/multipart';
import {
StorageValidationErrorCode,
Expand All @@ -25,7 +25,7 @@ import '../testUtils';
import { S3InternalConfig } from '../../../../../src/providers/s3/apis/internal/types';

jest.mock('@aws-amplify/core');
jest.mock('../../../../../src/providers/s3/utils/client');
jest.mock('../../../../../src/providers/s3/utils/client/s3data');

const credentials: AWSCredentials = {
accessKeyId: 'accessKeyId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import { AWSCredentials } from '@aws-amplify/core/internals/utils';

import { putObject } from '../../../../../src/providers/s3/utils/client';
import { putObject } from '../../../../../src/providers/s3/utils/client/s3data';
import { calculateContentMd5 } from '../../../../../src/providers/s3/utils';
import { putObjectJob } from '../../../../../src/providers/s3/apis/uploadData/putObjectJob';
import '../testUtils';
import { S3InternalConfig } from '../../../../../src/providers/s3/apis/internal/types';

jest.mock('../../../../../src/providers/s3/utils/client');
jest.mock('../../../../../src/providers/s3/utils/client/s3data');
jest.mock('../../../../../src/providers/s3/utils', () => {
const utils = jest.requireActual('../../../../../src/providers/s3/utils');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { abortMultipartUpload } from '../../../../../../../src/providers/s3/utils/client';
import { abortMultipartUpload } from '../../../../../../../src/providers/s3/utils/client/s3data';
import { ApiFunctionalTestCase } from '../../testUtils/types';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { completeMultipartUpload } from '../../../../../../../src/providers/s3/utils/client';
import { completeMultipartUpload } from '../../../../../../../src/providers/s3/utils/client/s3data';
import { ApiFunctionalTestCase } from '../../testUtils/types';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { copyObject } from '../../../../../../../src/providers/s3/utils/client';
import { copyObject } from '../../../../../../../src/providers/s3/utils/client/s3data';
import { ApiFunctionalTestCase } from '../../testUtils/types';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { createMultipartUpload } from '../../../../../../../src/providers/s3/utils/client';
import { createMultipartUpload } from '../../../../../../../src/providers/s3/utils/client/s3data';
import { ApiFunctionalTestCase } from '../../testUtils/types';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { deleteObject } from '../../../../../../../src/providers/s3/utils/client';
import { deleteObject } from '../../../../../../../src/providers/s3/utils/client/s3data';
import { ApiFunctionalTestCase } from '../../testUtils/types';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { getDataAccess } from '../../../../../../../src/providers/s3/utils/client/s3control';
import { ApiFunctionalTestCase } from '../../testUtils/types';

import {
DEFAULT_RESPONSE_HEADERS,
defaultConfig,
expectedMetadata,
} from './shared';

const MOCK_ACCOUNT_ID = 'accountId';
const MOCK_ACCESS_ID = 'accessId';
const MOCK_SECRET_ACCESS_KEY = 'secretAccessKey';
const MOCK_SESSION_TOKEN = 'sessionToken';
const MOCK_EXPIRATION = '2013-09-17T18:07:53.000Z';
const MOCK_EXPIRATION_DATE = new Date(MOCK_EXPIRATION);
const MOCK_GRANT_TARGET = 'matchedGrantTarget';

// API Reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_GetDataAccess.html
const getDataAccessHappyCase: ApiFunctionalTestCase<typeof getDataAccess> = [
'happy case',
'getDataAccess',
getDataAccess,
defaultConfig,
{
AccountId: MOCK_ACCOUNT_ID,
Target: 's3://my-bucket/path/to/object.md',
TargetType: 'Object',
DurationSeconds: 100,
Permission: 'READWRITE',
Privilege: 'Default',
},
expect.objectContaining({
url: expect.objectContaining({
href: 'https://accountid.s3-control.us-east-1.amazonaws.com/v20180820/accessgrantsinstance/dataaccess?durationSeconds=100&permission=READWRITE&privilege=Default&target=s3%3A%2F%2Fmy-bucket%2Fpath%2Fto%2Fobject.md&targetType=Object',
}),
method: 'GET',
headers: expect.objectContaining({
'x-amz-account-id': MOCK_ACCOUNT_ID,
}),
}),
{
status: 200,
headers: {
...DEFAULT_RESPONSE_HEADERS,
},
body: `
<?xml version="1.0" encoding="UTF-8"?>
<GetDataAccessResult>
<Credentials>
<AccessKeyId>${MOCK_ACCESS_ID}</AccessKeyId>
<SecretAccessKey>${MOCK_SECRET_ACCESS_KEY}</SecretAccessKey>
<SessionToken>${MOCK_SESSION_TOKEN}</SessionToken>
<Expiration>${MOCK_EXPIRATION}</Expiration>
</Credentials>
<MatchedGrantTarget>${MOCK_GRANT_TARGET}</MatchedGrantTarget>
</GetDataAccessResult>
`,
},
{
$metadata: expect.objectContaining(expectedMetadata),
Credentials: {
AccessKeyId: MOCK_ACCESS_ID,
SecretAccessKey: MOCK_SECRET_ACCESS_KEY,
SessionToken: MOCK_SESSION_TOKEN,
Expiration: MOCK_EXPIRATION_DATE,
},
MatchedGrantTarget: MOCK_GRANT_TARGET,
},
];

const getDataAccessErrorCase: ApiFunctionalTestCase<typeof getDataAccess> = [
'error case',
'getDataAccess',
getDataAccess,
defaultConfig,
getDataAccessHappyCase[4],
getDataAccessHappyCase[5],
{
status: 403,
headers: DEFAULT_RESPONSE_HEADERS,
body: `
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>656c76696e6727732072657175657374</RequestId>
<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>
</Error>
`,
},
{
message: 'Access Denied',
name: 'AccessDenied',
},
];

export default [getDataAccessHappyCase, getDataAccessErrorCase];
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { getObject } from '../../../../../../../src/providers/s3/utils/client';
import { getObject } from '../../../../../../../src/providers/s3/utils/client/s3data';
import { ApiFunctionalTestCase } from '../../testUtils/types';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { headObject } from '../../../../../../../src/providers/s3/utils/client';
import { headObject } from '../../../../../../../src/providers/s3/utils/client/s3data';
import { ApiFunctionalTestCase } from '../../testUtils/types';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import copyObjectCases from './copyObject';
import deleteObjectCases from './deleteObject';
import getObjectCases from './getObject';
import headObjectCases from './headObject';
import getDataAccess from './getDataAccess';
import listCallerAccessGrants from './listCallerAccessGrants';

export default [
...listObjectsV2Cases,
Expand All @@ -25,4 +27,6 @@ export default [
...deleteObjectCases,
...getObjectCases,
...headObjectCases,
...listCallerAccessGrants,
...getDataAccess,
];
Loading

0 comments on commit bcd8c9d

Please sign in to comment.