Skip to content

Commit

Permalink
Replace shallow copy to deep
Browse files Browse the repository at this point in the history
  • Loading branch information
forefy committed Feb 16, 2024
1 parent ac0491f commit e929a2e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions eburger/utils/outputs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Silence tool prints
import copy
from datetime import datetime
import json
import os
Expand Down Expand Up @@ -172,21 +173,22 @@ def save_as_sarif(output_file_path: Path, insights: dict):
"runs": [],
}

new_run = sarif_run_template.copy()
new_run = copy.deepcopy(sarif_run_template)

# insight is like a result object
for insight in insights:
rule_id = insight["name"].replace(" ", "_")

rule_exists = False

for index, rule in enumerate(new_run["tool"]["driver"]["rules"]):
if rule["id"] == rule_id:
rule_exists = True
rule_index = index # Capture the index of the existing rule
break

if not rule_exists:
new_rule = sarif_rule_template.copy()
new_rule = copy.deepcopy(sarif_rule_template)
new_rule["id"] = rule_id
new_rule["name"] = insight["name"]
new_rule["shortDescription"]["text"] = insight["name"]
Expand All @@ -200,6 +202,7 @@ def save_as_sarif(output_file_path: Path, insights: dict):
new_rule["properties"]["problem"]["security-severity"] = (
convert_severity_to_sarif_security_severity(insight["severity"])
)

new_run["tool"]["driver"]["rules"].append(new_rule)
rule_index = len(new_run["tool"]["driver"]["rules"]) - 1

Expand Down

0 comments on commit e929a2e

Please sign in to comment.