Created
February 29, 2024 09:31
-
-
Save Winand/dbb229abaebdb539e8c7b84b9647c05b to your computer and use it in GitHub Desktop.
Convert GitLab SAST report to HTML table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from json2html import json2html | |
import json | |
from markdown import markdown | |
filename = "gl-sast-report" | |
svr = {"Critical": "Crimson", "Medium": "Coral", "Low": "MediumSeaGreen", "Info": "SteelBlue"} | |
with open(filename + ".json") as f: | |
inp = json.load(f) | |
data = inp["vulnerabilities"] | |
for i in data: | |
del i["id"], i["category"], i["identifiers"] | |
i["description"] = markdown(i["description"], extensions=["fenced_code"]) | |
i["severity"] = f"<font color='{svr[i['severity']]}'>{i['severity']}</font>" | |
i["scanner"] = i["scanner"]["name"] | |
i["location"] = ":".join(str(i) for i in i["location"].values()) | |
with open(filename + ".html", 'w') as f: | |
html: str = json2html.convert(data, escape=False, table_attributes="border=\"1\" style=\"table-layout: fixed; width: 100%; word-wrap: break-word\"") | |
html = html.replace("<th>description</th>", "<th style='width:45%'>description</th>") | |
f.write(html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires
markdown
andjson2html
packages