Skip to content

Commit

Permalink
fix input fromText has extra quotations
Browse files Browse the repository at this point in the history
  • Loading branch information
samson-keung committed Oct 25, 2024
1 parent 1447087 commit d55f6c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 6 additions & 5 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class ScheduleTargetInput {
* @param text Text to use as the input for the target
*/
public static fromText(text: string): ScheduleTargetInput {
return new FieldAwareEventInput(text);
return new FieldAwareEventInput(text, false);
}

/**
Expand All @@ -28,7 +28,7 @@ export abstract class ScheduleTargetInput {
* @param obj object to use to convert to JSON to use as input for the target
*/
public static fromObject(obj: any): ScheduleTargetInput {
return new FieldAwareEventInput(obj);
return new FieldAwareEventInput(obj, true);
}

protected constructor() {
Expand All @@ -41,7 +41,7 @@ export abstract class ScheduleTargetInput {
}

class FieldAwareEventInput extends ScheduleTargetInput {
constructor(private readonly input: any) {
constructor(private readonly input: any, private readonly toJsonString: boolean) {
super();
}

Expand All @@ -57,10 +57,11 @@ class FieldAwareEventInput extends ScheduleTargetInput {
}

const stack = Stack.of(schedule);
return stack.toJsonString(Tokenization.resolve(this.input, {
const inputString = Tokenization.resolve(this.input, {
scope: schedule,
resolver: new Replacer(),
}));
});
return this.toJsonString ? stack.toJsonString(inputString) : inputString;
}
}

Expand Down
11 changes: 7 additions & 4 deletions packages/@aws-cdk/aws-scheduler-alpha/test/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('schedule target input', () => {
Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
Properties: {
Target: {
Input: '"test"',
Input: 'test',
},
},
});
Expand All @@ -52,13 +52,16 @@ describe('schedule target input', () => {
test('create an input from text with a ref inside', () => {
new Schedule(stack, 'MyScheduleDummy', {
schedule: expr,
target: new SomeLambdaTarget(func, ScheduleTargetInput.fromText(stack.account)),
target: new SomeLambdaTarget(func, ScheduleTargetInput.fromText(`a-${stack.account}`)),
});

const t = Template.fromStack(stack);

Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
Properties: {
Target: {
Input: {
'Fn::Join': ['', ['"', { Ref: 'AWS::AccountId' }, '"']],
'Fn::Join': ['', ['a-', { Ref: 'AWS::AccountId' }]],
},
},
},
Expand Down Expand Up @@ -115,7 +118,7 @@ describe('schedule target input', () => {
Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
Properties: {
Target: {
Input: '"Test=<aws.scheduler.schedule-arn>"',
Input: 'Test=<aws.scheduler.schedule-arn>',
},
},
});
Expand Down

0 comments on commit d55f6c2

Please sign in to comment.