Skip to content

Commit 560e5cd

Browse files
authored
Update E2520 to better handle properties we don't care about (#2875)
1 parent da3d52d commit 560e5cd

File tree

1 file changed

+42
-43
lines changed

1 file changed

+42
-43
lines changed

src/cfnlint/rules/resources/properties/Exclusive.py

+42-43
Original file line numberDiff line numberDiff line change
@@ -32,49 +32,48 @@ def __init__(self):
3232
def check(self, properties, exclusions, path, cfn):
3333
"""Check itself"""
3434
matches = []
35-
36-
property_sets = cfn.get_object_without_conditions(properties)
37-
for property_set in property_sets:
38-
obj = property_set["Object"].clean()
39-
for prop in obj:
40-
if prop in exclusions:
41-
for excl_property in exclusions[prop]:
42-
if excl_property in obj:
43-
if property_set["Scenario"] is None:
44-
message = (
45-
"Property {0} should NOT exist with {1} for {2}"
46-
)
47-
matches.append(
48-
RuleMatch(
49-
path + [prop],
50-
message.format(
51-
excl_property,
52-
prop,
53-
"/".join(map(str, path)),
54-
),
55-
)
56-
)
57-
else:
58-
scenario_text = " and ".join(
59-
[
60-
f'when condition "{k}" is {v}'
61-
for (k, v) in property_set["Scenario"].items()
62-
]
63-
)
64-
message = (
65-
"Property {0} should NOT exist with {1} {2} for {3}"
66-
)
67-
matches.append(
68-
RuleMatch(
69-
path + [prop],
70-
message.format(
71-
excl_property,
72-
prop,
73-
scenario_text,
74-
"/".join(map(str, path)),
75-
),
76-
)
77-
)
35+
for p_value, p_path in properties.items_safe(path[:]):
36+
for k, v in exclusions.items():
37+
property_sets = cfn.get_object_without_conditions(p_value, [k] + v)
38+
for property_set in property_sets:
39+
obj = property_set["Object"].clean()
40+
for prop in obj:
41+
if prop in exclusions:
42+
for excl_property in exclusions[prop]:
43+
if excl_property in obj:
44+
if property_set["Scenario"] is None:
45+
message = "Property {0} should NOT exist with {1} for {2}"
46+
matches.append(
47+
RuleMatch(
48+
p_path + [prop],
49+
message.format(
50+
excl_property,
51+
prop,
52+
"/".join(map(str, p_path)),
53+
),
54+
)
55+
)
56+
else:
57+
scenario_text = " and ".join(
58+
[
59+
f'when condition "{k}" is {v}'
60+
for (k, v) in property_set[
61+
"Scenario"
62+
].items()
63+
]
64+
)
65+
message = "Property {0} should NOT exist with {1} {2} for {3}"
66+
matches.append(
67+
RuleMatch(
68+
p_path + [prop],
69+
message.format(
70+
excl_property,
71+
prop,
72+
scenario_text,
73+
"/".join(map(str, p_path)),
74+
),
75+
)
76+
)
7877

7978
return matches
8079

0 commit comments

Comments
 (0)