-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema_diagram_generator_input.py
51 lines (43 loc) · 1.12 KB
/
schema_diagram_generator_input.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
from schema import Schema, And, Or, Optional, Use, SchemaError
cidr_block_entry_schema = {
'cidr': str,
'description': str
}
prefix_list_schema = {
'id': str,
'name': str,
'account_id': str,
'entries': [cidr_block_entry_schema],
'not_defined_in_state': bool
}
rule_schema = {
'security_group_id': str,
'type': str,
'description': str,
'from_port': int,
'to_port': int,
'protocol': str,
'source_security_group_ids': Or(None, [str]),
'cidr_blocks': Or(None, [str]),
'ipv6_cidr_blocks': Or(None, [str]),
'prefix_list_ids': Or(None, [str])
}
security_group_schema = {
'id': str,
'name': str,
'account_id': str,
'ingress_rules': [rule_schema],
'egress_rules': [rule_schema],
'not_defined_in_state': bool
}
json_schema = Schema({
'prefix_lists': [prefix_list_schema],
'cidr_blocks': [str],
'ipv6_cidr_blocks': [str],
'security_groups': [security_group_schema]
})
def check_input_json_against_schema(data):
try:
json_schema.validate(data)
except SchemaError as e:
raise Exception("JSON Validation failed!", e)