From 9ba73dadad7949af652bfde6e9aa0ce332767908 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 13 Nov 2023 18:22:13 -0500 Subject: [PATCH 1/3] update primary key label in tests --- src/app.test.js | 4 ++-- src/authorizeRequest/authorizeRequest.test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app.test.js b/src/app.test.js index e2524a8..f6f6c3c 100644 --- a/src/app.test.js +++ b/src/app.test.js @@ -12,7 +12,7 @@ process.env.DYNAMODB_TABLE = 'test-table'; // Mock the ddb client. ddbMock.on(GetCommand, { - Key: { SiteAndGroupKey: 'PROTECTED_SITES' }, + Key: { PK: 'PROTECTED_SITES' }, }).resolves({ Item: { ProtectedSites: JSON.stringify([ @@ -22,7 +22,7 @@ ddbMock.on(GetCommand, { ]), }, }).on(GetCommand, { - Key: { SiteAndGroupKey: 'example.host.bu.edu/protected#somegroup' }, + Key: { PK: 'example.host.bu.edu/protected#somegroup' }, }).resolves({ Item: { rules: JSON.stringify({ diff --git a/src/authorizeRequest/authorizeRequest.test.js b/src/authorizeRequest/authorizeRequest.test.js index 850d3dd..c6e4e15 100644 --- a/src/authorizeRequest/authorizeRequest.test.js +++ b/src/authorizeRequest/authorizeRequest.test.js @@ -10,7 +10,7 @@ process.env.DYNAMODB_TABLE = 'test-table'; // Mock the ddb client. ddbMock.on(GetCommand, { - Key: { SiteAndGroupKey: 'example.host.bu.edu/somesite#somegroup' }, + Key: { PK: 'example.host.bu.edu/somesite#somegroup' }, }).resolves({ Item: { rules: JSON.stringify({ @@ -22,7 +22,7 @@ ddbMock.on(GetCommand, { }), }, }).on(GetCommand, { - Key: { SiteAndGroupKey: 'example.host.bu.edu/somesite#othergroup' }, + Key: { PK: 'example.host.bu.edu/somesite#othergroup' }, }).resolves({ Item: { rules: JSON.stringify({ @@ -32,7 +32,7 @@ ddbMock.on(GetCommand, { }), }, }).on(GetCommand, { - Key: { SiteAndGroupKey: 'example.host.bu.edu/#somegroup' }, + Key: { PK: 'example.host.bu.edu/#somegroup' }, }).resolves({ Item: { rules: JSON.stringify({ From b8755ae71fba0ffe6bab9ad2317587b4d65676d0 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 13 Nov 2023 18:24:38 -0500 Subject: [PATCH 2/3] change label of primary key in queries --- src/authorizeRequest/authorizeRequest.js | 2 +- src/authorizeRequest/getProtectedSites.js | 2 +- src/getOrCreateObject/resizeAndSave/lookupCustomCrop.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/authorizeRequest/authorizeRequest.js b/src/authorizeRequest/authorizeRequest.js index 9ec9c6f..3627c98 100644 --- a/src/authorizeRequest/authorizeRequest.js +++ b/src/authorizeRequest/authorizeRequest.js @@ -69,7 +69,7 @@ async function authorizeRequest(userRequest, siteRule) { // to avoid INFO Failed to find the group in DynamoDB for group: entire-bu-community const { Item } = await dynamoDb.get({ TableName: tableName, - Key: { SiteAndGroupKey: siteAndGroupKey }, + Key: { PK: siteAndGroupKey }, }); if (Item == null) { diff --git a/src/authorizeRequest/getProtectedSites.js b/src/authorizeRequest/getProtectedSites.js index cd9484b..7815603 100644 --- a/src/authorizeRequest/getProtectedSites.js +++ b/src/authorizeRequest/getProtectedSites.js @@ -17,7 +17,7 @@ async function getProtectedSites() { const { Item } = await dynamoDb.get({ TableName: tableName, - Key: { SiteAndGroupKey: 'PROTECTED_SITES' }, + Key: { PK: 'PROTECTED_SITES' }, }); const { ProtectedSites } = Item; diff --git a/src/getOrCreateObject/resizeAndSave/lookupCustomCrop.js b/src/getOrCreateObject/resizeAndSave/lookupCustomCrop.js index 0e57a00..2c3d380 100644 --- a/src/getOrCreateObject/resizeAndSave/lookupCustomCrop.js +++ b/src/getOrCreateObject/resizeAndSave/lookupCustomCrop.js @@ -28,7 +28,7 @@ async function lookupCustomCrop(url, domain, sizeMatch) { const params = { TableName: tableName, Key: { - SiteAndGroupKey: `SIZES#${domain}${siteName}`, + PK: `SIZES#${domain}${siteName}`, }, }; From 02c62eff8a75ee6560c4353110fb40a3b952bfb1 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 13 Nov 2023 18:27:13 -0500 Subject: [PATCH 3/3] add a new temporary table that uses the new table structure. If this were a live transition, the original data could be moved to the new table. --- template.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/template.yaml b/template.yaml index 2a0f939..febc38c 100644 --- a/template.yaml +++ b/template.yaml @@ -147,12 +147,12 @@ Resources: Timeout: 30 Environment: Variables: - DYNAMODB_TABLE: !Ref AccessControlDynamoDB + DYNAMODB_TABLE: !Ref TempAccessControlDynamoDB ORIGINAL_BUCKET: !Ref S3Bucket # The function needs permission to call back to the S3 Object Lambda Access Point with the WriteGetObjectResponse. Policies: - DynamoDBReadPolicy: - TableName: !Ref AccessControlDynamoDB + TableName: !Ref TempAccessControlDynamoDB - S3CrudPolicy: BucketName: !Ref S3Bucket - Statement: @@ -169,6 +169,13 @@ Resources: Type: String TableName: !Sub ${AWS::StackName}-AccessControl + TempAccessControlDynamoDB: + Type: AWS::Serverless::SimpleTable + Properties: + PrimaryKey: + Name: PK + Type: String + TableName: !Sub ${AWS::StackName}-TempAccessControl Outputs: S3BucketName: