From 7a744d39f024f3e397b31be9bde51df06943967c Mon Sep 17 00:00:00 2001 From: joern-belonio <54737663+joern-belonio@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:54:35 +0200 Subject: [PATCH 1/4] fix(): Source ARN Regex The regex "^arn:(aws[a-zA-Z0-9-]*):([a-zA-Z0-9-]+):([a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\\d{1})?:(\\d{12})?:(.+)$ has to use\\d{1} instead of d{1} or all arns like eu-central-1 are rejected as invalid. --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index f254d55..7f832ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -339,7 +339,7 @@ class ServerlessPipes { pipe: string ): void { const arnRegex = new RegExp( - "^arn:(aws[a-zA-Z0-9-]*):([a-zA-Z0-9-]+):([a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-d{1})?:(d{12})?:(.+)$" + "^arn:(aws[a-zA-Z0-9-]*):([a-zA-Z0-9-]+):([a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\\d{1})?:(\\d{12})?:(.+)$" ); if (typeof arn === "object") arn = Object.keys(arn)[0]; if ( From b2d79e3aa07ed627d958fc117bd03c30597af676 Mon Sep 17 00:00:00 2001 From: Marco Klein Date: Tue, 9 Jul 2024 16:30:40 +0200 Subject: [PATCH 2/4] test: :white_check_mark: Add test for arn validation fix. --- tests/pipes.test.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/pipes.test.ts b/tests/pipes.test.ts index 91ae78c..6d80b34 100644 --- a/tests/pipes.test.ts +++ b/tests/pipes.test.ts @@ -1,6 +1,7 @@ -import { expect, assert } from "chai"; -import ServerlessPipes from "../src/index"; +import { assert, expect } from "chai"; import Serverless from "serverless"; + +import ServerlessPipes from "../src"; import { compileBasedOnSourceType, compileBasedOnTargetType, @@ -255,6 +256,18 @@ describe("ServerlessPipes", () => { expect(serverlessPipes.validateArn(arn, type, pipe)).to.be.undefined; }); + it("should vaidateArn without error if proper arn is given", () => { + const type = "source"; + const pipe = "testPipe"; + expect( + serverlessPipes.validateArn( + "arn:aws:sqs:eu-central-1:123456789012:queue-name", + type, + pipe + ) + ).to.be.undefined; + }); + it("should throw error if validateArn doesnt get invalid input parameters", () => { try { const arn = { "Fn::GetAtt:": ["SourceSQSQueue", "Arn"] }; //invalid arn; starts with Fn::GetAtt:: instead of Fn::GetAtt From 88fa2e9e63561919affc679b99556f736d022848 Mon Sep 17 00:00:00 2001 From: Marco Klein Date: Tue, 9 Jul 2024 16:37:07 +0200 Subject: [PATCH 3/4] docs: :memo: Add arns as strings in example of README --- README.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a0a6ef8..8de7047 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - # Serverless Pipes Plugin Serverless Framework plugin called as "pipes", used to create EventBridge Pipes by providing the required event sources, targets and other parameters as needed. @@ -16,8 +15,8 @@ yarn add serverless-pipes ``` ## Allowed Services -At the initial version of the plugin, the below mentioned AWS services are supported for the source, target and enrichment in the EventBridge Pipes. We will expand to other services in the future. +At the initial version of the plugin, the below mentioned AWS services are supported for the source, target and enrichment in the EventBridge Pipes. We will expand to other services in the future. ### Source @@ -36,8 +35,6 @@ At the initial version of the plugin, the below mentioned AWS services are suppo - [Lambda Function](docs/parameters/EnrichmentParameters.md) - - ## Usage ```yaml @@ -51,7 +48,7 @@ functions: handler: functions/pipeEnricher.handler pipes: - testPipe: #pipeName + testPipe: #pipeName enabled: true source: sqs: @@ -61,7 +58,21 @@ pipes: sns: arn: Fn::GetAtt: [TargetSNSTopic, TopicArn] - enrichment: + enrichment: + name: pipeEnricher + filter: + - Pattern: "{ \"body\": { \"message\": [ \"hello\" ], \"city\": [ \"hey\" ] }}" + iamRolePipes: + type: "individual" + testPipe: #pipeName + enabled: true + source: + sqs: + arn: arn:aws:sqs:eu-central-1:123456789012:source-queue-name + target: + sns: + arn: arn:aws:sqs:eu-central-1:123456789012:target-queue-name + enrichment: name: pipeEnricher filter: - Pattern: "{ \"body\": { \"message\": [ \"hello\" ], \"city\": [ \"hey\" ] }}" From a48e5901f3aca460bfc78b9a18c0ccdfcd7f0a1c Mon Sep 17 00:00:00 2001 From: Marco Klein Date: Tue, 9 Jul 2024 16:38:40 +0200 Subject: [PATCH 4/4] docs: :truck: Rename example pipe --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8de7047..c0402cb 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ plugins: - serverless-pipes functions: - pipeEnricher: - handler: functions/pipeEnricher.handler + pipeEnricher: + handler: functions/pipeEnricher.handler pipes: testPipe: #pipeName @@ -61,10 +61,11 @@ pipes: enrichment: name: pipeEnricher filter: - - Pattern: "{ \"body\": { \"message\": [ \"hello\" ], \"city\": [ \"hey\" ] }}" + - Pattern: '{ "body": { "message": [ "hello" ], "city": [ "hey" ] }}' iamRolePipes: type: "individual" - testPipe: #pipeName + + anotherTestPipe: #pipeName enabled: true source: sqs: @@ -75,10 +76,9 @@ pipes: enrichment: name: pipeEnricher filter: - - Pattern: "{ \"body\": { \"message\": [ \"hello\" ], \"city\": [ \"hey\" ] }}" + - Pattern: '{ "body": { "message": [ "hello" ], "city": [ "hey" ] }}' iamRolePipes: type: "individual" - ``` For documentation refer [Docs](docs/index.md)