def _stub_get_template(self, stubber, stack_id, template_type="json"):
        with open(self.template_file(), "r") as template_file:
            template_body_raw, _ = load(template_file.read())
        template_file.close()
        if template_type == "yaml":
            template_body = dump_yaml(template_body_raw)
        else:
            template_body = dump_json(template_body_raw)

        expected_params = {"StackName": self.stack_id()}
        mock_response = {
            "TemplateBody": template_body,
            "StagesAvailable": ["Original", "Processed"],
            "ResponseMetadata": {
                "RequestId": "a31f5380-73ad-4f7f-a440-aaaaaaaaab",
                "HTTPStatusCode": 200,
                "HTTPHeaders": {
                    "x-amzn-requestid": "a31f5380-73ad-4f7f-a440-aaaaaaaaab",
                    "content-type": "text/xml",
                    "content-length": "1798",
                    "date": "Thu, 18 Mar 2021 09:36:17 GMT",
                },
                "RetryAttempts": 0,
            },
        }
        stubber.add_response("get_template", mock_response, expected_params)
예제 #2
0
    def compare_stack_configurations(
        self,
        deployed: Optional[StackConfiguration],
        generated: StackConfiguration,
    ) -> List[str]:
        if deployed is None:
            comparable_deployed = None
        else:
            comparable_deployed = self._make_stack_configuration_comparable(
                deployed)

        comparable_generated = self._make_stack_configuration_comparable(
            generated)
        deployed_string = cfn_flip.dump_yaml(comparable_deployed)
        generated_string = cfn_flip.dump_yaml(comparable_generated)
        return self._make_string_diff(deployed_string, generated_string)
예제 #3
0
def dump_cfn_template_yaml(template_data, clean_up=False, long_form=False):
    """
    Wrapper around cfn_flip.dump_yaml() that converts the given template data
    to the ODict type it expets.
    """
    return cfn_flip.dump_yaml(copy_dict(template_data, impl=ODict),
                              clean_up=clean_up,
                              long_form=long_form)
예제 #4
0
def _format_yaml(filename):
    with open(filename, "r", encoding="utf-8") as f:
        try:
            unformatted_yaml = load_yaml(f)
        except Exception as e:
            print("ERROR: Invalid yaml document: {error}".format(error=e))
            exit(1)

    return dump_yaml(unformatted_yaml, clean_up=True)
예제 #5
0
    def load_template(self, name):
        with open(name) as f:
            template = cfn_flip.load_yaml(f)
            template['Transform'] = os.getenv('MACRO_NAME')

        return cfn_flip.dump_yaml(template)