-
Notifications
You must be signed in to change notification settings - Fork 1
/
cfn_validator.py
107 lines (74 loc) · 2.93 KB
/
cfn_validator.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from Modules import ValidateTemplate
from Modules import ValidateParameters
from Modules import ValidateResources
import sys
# Globals
region = 'us-west-2'
def get_command_line_arguments_or_exit():
"""
Get the command line arguments passed to the python script.
If there are less than 1 or more than 2 arguments passed to the script then
we will print a help-like output and exit.
input example:
python main.py <cfn_template_filename> [input_parameter_filename]
Returns
string, string -- filenames for cfn_template and input_params files
"""
cfn_template_filename = ''
input_params_filename = ''
num_arguments_provided = len(sys.argv)
if num_arguments_provided == 2:
cfn_template_filename = sys.argv[1]
if num_arguments_provided == 3:
cfn_template_filename = sys.argv[1]
input_params_filename = sys.argv[2]
if num_arguments_provided < 2 or num_arguments_provided > 3:
print("usage: python " +
sys.argv[0] +
" <cfn_template_filename> [input_parameter_filename]")
exit()
return cfn_template_filename, input_params_filename
def print_header(stage):
"""
Print out the section header
Should look like this:
#############################
{stage}
#############################
Arguments:
stage {string} -- sting to display between header and footer
"""
header = '#############################'
print('', '', header, stage, header, sep='\n')
def main():
cfn_template_filename, input_params_filename = \
get_command_line_arguments_or_exit()
template = ValidateTemplate.parse_cfn_template_file(
cfn_template_filename)
input_params = ValidateTemplate.parse_input_params_file(
input_params_filename)
# Validate Template Section
print_header('Validate Template Section')
ValidateTemplate.verify_template_description_not_exceed_limit(template)
# Validate Parameters Section
print_header('Validate Parameters Section')
ValidateParameters.verify_all_template_params_provided_by_input_params(
template['Parameters'], input_params)
# Validate Mappings Section
# print_header('Validate Mappings Section')
# Validate Conditions Section
# print_header('Validate Conditions Section')
# Validate Resources Section
print_header('Validate Resources Section')
resource_specifications = \
ValidateResources.get_resource_specifications(region)
ValidateResources.verify_all_template_resource_types_are_valid(
template, resource_specifications)
ValidateResources.verify_all_template_resources_have_valid_properties(
template, resource_specifications)
ValidateResources.verify_all_template_resources_have_required_properties(
template, resource_specifications)
# Validate Outputs Section
# print_header('Validate Outputs Section')
if __name__ == '__main__':
main()