Ejemplo n.º 1
0
def validate_template_cfn_lint(template):
    # Importing cfnlint adds a significant overhead, so we keep it local
    from cfnlint import decode, core

    # Save the template to a temporary file -- cfn-lint requires a file
    filename = "file.tmp"
    with open(filename, "w") as file:
        file.write(template)
    abs_filename = os.path.abspath(filename)

    # decode handles both yaml and json
    try:
        template, matches = decode.decode(abs_filename, False)
    except TypeError:
        # As of cfn-lint 0.39.0, the second argument (ignore_bad_template) was dropped
        # https://github.com/aws-cloudformation/cfn-python-lint/pull/1580
        template, matches = decode.decode(abs_filename)

    # Set cfn-lint to info
    core.configure_logging(None)

    # Initialize the ruleset to be applied (no overrules, no excludes)
    rules = core.get_rules([], [], [])

    # Use us-east-1 region (spec file) for validation
    regions = ["us-east-1"]

    # Process all the rules and gather the errors
    matches = core.run_checks(abs_filename, template, rules, regions)

    return matches
Ejemplo n.º 2
0
Archivo: utils.py Proyecto: spulec/moto
def validate_template_cfn_lint(template):

    # Save the template to a temporary file -- cfn-lint requires a file
    filename = "file.tmp"
    with open(filename, "w") as file:
        file.write(template)
    abs_filename = os.path.abspath(filename)

    # decode handles both yaml and json
    template, matches = decode.decode(abs_filename, False)

    # Set cfn-lint to info
    core.configure_logging(None)

    # Initialize the ruleset to be applied (no overrules, no excludes)
    rules = core.get_rules([], [], [])

    # Use us-east-1 region (spec file) for validation
    regions = ['us-east-1']

    # Process all the rules and gather the errors
    matches = core.run_checks(
        abs_filename,
        template,
        rules,
        regions)

    return matches
Ejemplo n.º 3
0
def validate_template_cfn_lint(template):
    # Importing cfnlint adds a significant overhead, so we keep it local
    from cfnlint import decode, core

    # Save the template to a temporary file -- cfn-lint requires a file
    filename = "file.tmp"
    with open(filename, "w") as file:
        file.write(template)
    abs_filename = os.path.abspath(filename)

    # decode handles both yaml and json
    template, matches = decode.decode(abs_filename, False)

    # Set cfn-lint to info
    core.configure_logging(None)

    # Initialize the ruleset to be applied (no overrules, no excludes)
    rules = core.get_rules([], [], [])

    # Use us-east-1 region (spec file) for validation
    regions = ["us-east-1"]

    # Process all the rules and gather the errors
    matches = core.run_checks(abs_filename, template, rules, regions)

    return matches
Ejemplo n.º 4
0
def get_cnflint_errors(template_path: str,
                       region: str = "us-east-1") -> List[Match]:
    regions = [region]
    template = cfnlint.decode.cfn_yaml.load(template_path)
    rules = get_rules(
        ["cfn_lint_ax.rules"],
        ignore_rules=[],
        include_rules=["I"],
        include_experimental=True,
    )
    runner = Runner(rules=rules,
                    filename=template_path,
                    template=template,
                    regions=regions)
    runner.transform()
    errors = runner.run()
    return errors
Ejemplo n.º 5
0
import boto3, re, os, requests, shutil, tempfile, time
from cfnlint import decode, core
from aws_xray_sdk.core import xray_recorder
from zipfile import ZipFile
from github import Github
from aws_xray_sdk.core import patch_all

patch_all()

# initialize the cfn-lint ruleset to be applied
rules = core.get_rules([], [], ['I', 'E', 'W'], [], True, [])

# retrieve the dynamodb tables from env vars
dynamo_table_metadata = os.environ['dynamo_table_metadata']
dynamo_table_scan = os.environ['dynamo_table_scan']
region = str(os.environ['AWS_REGION'])

# connect to dynamodb
ddb_scan = boto3.resource('dynamodb',
                          region_name=region).Table(dynamo_table_scan)
ddb_meta = boto3.resource('dynamodb',
                          region_name=region).Table(dynamo_table_metadata)


# load cfnfile keywords from keywords.txt
@xray_recorder.capture("load_keywords")
def load_keywords():
    kw = []
    f = 'keywords.txt'

    # open the feeds file and read line by line
Ejemplo n.º 6
0
from typing import List

import pytest
from _pytest.fixtures import SubRequest
from cfnlint.core import get_rules
from cfnlint.rules import CloudFormationLintRule

from tests.utils import BAD_TEMPLATE_FIXTURES_PATH, GOOD_TEMPLATE_FIXTURES_PATH

_ax_rules: List[CloudFormationLintRule] = [
    rule
    for rule in get_rules(["cfn_lint_ax.rules"], [], [])
    if rule.__module__.startswith("cfn_lint_ax.rules.")
]


@pytest.fixture(name="ax_rules")
def fixture_ax_rules() -> List[CloudFormationLintRule]:
    return _ax_rules.copy()


@pytest.fixture(name="ax_rule", params=_ax_rules)
def fixture_ax_rule(request: SubRequest) -> CloudFormationLintRule:
    return request.param


_bad_templates = [p.name for p in BAD_TEMPLATE_FIXTURES_PATH.glob("*.yaml")]
_good_templates = [p.name for p in GOOD_TEMPLATE_FIXTURES_PATH.glob("*.yaml")]


@pytest.fixture(