forked from aws-cloudformation/cfn-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.py
55 lines (48 loc) · 2.26 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
"""
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 Mappings are configured correctly"""
id = 'E7001'
shortdesc = 'Mappings are appropriately configured'
description = 'Check if Mappings are properly configured'
source_url = 'https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html'
tags = ['mappings']
def match(self, cfn):
matches = []
valid_map_types = (str, list, int, float)
mappings = cfn.template.get('Mappings', {})
if mappings:
for mapname, mapobj in mappings.items():
if not isinstance(mapobj, dict):
message = 'Mapping {0} has invalid property'
matches.append(
RuleMatch(['Mappings', mapname], message.format(mapname))
)
else:
for firstkey in mapobj:
firstkeyobj = mapobj[firstkey]
if not isinstance(firstkeyobj, dict):
message = 'Mapping {0} has invalid property at {1}'
matches.append(
RuleMatch(
['Mappings', mapname, firstkey],
message.format(mapname, firstkeyobj),
)
)
else:
for secondkey in firstkeyobj:
if not isinstance(
firstkeyobj[secondkey], valid_map_types
):
message = 'Mapping {0} has invalid property at {1}'
matches.append(
RuleMatch(
['Mappings', mapname, firstkey, secondkey],
message.format(mapname, secondkey),
)
)
return matches