-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from cfstacks/fix/security
Upgrade pyyaml to version 4.2b1 or later
- Loading branch information
Showing
5 changed files
with
45 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# noinspection PyProtectedMember | ||
from yaml.resolver import ScalarNode, SequenceNode | ||
|
||
|
||
# noinspection PyUnusedLocal | ||
def intrinsics_multi_constructor(loader, tag_prefix, node): | ||
""" | ||
YAML constructor to parse CloudFormation intrinsics. | ||
This will return a dictionary with key being the instrinsic name | ||
""" | ||
|
||
# Get the actual tag name excluding the first exclamation | ||
tag = node.tag[1:] | ||
|
||
# Some intrinsic functions doesn't support prefix "Fn::" | ||
prefix = "Fn::" | ||
if tag in ["Ref", "Condition"]: | ||
prefix = "" | ||
|
||
cfntag = prefix + tag | ||
|
||
if tag == "GetAtt" and isinstance(node.value, str): | ||
# ShortHand notation for !GetAtt accepts Resource.Attribute format | ||
# while the standard notation is to use an array | ||
# [Resource, Attribute]. Convert shorthand to standard format | ||
value = node.value.split(".", 1) | ||
|
||
elif isinstance(node, ScalarNode): | ||
# Value of this node is scalar | ||
value = loader.construct_scalar(node) | ||
|
||
elif isinstance(node, SequenceNode): | ||
# Value of this node is an array (Ex: [1,2]) | ||
value = loader.construct_sequence(node) | ||
|
||
else: | ||
# Value of this node is an mapping (ex: {foo: bar}) | ||
value = loader.construct_mapping(node) | ||
|
||
return {cfntag: value} |