-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.py
33 lines (31 loc) · 1.42 KB
/
parser.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
import json
import pprint
import sys
def parse(path):
try:
with open(path, "r", encoding="utf-8") as fd:
ltm = []
for el in json.load(fd)["detail"]["diagrams"][0]["diagramJson"]["cells"]:
tmp = {}
for key in ["type", "hasOpenThreats", "isWebApplication", "isEncrypted",
"description", "privilegeLevel", "isPublicNetwork", "outOfScope",
"protocol", "storesInventory", "storesCredentials"]:
if key in el.keys():
tmp[key] = el[key]
if "text" in el["attrs"] and "text" in el["attrs"]["text"]:
tmp["text"] = el["attrs"]["text"]["text"]
if "labels" in el:
tmp["label"] = el["labels"][0]["attrs"]["text"]["text"]
if "threats" in el.keys():
tmp["threats"] = {}
for threat in el["threats"]:
for t in threat.keys():
if t in ["description", "mitigation", "modelType",
"severity", "status", "title", "type"]:
tmp["threats"][t] = threat[t]
ltm.append(tmp)
return ltm
except IOError as e:
print(f"Bad Human: {e}")
if __name__ == "__main__":
pprint.pprint(parse(sys.argv[1]))