-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
43 lines (34 loc) · 1.09 KB
/
Copy pathmodel.py
File metadata and controls
43 lines (34 loc) · 1.09 KB
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
def build_model(data):
model = {
"roles": [],
"networks": {},
"services": {
"ANY": {
"protocol": "ip",
"port": None
}
},
"vpn_pools": {},
"rules": []
}
for item in data:
item_type = item.get("type")
if item_type == "role":
role_name = item["name"]
if role_name not in model["roles"]:
model["roles"].append(role_name)
elif item_type == "network":
model["networks"][item["name"]] = item["cidr"]
elif item_type == "service":
model["services"][item["name"]] = {
"protocol": item["protocol"],
"port": item["port"]
}
elif item_type == "vpn":
model["vpn_pools"][item["name"]] = item["cidr"]
model["networks"][item["name"]] = item["cidr"]
if item["name"] not in model["roles"]:
model["roles"].append(item["name"])
elif item_type == "rule":
model["rules"].append(item)
return model