Skip to content

Commit 729a695

Browse files
committed
Switch cfnlint to use api
1 parent 6943c61 commit 729a695

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed
Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import json
21
import logging
32

4-
import cfnlint.config
5-
import cfnlint.core
3+
from cfnlint.api import lint
64

75
from .module_fragment_reader import _get_fragment_file
86

@@ -27,11 +25,13 @@ def print_cfn_lint_warnings(fragment_dir):
2725

2826
def __get_cfn_lint_matches(fragment_dir):
2927
filepath = _get_fragment_file(fragment_dir)
28+
3029
try:
31-
try:
32-
template = cfnlint.decode.cfn_json.load(filepath)
33-
except json.decoder.JSONDecodeError:
34-
template = cfnlint.decode.cfn_yaml.load(filepath)
30+
with open(filepath, encoding="utf-8") as handle:
31+
template = handle.read()
32+
matches = lint(template, regions=["us-east-1"])
33+
34+
return matches
3535
except Exception as e: # pylint: disable=broad-except
3636
LOG.error(
3737
"Skipping cfn-lint validation due to an internal error.\n"
@@ -40,14 +40,3 @@ def __get_cfn_lint_matches(fragment_dir):
4040
)
4141
LOG.error(str(e))
4242
return []
43-
44-
# Initialize the ruleset to be applied (no overrules, no excludes)
45-
rules = cfnlint.core.get_rules([], [], [], [], False, [])
46-
47-
# Default region used by cfn-lint
48-
regions = ["us-east-1"]
49-
50-
# Runs Warning and Error rules
51-
matches = cfnlint.core.run_checks(filepath, template, rules, regions)
52-
53-
return matches

0 commit comments

Comments
 (0)