Skip to content

Commit

Permalink
add support for include transforms in lists, minor changes per PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliot Korte committed Oct 17, 2018
1 parent 17fced5 commit 1eaa24f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 7 additions & 3 deletions awscli/customizations/cloudformation/artifact_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,16 @@ def export_global_artifacts(self, template_dict):
here we iterate through the template dict and export params with a
handler defined in GLOBAL_EXPORT_DICT
"""
for key, val in iter(template_dict.items()):
for key, val in template_dict.items():
if key in GLOBAL_EXPORT_DICT:
template_dict[key] = GLOBAL_EXPORT_DICT[key](val, self.uploader)
elif type(val) is dict:
elif isinstance(val, dict):
self.export_global_artifacts(val)
return self.template_dict
elif isinstance(val, list):
for item in val:
if isinstance(item, dict):
self.export_global_artifacts(item)
return template_dict


def export(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ def test_template_global_export(self, yaml_parse_mock):
}
properties1 = {"foo": "bar", "Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": "foo.yaml"}}}
properties2 = {"foo": "bar", "Fn::Transform": {"Name": "AWS::OtherTransform"}}
properties_in_list = {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": "bar.yaml"}}}
template_dict = {
"Resources": {
"Resource1": {
Expand All @@ -798,9 +799,10 @@ def test_template_global_export(self, yaml_parse_mock):
},
"Resource2": {
"Type": "resource_type2",
"Properties": properties2
"Properties": properties2,
}
}
},
"List": ["foo", properties_in_list]
}
open_mock = mock.mock_open()
include_transform_export_handler_mock = Mock()
Expand All @@ -819,12 +821,15 @@ def test_template_global_export(self, yaml_parse_mock):

first_call_args, kwargs = include_transform_export_handler_mock.call_args_list[0]
second_call_args, kwargs = include_transform_export_handler_mock.call_args_list[1]
call_args = [first_call_args[0], second_call_args[0]]
third_call_args, kwargs = include_transform_export_handler_mock.call_args_list[2]
call_args = [first_call_args[0], second_call_args[0], third_call_args[0]]
self.assertTrue({"Name": "AWS::Include", "Parameters": {"Location": "foo.yaml"}} in call_args)
self.assertTrue({"Name": "AWS::OtherTransform"} in call_args)
self.assertEquals(include_transform_export_handler_mock.call_count, 2)
self.assertTrue({"Name": "AWS::Include", "Parameters": {"Location": "bar.yaml"}} in call_args)
self.assertEquals(include_transform_export_handler_mock.call_count, 3)
#new s3 url is added to include location
self.assertEquals(exported_template["Resources"]["Resource1"]["Properties"]["Fn::Transform"], {"Name": "AWS::Include", "Parameters": {"Location": "s3://foo"}})
self.assertEquals(exported_template["List"][1]["Fn::Transform"], {"Name": "AWS::Include", "Parameters": {"Location": "s3://foo"}})

@patch("awscli.customizations.cloudformation.artifact_exporter.is_local_file")
def test_include_transform_export_handler(self, is_local_file_mock):
Expand Down

0 comments on commit 1eaa24f

Please sign in to comment.