Skip to content

Commit 72564e2

Browse files
committed
Add naive json formatting
1 parent e43f284 commit 72564e2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

cve_bin_tool/OutputEngine.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import csv
2+
import json
23
import os
34

45
from datetime import datetime
@@ -20,11 +21,21 @@ def generate_filename(self, extention=None):
2021
self.filename = f"output.cve-bin-tool.{now}.{extention}"
2122

2223
def output_cves(self, outfile, output=None):
23-
2424
""" Output a list of CVEs
25-
format is modules[checker_name][version] = dict{id: severity}
25+
format self.modules[checker_name][version] = dict{id: severity}
26+
to other formats like CSV or JSON
2627
"""
28+
if output == "json":
29+
self.output_json(outfile)
30+
else: # csv, console, or anything else that is unrecognised
31+
self.output_csv(outfile)
32+
33+
def output_json(self, outfile):
34+
""" Output a JSON of CVEs """
35+
json.dump(self.modules, outfile)
2736

37+
def output_csv(self, outfile):
38+
""" Output a CSV of CVEs """
2839
writer = csv.writer(outfile)
2940
writer.writerow(["Module Name", "Version", "CVE Number", "Severity"])
3041
for modulename, versions in self.modules.items():

0 commit comments

Comments
 (0)