Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(events): correct token resolution in RuleTargetInput #3127

Merged
merged 2 commits into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-events/lib/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class FieldAwareEventInput extends RuleTargetInput {
}

public resolveToken(t: Token, _context: IResolveContext) {
if (!isEventField(t)) { return t; }
if (!isEventField(t)) { return Token.asString(t); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it used to inherit a working toString(). Implementing that on the Token would also have worked. I think I would feel safer if we did that... but that can wait until we uncover a new failing case maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it have worked with token encoded as numbers?


const key = keyForField(t);
if (inputPathsMap[key] && inputPathsMap[key] !== t.path) {
Expand Down
39 changes: 38 additions & 1 deletion packages/@aws-cdk/aws-events/test/test.input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, haveResourceLike } from '@aws-cdk/assert';
import { User } from '@aws-cdk/aws-iam';
import cdk = require('@aws-cdk/core');
import { Duration, Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
Expand Down Expand Up @@ -27,6 +28,42 @@ export = {
}));
test.done();
},

'can use token'(test: Test) {
// GIVEN
const stack = new Stack();
const rule = new Rule(stack, 'Rule', {
schedule: Schedule.rate(Duration.minutes(1)),
});
const user = new User(stack, 'User');

// WHEN
rule.addTarget(new SomeTarget(RuleTargetInput.fromObject({ userArn: user.userArn })));

// THEN
expect(stack).to(haveResourceLike('AWS::Events::Rule', {
Targets: [
{
Input: {
'Fn::Join': [
'',
[
'{\"userArn\":\"',
{
'Fn::GetAtt': [
'User00B015A1',
'Arn'
]
},
'\"}'
]
]
}
}
]
}));
test.done();
},
},

'text templates': {
Expand Down Expand Up @@ -107,4 +144,4 @@ class SomeTarget implements IRuleTarget {
public bind() {
return { id: 'T1', arn: 'ARN1', input: this.input };
}
}
}