Created
December 4, 2023 07:37
-
-
Save h4ck4life/9a87db54b28209af8e0fc59502260e7a to your computer and use it in GitHub Desktop.
Gitlab SAST result HTML converter
This file contains 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
import json | |
import sys | |
def parse_json_to_html(json_data): | |
vulnerabilities = json_data.get('vulnerabilities', []) | |
# Start HTML document | |
html = ''' | |
<html> | |
<head> | |
<title>SAST Report</title> | |
<style> | |
body { font-family: Arial, sans-serif; } | |
table { border-collapse: collapse; width: 100%; } | |
th, td { border: 1px solid #dddddd; text-align: left; padding: 8px; } | |
th { background-color: #f2f2f2; } | |
</style> | |
</head> | |
<body> | |
<h2>GitLab SAST Report</h2> | |
<table> | |
<tr> | |
<th>Name</th> | |
<th>Description</th> | |
<th>Severity</th> | |
<th>File</th> | |
<th>Line</th> | |
</tr> | |
''' | |
# Add table rows for each vulnerability | |
for item in vulnerabilities: | |
html += f''' | |
<tr> | |
<td>{item.get('name', '')}</td> | |
<td>{item.get('description', '')}</td> | |
<td>{item.get('severity', '')}</td> | |
<td>{item.get('location', {}).get('file', '')}</td> | |
<td>{item.get('location', {}).get('start_line', '')}</td> | |
</tr> | |
''' | |
# Close HTML document | |
html += ''' | |
</table> | |
</body> | |
</html> | |
''' | |
return html | |
def main(): | |
if len(sys.argv) != 3: | |
print("Usage: python convert_sast_to_html.py <input_json_file> <output_html_file>") | |
sys.exit(1) | |
input_json_file = sys.argv[1] | |
output_html_file = sys.argv[2] | |
# Read JSON data | |
with open(input_json_file, 'r') as file: | |
json_data = json.load(file) | |
html_content = parse_json_to_html(json_data) | |
# Write HTML content to file | |
with open(output_html_file, 'w') as file: | |
file.write(html_content) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment