Skip to content

Commit

Permalink
feat(amplify-category-storage): add CRUD PartiQL permissions for Dyna…
Browse files Browse the repository at this point in the history
…moDB (#11002)
  • Loading branch information
johnf committed Jun 16, 2023
1 parent 911faa7 commit 19ed508
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslint-dictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@
"openpgp",
"opensearch",
"orgs",
"Parti",
"parens",
"pathname",
"pathnames",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DynamoDBCLIInputs,
FieldType,
} from '../../../../provider-utils/awscloudformation/service-walkthrough-types/dynamoDB-user-input-types';
import { getIAMPolicies } from '../../../../provider-utils/awscloudformation/service-walkthroughs/dynamoDb-walkthrough';

jest.mock('@aws-amplify/amplify-cli-core');
jest.mock('@aws-amplify/amplify-prompts');
Expand Down Expand Up @@ -243,3 +244,29 @@ describe('update ddb walkthrough tests', () => {
expect(DynamoDBInputState.prototype.saveCliInputPayload).toHaveBeenCalledWith(expectedCLIInputsJSON);
});
});

describe('PartiQL Policies', () => {
it('create', async () => {
const { policy } = getIAMPolicies('Dummy', ['create']);
const actions = policy.Action as string[];
expect(actions.includes('dynamodb:PartiQLInsert')).toBe(true);
});

it('update', async () => {
const { policy } = getIAMPolicies('Dummy', ['update']);
const actions = policy.Action as string[];
expect(actions.includes('dynamodb:PartiQLUpdate')).toBe(true);
});

it('read', async () => {
const { policy } = getIAMPolicies('Dummy', ['read']);
const actions = policy.Action as string[];
expect(actions.includes('dynamodb:PartiQLSelect')).toBe(true);
});

it('delete', async () => {
const { policy } = getIAMPolicies('Dummy', ['delete']);
const actions = policy.Action as string[];
expect(actions.includes('dynamodb:PartiQLDelete')).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -731,22 +731,30 @@ export function migrate(context: $TSContext, projectPath: any, resourceName: any
}

export function getIAMPolicies(resourceName: string, crudOptions: $TSAny) {
let policy = {};
let policy: $TSObject = {};
const actions: string[] = [];

crudOptions.forEach((crudOption: $TSAny) => {
switch (crudOption) {
case 'create':
actions.push('dynamodb:Put*', 'dynamodb:Create*', 'dynamodb:BatchWriteItem');
actions.push('dynamodb:Put*', 'dynamodb:Create*', 'dynamodb:BatchWriteItem', 'dynamodb:PartiQLInsert');
break;
case 'update':
actions.push('dynamodb:Update*', 'dynamodb:RestoreTable*');
actions.push('dynamodb:Update*', 'dynamodb:RestoreTable*', 'dynamodb:PartiQLUpdate');
break;
case 'read':
actions.push('dynamodb:Get*', 'dynamodb:BatchGetItem', 'dynamodb:List*', 'dynamodb:Describe*', 'dynamodb:Scan', 'dynamodb:Query');
actions.push(
'dynamodb:Get*',
'dynamodb:BatchGetItem',
'dynamodb:List*',
'dynamodb:Describe*',
'dynamodb:Scan',
'dynamodb:Query',
'dynamodb:PartiQLSelect',
);
break;
case 'delete':
actions.push('dynamodb:Delete*');
actions.push('dynamodb:Delete*', 'dynamodb:PartiQLDelete');
break;
default:
console.log(`${crudOption} not supported`);
Expand Down

0 comments on commit 19ed508

Please sign in to comment.