Skip to content

Commit

Permalink
Skip secondary key check when using language transform (#3190)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored May 1, 2024
1 parent 91cf060 commit eb7dd62
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/cfnlint/rules/functions/FindInMapKeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FindInMapKeys(CloudFormationLintRule):
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html"
tags = ["functions", "findinmap"]

def check_keys(self, map_name, keys, mappings, tree):
def check_keys(self, map_name, keys, mappings, tree, cfn):
"""Check the validity of the first key"""
matches = []
first_key = keys[0]
Expand Down Expand Up @@ -58,20 +58,21 @@ def check_keys(self, map_name, keys, mappings, tree):
)
)
else:
for key, value in mapping.items():
if value.get(second_key) is None:
message = 'FindInMap second key "{0}" doesn\'t exist in map "{1}" under "{2}" at {3}'
matches.append(
RuleMatch(
tree[:] + [2],
message.format(
second_key,
map_name,
key,
"/".join(map(str, tree)),
),
if not cfn.has_language_extensions_transform():
for key, value in mapping.items():
if value.get(second_key) is None:
message = 'FindInMap second key "{0}" doesn\'t exist in map "{1}" under "{2}" at {3}'
matches.append(
RuleMatch(
tree[:] + [2],
message.format(
second_key,
map_name,
key,
"/".join(map(str, tree)),
),
)
)
)

return matches

Expand All @@ -85,6 +86,8 @@ def match(self, cfn):
map_obj = findinmap[-1]

if len(map_obj) == 3:
matches.extend(self.check_keys(map_obj[0], map_obj[1:], mappings, tree))
matches.extend(
self.check_keys(map_obj[0], map_obj[1:], mappings, tree, cfn)
)

return matches

0 comments on commit eb7dd62

Please sign in to comment.