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 8697c21
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 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
10 changes: 5 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ all =
docker>=3.0.0
graphql-core
PyYAML>=5.1
cfn-lint>=0.40.0
cfn-lint>=1.3.0
openapi-spec-validator>=0.5.0
pyparsing>=3.0.7
jsondiff>=1.1.2
Expand All @@ -65,7 +65,7 @@ proxy =
docker>=2.5.1
graphql-core
PyYAML>=5.1
cfn-lint>=0.40.0
cfn-lint>=1.3.0
openapi-spec-validator>=0.5.0
pyparsing>=3.0.7
jsondiff>=1.1.2
Expand All @@ -80,7 +80,7 @@ server =
docker>=3.0.0
graphql-core
PyYAML>=5.1
cfn-lint>=0.40.0
cfn-lint>=1.3.0
openapi-spec-validator>=0.5.0
pyparsing>=3.0.7
jsondiff>=1.1.2
Expand Down Expand Up @@ -115,7 +115,7 @@ cloudformation =
docker>=3.0.0
graphql-core
PyYAML>=5.1
cfn-lint>=0.40.0
cfn-lint>=1.3.0
openapi-spec-validator>=0.5.0
pyparsing>=3.0.7
jsondiff>=1.1.2
Expand Down Expand Up @@ -204,7 +204,7 @@ resourcegroupstaggingapi =
docker>=3.0.0
graphql-core
PyYAML>=5.1
cfn-lint>=0.40.0
cfn-lint>=1.3.0
openapi-spec-validator>=0.5.0
pyparsing>=3.0.7
jsondiff>=1.1.2
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 8697c21

Please sign in to comment.