Skip to content

Commit

Permalink
Fix cfnlint 1.3.0 breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
viren-nadkarni committed Jun 20, 2024
1 parent ae4667a commit 6eaf163
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
23 changes: 3 additions & 20 deletions moto/cloudformation/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import string
from typing import Any, List
from urllib.parse import urlparse
Expand Down Expand Up @@ -59,24 +58,10 @@ def _f(loader: Any, tag: Any, node: Any) -> Any:

def validate_template_cfn_lint(template: str) -> List[Any]:
# Importing cfnlint adds a significant overhead, so we keep it local
from cfnlint import core, decode

# 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)
from cfnlint import api, config, core

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

# Initialize the ruleset to be applied (no overrules, no excludes)
rules = core.get_rules([], [], [])
Expand All @@ -85,9 +70,7 @@ def validate_template_cfn_lint(template: str) -> List[Any]:
regions = ["us-east-1"]

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

return matches
return api.lint(template, rules, regions)


def get_stack_from_s3_url(template_url: str, account_id: str, partition: str) -> str:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cloudformation/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_boto3_json_invalid_missing_resource():
err = exc.value.response["Error"]
assert (
err["Message"]
== "Stack with id Missing top level template section Resources does not exist"
== "Stack with id 'Resources' is a required property does not exist"
)


Expand Down Expand Up @@ -124,5 +124,5 @@ def test_boto3_yaml_invalid_missing_resource():
err = exc.value.response["Error"]
assert (
err["Message"]
== "Stack with id Missing top level template section Resources does not exist"
== "Stack with id 'Resources' is a required property does not exist"
)

0 comments on commit 6eaf163

Please sign in to comment.