diff --git a/packages/@aws-cdk/aws-events/README.md b/packages/@aws-cdk/aws-events/README.md index 456e4b18f9ad1..d2e3417b6367c 100644 --- a/packages/@aws-cdk/aws-events/README.md +++ b/packages/@aws-cdk/aws-events/README.md @@ -114,10 +114,11 @@ const rule = new events.Rule(this, 'rule', { // 'OR' condition 'source-storage-class': events.Match.anyOf( - events.Match.prefix("GLACIER"), + events.Match.prefix("GLACIER"), events.Match.exactString('DEEP_ARCHIVE'), ), }, + 'detail-type': events.Match.equalsIgnoreCase('object created'), // If you prefer, you can use a low level array of strings, as directly consumed by EventBridge source: ['aws.s3'], diff --git a/packages/@aws-cdk/aws-events/lib/event-pattern.ts b/packages/@aws-cdk/aws-events/lib/event-pattern.ts index c9d520a6bb030..494ba76ca7141 100644 --- a/packages/@aws-cdk/aws-events/lib/event-pattern.ts +++ b/packages/@aws-cdk/aws-events/lib/event-pattern.ts @@ -40,21 +40,35 @@ export class Match implements IResolvable { /** * Matches a string, exactly, in the JSON of the event */ - public static exactString(value: string): string [] { + public static exactString(value: string): string[] { return this.fromObjects([value]); } + /** + * Matches a string, regardless of case, in the JSON of the event + */ + public static equalsIgnoreCase(value: string): string[] { + return this.fromObjects([{ 'equals-ignore-case': value }]); + } + /** * Matches strings with the given prefix in the JSON of the event */ - static prefix(value: string): string[] { + public static prefix(value: string): string[] { return this.fromObjects([{ prefix: value }]); } + /** + * Matches strings with the given suffix in the JSON of the event + */ + public static suffix(value: string): string[] { + return this.fromObjects([{ suffix: value }]); + } + /** * Matches IPv4 and IPv6 network addresses using the Classless Inter-Domain Routing (CIDR) format */ - static cidr(range: string): string[] { + public static cidr(range: string): string[] { const ipv4Regex = /^([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))?$/igm; const ipv6Regex = /^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$/igm; @@ -69,7 +83,7 @@ export class Match implements IResolvable { * Matches IPv4 and IPv6 network addresses using the Classless Inter-Domain Routing (CIDR) format. * Alias of `cidr()`. */ - static ipAddressRange(range: string): string[] { + public static ipAddressRange(range: string): string[] { return Match.cidr(range); } @@ -77,7 +91,7 @@ export class Match implements IResolvable { * Matches anything except what's provided in the rule. The list of provided values must contain * only strings or only numbers. */ - static anythingBut(...values: any[]): string[] { + public static anythingBut(...values: any[]): string[] { if (values.length === 0) { throw new Error('anythingBut matchers must be non-empty lists'); } @@ -95,7 +109,7 @@ export class Match implements IResolvable { /** * Matches any string that doesn't start with the given prefix. */ - static anythingButPrefix(prefix: string): string[] { + public static anythingButPrefix(prefix: string): string[] { return this.fromObjects([{ 'anything-but': { prefix: prefix } }]); } @@ -142,7 +156,7 @@ export class Match implements IResolvable { * @param lower Lower bound (inclusive) * @param upper Upper bound (inclusive) */ - static interval(lower: number, upper: number): string[] { + public static interval(lower: number, upper: number): string[] { if (lower > upper) { throw new Error(`Invalid interval: [${lower}, ${upper}]`); } diff --git a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/IntegTestBatchDefaultEnvVarsStackDefaultTestDeployAssertC15EFFF2.assets.json b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/IntegTestBatchDefaultEnvVarsStackDefaultTestDeployAssertC15EFFF2.assets.json index 21546707f8b49..0ee3c895dea43 100644 --- a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/IntegTestBatchDefaultEnvVarsStackDefaultTestDeployAssertC15EFFF2.assets.json +++ b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/IntegTestBatchDefaultEnvVarsStackDefaultTestDeployAssertC15EFFF2.assets.json @@ -1,5 +1,5 @@ { - "version": "20.0.0", + "version": "21.0.0", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/RuleStack.assets.json b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/RuleStack.assets.json index 493c9f680c6b6..21e208bc4a0a6 100644 --- a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/RuleStack.assets.json +++ b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/RuleStack.assets.json @@ -1,7 +1,7 @@ { - "version": "20.0.0", + "version": "21.0.0", "files": { - "f8f3154528da0601b814868afeeb0474f8644916293f783617ff6d56a6d92035": { + "f9728b2d2c64ff638563c8cc4a3e8eb9ddf3074e2ae01d68fde11aeda0968fb1": { "source": { "path": "RuleStack.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "f8f3154528da0601b814868afeeb0474f8644916293f783617ff6d56a6d92035.json", + "objectKey": "f9728b2d2c64ff638563c8cc4a3e8eb9ddf3074e2ae01d68fde11aeda0968fb1.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/RuleStack.template.json b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/RuleStack.template.json index 74e687f119c09..5025f8b2c914b 100644 --- a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/RuleStack.template.json +++ b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/RuleStack.template.json @@ -108,6 +108,16 @@ "prefix": "sensitive-" } } + ], + "suffix": [ + { + "suffix": ".com" + } + ], + "equalsIgnoreCase": [ + { + "equals-ignore-case": "ignore case" + } ] }, "detail-type": [ diff --git a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/cdk.out b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/cdk.out index 588d7b269d34f..8ecc185e9dbee 100644 --- a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"20.0.0"} \ No newline at end of file +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/integ.json b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/integ.json index 26b8dc998323a..3716c914b03f1 100644 --- a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/integ.json @@ -1,11 +1,12 @@ { - "version": "20.0.0", + "version": "21.0.0", "testCases": { "IntegTest-BatchDefaultEnvVarsStack/DefaultTest": { "stacks": [ "RuleStack" ], - "assertionStack": "IntegTest-BatchDefaultEnvVarsStack/DefaultTest/DeployAssert" + "assertionStack": "IntegTest-BatchDefaultEnvVarsStack/DefaultTest/DeployAssert", + "assertionStackName": "IntegTestBatchDefaultEnvVarsStackDefaultTestDeployAssertC15EFFF2" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/manifest.json b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/manifest.json index dd5bfe14671b1..4117383bdd483 100644 --- a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/manifest.json @@ -1,12 +1,6 @@ { - "version": "20.0.0", + "version": "21.0.0", "artifacts": { - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - }, "RuleStack.assets": { "type": "cdk:asset-manifest", "properties": { @@ -23,7 +17,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/f8f3154528da0601b814868afeeb0474f8644916293f783617ff6d56a6d92035.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/f9728b2d2c64ff638563c8cc4a3e8eb9ddf3074e2ae01d68fde11aeda0968fb1.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -106,6 +100,12 @@ ] }, "displayName": "IntegTest-BatchDefaultEnvVarsStack/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/tree.json b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/tree.json index f7174f4afdd17..f68ebe1fc832e 100644 --- a/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-events/test/integ.rule.js.snapshot/tree.json @@ -4,14 +4,6 @@ "id": "App", "path": "", "children": { - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" - } - }, "RuleStack": { "id": "RuleStack", "path": "RuleStack", @@ -131,6 +123,16 @@ "prefix": "sensitive-" } } + ], + "suffix": [ + { + "suffix": ".com" + } + ], + "equalsIgnoreCase": [ + { + "equals-ignore-case": "ignore case" + } ] }, "detail-type": [ @@ -172,11 +174,27 @@ "fqn": "@aws-cdk/aws-events.Rule", "version": "0.0.0" } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "RuleStack/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "RuleStack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" } }, "IntegTest-BatchDefaultEnvVarsStack": { @@ -192,15 +210,33 @@ "path": "IntegTest-BatchDefaultEnvVarsStack/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.1.85" + "version": "10.1.154" } }, "DeployAssert": { "id": "DeployAssert", "path": "IntegTest-BatchDefaultEnvVarsStack/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "IntegTest-BatchDefaultEnvVarsStack/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "IntegTest-BatchDefaultEnvVarsStack/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } + } + }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" } } }, @@ -214,11 +250,19 @@ "fqn": "@aws-cdk/integ-tests.IntegTest", "version": "0.0.0" } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.154" + } } }, "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.85" + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-events/test/integ.rule.ts b/packages/@aws-cdk/aws-events/test/integ.rule.ts index 941d3860ce662..9f84ae6e8e398 100644 --- a/packages/@aws-cdk/aws-events/test/integ.rule.ts +++ b/packages/@aws-cdk/aws-events/test/integ.rule.ts @@ -29,6 +29,8 @@ new Rule(stack, 'MyRule', { state: Match.anythingBut('initializing'), limit: Match.anythingBut(100, 200, 300), notPrefixedBy: Match.anythingButPrefix('sensitive-'), + suffix: Match.suffix('.com'), + equalsIgnoreCase: Match.equalsIgnoreCase('ignore case'), }, detailType: ['detailType1'], id: ['id1', 'id2'], diff --git a/packages/@aws-cdk/aws-events/test/matchers.test.ts b/packages/@aws-cdk/aws-events/test/matchers.test.ts index 4bc5ef8767a69..081452c2e5a2a 100644 --- a/packages/@aws-cdk/aws-events/test/matchers.test.ts +++ b/packages/@aws-cdk/aws-events/test/matchers.test.ts @@ -64,4 +64,22 @@ describe(Match, () => { expect(() => stack.resolve(Match.anyOf())).toThrow(/A list of matchers must contain at least one element/); }); -}); \ No newline at end of file + + test('prefix', () => { + expect(stack.resolve(Match.prefix('foo'))).toEqual([ + { prefix: 'foo' }, + ]); + }); + + test('suffix', () => { + expect(stack.resolve(Match.suffix('foo'))).toEqual([ + { suffix: 'foo' }, + ]); + }); + + test('equalsIgnoreCase', () => { + expect(stack.resolve(Match.equalsIgnoreCase('foo'))).toEqual([ + { 'equals-ignore-case': 'foo' }, + ]); + }); +});