33
44class DeepfenceThreatmapperCompliance :
55 def get_findings (self , row , headers , test ):
6- description = ""
6+ if "compliance_check_type" in headers and "test_number" in headers :
7+ return self ._parse_old_format (row , headers , test )
8+ if "Compliance Standard" in headers and "Control ID" in headers :
9+ return self ._parse_new_format (row , headers , test )
10+ return None
11+
12+ def _parse_old_format (self , row , headers , test ):
713 compliance_check_type = row [headers ["compliance_check_type" ]]
814 count = row [headers ["count" ]]
915 doc_id = row [headers ["doc_id" ]]
@@ -18,34 +24,76 @@ def get_findings(self, row, headers, test):
1824 test_desc = row [headers ["test_desc" ]]
1925 test_info = row [headers ["test_info" ]]
2026 test_number = row [headers ["test_number" ]]
21- description += "**compliance_check_type:** " + str (compliance_check_type ) + "\n "
22- description += "**host_name:** " + str (host_name ) + "\n "
23- description += "**cloud_account_id:** " + str (cloud_account_id ) + "\n "
24- description += "**masked:** " + str (masked ) + "\n "
25- description += "**node_id:** " + str (node_id ) + "\n "
26- description += "**node_name:** " + str (node_name ) + "\n "
27- description += "**node_type:** " + str (node_type ) + "\n "
28- description += "**status:** " + str (status ) + "\n "
29- description += "**test_category:** " + str (test_category ) + "\n "
30- description += "**test_desc:** " + str (test_desc ) + "\n "
31- description += "**test_info:** " + str (test_info ) + "\n "
32- description += "**test_number:** " + str (test_number ) + "\n "
33- description += "**count:** " + str (count ) + "\n "
34- description += "**doc_id:** " + str (doc_id ) + "\n "
27+
28+ description = (
29+ f"**Compliance Check Type:** { compliance_check_type } \n "
30+ f"**Host Name:** { host_name } \n "
31+ f"**Cloud Account ID:** { cloud_account_id } \n "
32+ f"**Masked:** { masked } \n "
33+ f"**Node ID:** { node_id } \n "
34+ f"**Node Name:** { node_name } \n "
35+ f"**Node Type:** { node_type } \n "
36+ f"**Status:** { status } \n "
37+ f"**Test Category:** { test_category } \n "
38+ f"**Test Description:** { test_desc } \n "
39+ f"**Test Info:** { test_info } \n "
40+ f"**Test Number:** { test_number } \n "
41+ f"**Count:** { count } \n "
42+ f"**Doc ID:** { doc_id } \n "
43+ )
44+
45+ return Finding (
46+ title = f"Threatmapper_Compliance_Report-{ test_number } " ,
47+ description = description ,
48+ severity = self .compliance_severity (status ),
49+ static_finding = False ,
50+ dynamic_finding = True ,
51+ test = test ,
52+ )
53+
54+ def _parse_new_format (self , row , headers , test ):
55+ compliance_standard = row [headers ["Compliance Standard" ]]
56+ status = row [headers ["Status" ]]
57+ category = row [headers ["Category" ]]
58+ description_text = row [headers ["Description" ]]
59+ info = row [headers ["Info" ]]
60+ control_id = row [headers ["Control ID" ]]
61+ node_name = row [headers ["Node Name" ]]
62+ node_type = row [headers ["Node Type" ]]
63+ remediation = row [headers ["Remediation" ]]
64+ masked = row [headers ["Masked" ]]
65+
66+ description = (
67+ f"**Compliance Standard:** { compliance_standard } \n "
68+ f"**Status:** { status } \n "
69+ f"**Category:** { category } \n "
70+ f"**Description:** { description_text } \n "
71+ f"**Info:** { info } \n "
72+ f"**Control ID:** { control_id } \n "
73+ f"**Node Name:** { node_name } \n "
74+ f"**Node Type:** { node_type } \n "
75+ f"**Remediation:** { remediation } \n "
76+ f"**Masked:** { masked } \n "
77+ )
78+
3579 return Finding (
36- title = "Threatmapper_Compliance_Report-" + test_number ,
80+ title = f "Threatmapper_Compliance_Report-{ control_id } " ,
3781 description = description ,
3882 severity = self .compliance_severity (status ),
3983 static_finding = False ,
4084 dynamic_finding = True ,
85+ mitigation = remediation ,
4186 test = test ,
4287 )
4388
4489 def compliance_severity (self , severity_input ):
90+ if severity_input is None :
91+ return "Info"
92+ severity_input = severity_input .lower ()
4593 if severity_input in {"pass" , "info" }:
46- output = "Info"
47- elif severity_input == "warn" :
48- output = "Medium"
49- else :
50- output = "Info "
51- return output
94+ return "Info"
95+ if severity_input == "warn" :
96+ return "Medium"
97+ if severity_input == "fail" :
98+ return "High "
99+ return "Info"
0 commit comments