Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def normalize_json(template):
"""Normalize our template for diffing.
Args:
template(str): string representing the template
Returns:
list: json representation of the parameters
"""
obj = parse_cloudformation_template(template)
json_str = json.dumps(
obj, sort_keys=True, indent=4, default=str, separators=(',', ': '),
)
result = []
lines = json_str.split("\n")
for line in lines:
result.append(line + "\n")
return result
def to_dict(self):
"""Return the template as a python dictionary.
Returns:
dict: the loaded template as a python dictionary
"""
return parse_cloudformation_template(self.rendered)
new_template = stack.blueprint.rendered
new_stack = normalize_json(new_template)
output = ["============== Stack: %s ==============" % (stack.name,)]
# If this is a completely new template dump our params & stack
if not old_template:
output.extend(self._build_new_template(new_stack, parameters))
else:
# Diff our old & new stack/parameters
old_template = parse_cloudformation_template(old_template)
if isinstance(old_template, str):
# YAML templates returned from CFN need parsing again
# "AWSTemplateFormatVersion: \"2010-09-09\"\nParam..."
# ->
# AWSTemplateFormatVersion: "2010-09-09"
old_template = parse_cloudformation_template(old_template)
old_stack = normalize_json(
json.dumps(old_template,
sort_keys=True,
indent=4,
default=str)
)
output.extend(build_stack_changes(stack.name, new_stack, old_stack,
new_params, old_params))
ui.info('\n' + '\n'.join(output))
stack.set_outputs(
provider.get_output_dict(provider_stack))
return COMPLETE
stack.resolve(self.context, provider)
# generate our own template & params
parameters = self.build_parameters(stack)
new_params = dict()
for p in parameters:
new_params[p['ParameterKey']] = p['ParameterValue']
new_template = stack.blueprint.rendered
new_stack = normalize_json(new_template)
output = ["============== Stack: %s ==============" % (stack.name,)]
# If this is a completely new template dump our params & stack
if not old_template:
output.extend(self._build_new_template(new_stack, parameters))
else:
# Diff our old & new stack/parameters
old_template = parse_cloudformation_template(old_template)
if isinstance(old_template, str):
# YAML templates returned from CFN need parsing again
# "AWSTemplateFormatVersion: \"2010-09-09\"\nParam..."
# ->
# AWSTemplateFormatVersion: "2010-09-09"
old_template = parse_cloudformation_template(old_template)
old_stack = normalize_json(
json.dumps(old_template,
sort_keys=True,
indent=4,
default=str)
)
output.extend(build_stack_changes(stack.name, new_stack, old_stack,
new_params, old_params))
ui.info('\n' + '\n'.join(output))