forked from aws-cloudformation/cfn-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.py
56 lines (49 loc) · 2.02 KB
/
Configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""
from cfnlint.rules import CloudFormationLintRule
from cfnlint.rules import RuleMatch
class Configuration(CloudFormationLintRule):
"""Check if Conditions are configured correctly"""
id = 'E8001'
shortdesc = 'Conditions have appropriate properties'
description = 'Check if Conditions are properly configured'
source_url = 'https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html'
tags = ['conditions']
condition_keys = [
'Condition',
'Fn::And',
'Fn::Equals',
'Fn::Not',
'Fn::Or',
]
def match(self, cfn):
matches = []
conditions = cfn.template.get('Conditions', {})
if conditions:
for condname, condobj in conditions.items():
if not isinstance(condobj, dict):
message = 'Condition {0} has invalid property'
matches.append(
RuleMatch(['Conditions', condname], message.format(condname))
)
else:
if len(condobj) != 1:
message = 'Condition {0} has too many intrinsic conditions'
matches.append(
RuleMatch(
['Conditions', condname], message.format(condname)
)
)
else:
for k, _ in condobj.items():
if k not in self.condition_keys:
message = 'Condition {0} has invalid property {1}'
matches.append(
RuleMatch(
['Conditions', condname] + [k],
message.format(condname, k),
)
)
return matches