From 1e3f42ce271855114e17812866faecae4df72d49 Mon Sep 17 00:00:00 2001 From: Doug Toppin Date: Fri, 3 Feb 2023 14:39:31 -0500 Subject: [PATCH 1/3] Remove unicode changes from backend, fix unicode support in demo-ui --- source/demo-ui/scripts.js | 15 +++++++++++---- source/image-handler/image-handler.ts | 2 +- source/image-handler/image-request.ts | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/source/demo-ui/scripts.js b/source/demo-ui/scripts.js index dfaa7e622..4966fde6a 100644 --- a/source/demo-ui/scripts.js +++ b/source/demo-ui/scripts.js @@ -18,10 +18,13 @@ function importOriginalImage() { // Assemble the image request const request = { bucket: bucketName, - key: encodeURIComponent(keyName) + key: keyName } const strRequest = JSON.stringify(request); - const encRequest = btoa(strRequest); + const encRequest = btoa(encodeURIComponent(strRequest).replace(/%([0-9A-F]{2})/g, function(match, p1) { + return String.fromCharCode(parseInt(p1, 16)) + })); + // Import the image data into the element $(`#img-original`) .attr(`src`, `${appVariables.apiEndpoint}/${encRequest}`) @@ -77,14 +80,18 @@ function getPreviewImage() { // Set up the request body const request = { bucket: bucketName, - key: encodeURIComponent(keyName), + key: keyName, edits: _edits } if (Object.keys(request.edits).length === 0) { delete request.edits } console.log(request); // Setup encoded request const str = JSON.stringify(request); - const enc = btoa(str); + + const enc = btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) { + return String.fromCharCode(parseInt(p1, 16)) + })); + // Fill the preview image $(`#img-preview`).attr(`src`, `${appVariables.apiEndpoint}/${enc}`); // Fill the request body field diff --git a/source/image-handler/image-handler.ts b/source/image-handler/image-handler.ts index beef93f36..82cd67937 100644 --- a/source/image-handler/image-handler.ts +++ b/source/image-handler/image-handler.ts @@ -443,7 +443,7 @@ export class ImageHandler { alpha: string, sourceImageMetadata: sharp.Metadata ): Promise { - const params = { Bucket: bucket, Key: decodeURIComponent(key) }; + const params = { Bucket: bucket, Key: key }; try { const { width, height } = sourceImageMetadata; const overlayImage: S3.GetObjectOutput = await this.s3Client.getObject(params).promise(); diff --git a/source/image-handler/image-request.ts b/source/image-handler/image-request.ts index d23350d75..f17b25e44 100644 --- a/source/image-handler/image-request.ts +++ b/source/image-handler/image-request.ts @@ -269,7 +269,7 @@ export class ImageRequest { if (requestType === RequestTypes.DEFAULT) { // Decode the image request and return the image key const { key } = this.decodeRequest(event); - return decodeURIComponent(key); + return key; } if (requestType === RequestTypes.THUMBOR || requestType === RequestTypes.CUSTOM) { From c7a157d9a904243973df139321051e2c233fadf4 Mon Sep 17 00:00:00 2001 From: garvit singh Date: Mon, 6 Feb 2023 12:02:19 -0500 Subject: [PATCH 2/3] Use stack name in Service Catalog Application name for multiple cfn stack deployments (#438) * Add stack name to service catalog application This allows multiple stack deployments in the same account, region * Update cdk snapshot * Add changelog entry * Prepend AppRegistry application name with static name Stack name is used in naming AppRegistry application and attribute group; which must not begin with aws. The change adds support for stack names starting with aws-* --- CHANGELOG.md | 1 + .../common-resources-construct.ts | 4 ++-- .../test/__snapshots__/constructs.test.ts.snap | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c39e24f09..cdbcba1ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - package-lock.json for all modules [#426](https://github.com/aws-solutions/serverless-image-handler/pull/426) - github workflows for running unit test, eslint and prettier formatting, cdk nag, security scans [#402](https://github.com/aws-solutions/serverless-image-handler/pull/402) - demo-ui unicode support [#416](https://github.com/aws-solutions/serverless-image-handler/issues/416) +- support for multiple cloudformation stack deployments in the same region ### Changed diff --git a/source/constructs/lib/common-resources/common-resources-construct.ts b/source/constructs/lib/common-resources/common-resources-construct.ts index 5878398e9..20b7e9f70 100644 --- a/source/constructs/lib/common-resources/common-resources-construct.ts +++ b/source/constructs/lib/common-resources/common-resources-construct.ts @@ -93,7 +93,7 @@ export class CommonResources extends Construct { const applicationType = "AWS-Solutions"; const application = new appreg.Application(stack, "AppRegistry", { - applicationName: Fn.join("-", [props.applicationName, Aws.REGION, Aws.ACCOUNT_ID]), + applicationName: Fn.join("-", ["AppRegistry", Aws.STACK_NAME, Aws.REGION, Aws.ACCOUNT_ID]), description: `Service Catalog application to track and manage all your resources for the solution ${props.applicationName}`, }); application.associateStack(stack); @@ -104,7 +104,7 @@ export class CommonResources extends Construct { Tags.of(application).add("Solutions:ApplicationType", applicationType); const attributeGroup = new appreg.AttributeGroup(stack, "DefaultApplicationAttributes", { - attributeGroupName: Aws.STACK_NAME, + attributeGroupName: `AppRegistry-${Aws.STACK_NAME}`, description: "Attribute group for solution information", attributes: { applicationType, diff --git a/source/constructs/test/__snapshots__/constructs.test.ts.snap b/source/constructs/test/__snapshots__/constructs.test.ts.snap index 02bbeaf95..1546e1cc4 100644 --- a/source/constructs/test/__snapshots__/constructs.test.ts.snap +++ b/source/constructs/test/__snapshots__/constructs.test.ts.snap @@ -333,7 +333,10 @@ exports[`Serverless Image Handler Stack Snapshot 1`] = ` "Fn::Join": [ "-", [ - "sih", + "AppRegistry", + { + "Ref": "AWS::StackName", + }, { "Ref": "AWS::Region", }, @@ -1823,7 +1826,15 @@ exports[`Serverless Image Handler Stack Snapshot 1`] = ` }, "Description": "Attribute group for solution information", "Name": { - "Ref": "AWS::StackName", + "Fn::Join": [ + "", + [ + "AppRegistry-", + { + "Ref": "AWS::StackName", + }, + ], + ], }, "Tags": { "SolutionId": "S0ABC", From 16770174e54f39d4e56ae3a056a4fb2531958eb5 Mon Sep 17 00:00:00 2001 From: Doug Toppin Date: Tue, 7 Feb 2023 15:02:52 -0500 Subject: [PATCH 3/3] Update to v6.1.1, set release date, include PR link --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdbcba1ca..594ede86a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,14 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [6.1.1] - 2023-02-02 +## [6.1.1] - 2023-02-09 ### Added - package-lock.json for all modules [#426](https://github.com/aws-solutions/serverless-image-handler/pull/426) - github workflows for running unit test, eslint and prettier formatting, cdk nag, security scans [#402](https://github.com/aws-solutions/serverless-image-handler/pull/402) - demo-ui unicode support [#416](https://github.com/aws-solutions/serverless-image-handler/issues/416) -- support for multiple cloudformation stack deployments in the same region +- support for multiple cloudformation stack deployments in the same region [#438](https://github.com/aws-solutions/serverless-image-handler/pull/438) ### Changed