Skip to content

Commit

Permalink
fix(events): eventSourceName does not accept tokens (aws#20719)
Browse files Browse the repository at this point in the history
Addresses aws#20718 

Adds a check to see if the value is a token before running the validation regex on `eventSourceName`.

Simple fix following a similar fix in aws#10772

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
keetonian authored and daschaa committed Jul 9, 2022
1 parent 29e026c commit 5b77e27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/@aws-cdk/aws-events/lib/event-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,18 @@ export class EventBus extends EventBusBase {
}

if (eventSourceName !== undefined) {
// Ex: aws.partner/PartnerName/acct1/repo1
const eventSourceNameRegex = /^aws\.partner(\/[\.\-_A-Za-z0-9]+){2,}$/;
if (!eventSourceNameRegex.test(eventSourceName)) {
throw new Error(
`'eventSourceName' must satisfy: ${eventSourceNameRegex}`,
);
} else if (!eventBusNameRegex.test(eventSourceName)) {
throw new Error(
`'eventSourceName' must satisfy: ${eventBusNameRegex}`,
);
if (!Token.isUnresolved(eventSourceName)) {
// Ex: aws.partner/PartnerName/acct1/repo1
const eventSourceNameRegex = /^aws\.partner(\/[\.\-_A-Za-z0-9]+){2,}$/;
if (!eventSourceNameRegex.test(eventSourceName)) {
throw new Error(
`'eventSourceName' must satisfy: ${eventSourceNameRegex}`,
);
} else if (!eventBusNameRegex.test(eventSourceName)) {
throw new Error(
`'eventSourceName' must satisfy: ${eventBusNameRegex}`,
);
}
}
return { eventBusName: eventSourceName, eventSourceName };
}
Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-events/test/event-bus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ describe('event bus', () => {
}).toThrow(/'eventSourceName' must satisfy: \/\^aws/);
});

test('does not throw if eventSourceName is a token', () => {
// GIVEN
const stack = new Stack();

// WHEN / THEN
expect(() => new EventBus(stack, 'EventBus', {
eventSourceName: Aws.STACK_NAME,
})).not.toThrow();
});

test('event bus source name cannot be empty string', () => {
// GIVEN
const stack = new Stack();
Expand Down

0 comments on commit 5b77e27

Please sign in to comment.