Fix Json string literal in resource property #80
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: This fix solves the issue with JSON payload in resource
AWS::StepFunctions::StateMachine
and propertyDefinitionString
that has a JSON string that must remain a json string when converted to YAML.Details:
When the script load a json file all key/values are converted to objects and those objects and later converted to yaml. This behavior made some payloads like
DefinitionString
to become Yaml but the property is a json and in a Yaml document this property must be converted to a string literal.The way to solve this is to run a parser that will check for
Key == AWS::StepFunctions::StateMachine
and when found this resource we try to find the propertyDefinitionString
. If found the property we convert the object into a string using json.dumpsand create a python object to be specifically parsed in the yaml representer to use the style
|
.Here is where the things get interesting.
Just adding the style
|
to generate a literal didn't work as expected as some simple strings got converted correctly and others don't.You can reproduce the behavior with this script:
After analysing the problem I found that pyYaml in the Emitter step there is a string validation to check against leading and trailing whitespaces.
The code is here: https://github.com/yaml/pyyaml/blob/master/lib/yaml/emitter.py
The way to circumvent this characteristic is to override the method
analyze_scalar
from classEmitter
and when we find a scalar that is a instance of our object typeLiteralString
we return theScalarAnalisys
with the parameters that we want (In this case toallow_block_plain=True
This solution allow an easy way to add more resource properties as the code has an array of tuples of
(<Resource_Type>, <Property_Name>)
Fix: Updated the PyYaml requirement in
setup.py
to >= 4.1 to avoid remote execution vulnerability in CVE-2017-18342By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.