forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(events): support embedded string variables (aws#13487)
Event Bridge transformers have been updated to support embedded variable replacement within strings within objects. ``` { data: "some string <myValue>" } ``` Previously input transformers only supported string when they were the only value of an object, or just static strings. ``` // Before Event Bridges's change { data: <myValue>, // OK data2: "some string", // OK data3: "some string <myValue>" // NOT OK } ``` The CDK solution was to assume that developers knew this restriction, wrap the string variable in special characters, and replace the double quotes plus special character set with nothing after token replacement. This caused issues like aws#9191. Where string tokens (`EventField`) within a string would give a cryptic error during Cfn deployment due the resulting invalid object string generated (missing a closing double quote and leaving the special characters behind). ### Solution: Removed the special character sequence addition and stripping and instead only replace any instances of `"<myValue>"` that are added. * Iterate over the known input transform keys to reduce possible unexpected impact and give developers a backdoor to change their keys in the worst case. * Edge Case: `"<myValue>"` can appear with escaped quote sequences `"something \"quoted\"<myValue>"`. This is a valid string variable replacement case. Used a lookback regex (`(?<!\\\\)\"\<${key}\>\"`) to avoid the prefix escaped quote when replacing transform input keys with quote-less keys. ### Tradeoffs Removed the addition of special characters to find the keys in the final json string. Instead search for the specific pattern of transform input keys that should exist within the output and handle the edge case describe above. This SHOULD cover all edge cases as it is not valid to have a trailing quote without an escape (`"<myValue>"" //not valid`) and it is not valid to have a prefix quote that is not escaped (`""<myValue>" // not valid`). This was done to reduce the small change of overlapping with a developer's content, to be more targeted, and because the above should prove that the edge case is covered. https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html fixes aws#9191 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
3 changed files
with
181 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters