How to use the cfripper.model.utils.convert_json_or_yaml_to_dict function in cfripper

To help you get started, we’ve selected a few cfripper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Skyscanner / cfripper / tests / test_boto3_client.py View on Github external
def test_valid_yaml_as_bytes():
    result = convert_json_or_yaml_to_dict(bytes("hello: this is valid", "utf8"))
    assert result["hello"] == "this is valid"
github Skyscanner / cfripper / tests / test_rule_cloud_formation_authentication.py View on Github external
def template_good(self):
        dir_path = os.path.dirname(os.path.realpath(__file__))
        with open(f"{dir_path}/test_templates/cfn_authentication_good.json") as cf_script:
            cf_template = convert_json_or_yaml_to_dict(cf_script.read())
        return pycfmodel.parse(cf_template)
github Skyscanner / cfripper / cfripper / cli.py View on Github external
def cli(templates, logging_level, resolve_parameters, **kwargs):
    """Analyse AWS Cloudformation templates passed by parameter."""
    try:
        setup_logging(logging_level)

        if kwargs["resolve"] and resolve_parameters:
            resolve_parameters = convert_json_or_yaml_to_dict(resolve_parameters.read())

        for template in templates:
            process_template(template=template, resolve_parameters=resolve_parameters, **kwargs)

    except Exception as e:
        logging.exception(
            "Unhandled exception raised, please create an issue wit the error message at "
            "https://github.com/Skyscanner/cfripper/issues"
        )
        try:
            sys.exit(e.errno)
        except AttributeError:
            sys.exit(1)
github Skyscanner / cfripper / simulator / simulator.py View on Github external
def test_script(script_name, service_name, project_name, stack):
    event = {
        "stack_template_url": "https://fake/bucket/key",
        "project": project_name,
        "serviceName": service_name,
        "stack": stack,
    }
    mock_boto3_client_object = Mock()
    with open(f"{dir_path}/test_cf_scripts/{script_name}") as cf_script:
        mock_boto3_client_object.download_template_to_dictionary.return_value = convert_json_or_yaml_to_dict(
            cf_script.read()
        )

    mock_boto3_client = Mock(return_value=mock_boto3_client_object)

    with patch("cfripper.main.Boto3Client", new=mock_boto3_client):
        from cfripper.main import handler

        event_result = handler(event, "None")
        print(f"{script_name} -- valid: {event_result['valid']}\n {event_result['reason']}")
github Skyscanner / cfripper / cfripper / boto3_client.py View on Github external
def download_template_to_dictionary(self, s3_url):
        """
        Download a CloudFormation template from S3 into a Dictionary.

        :param s3_url: The URL to download from.
        :return: Dictionary version of the CF Template.
        """
        bucket_name, file_path = extract_bucket_name_and_path_from_url(s3_url)

        client = self.session.client("s3", region_name=self.region)
        response = client.get_object(Bucket=bucket_name, Key=file_path)
        file_contents = response["Body"].read().decode("utf-8")

        return convert_json_or_yaml_to_dict(file_contents)
github Skyscanner / cfripper / cfripper / cli.py View on Github external
def get_cfmodel(template: TextIOWrapper) -> CFModel:
    template = convert_json_or_yaml_to_dict(template.read())
    cfmodel = pycfmodel.parse(template)
    return cfmodel