Skip to content

Commit 383f389

Browse files
authored
CM-32925 - Add Report URLs and Scan IDs to JSON output (#215)
1 parent ae85c8f commit 383f389

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

cycode/cli/printers/json_printer.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ def print_error(self, error: CliError) -> None:
2525
def print_scan_results(
2626
self, local_scan_results: List['LocalScanResult'], errors: Optional[Dict[str, 'CliError']] = None
2727
) -> None:
28+
scan_ids = []
29+
report_urls = []
2830
detections = []
31+
2932
for local_scan_result in local_scan_results:
33+
scan_ids.append(local_scan_result.scan_id)
34+
35+
if local_scan_result.report_url:
36+
report_urls.append(local_scan_result.report_url)
37+
3038
for document_detections in local_scan_result.document_detections:
3139
detections.extend(document_detections.detections)
3240

@@ -37,12 +45,16 @@ def print_scan_results(
3745
# FIXME(MarshalX): we don't care about scan IDs in JSON output due to clumsy JSON root structure
3846
inlined_errors = [err._asdict() for err in errors.values()]
3947

40-
click.echo(self._get_json_scan_result(detections_dict, inlined_errors))
48+
click.echo(self._get_json_scan_result(scan_ids, detections_dict, report_urls, inlined_errors))
4149

42-
def _get_json_scan_result(self, detections: dict, errors: List[dict]) -> str:
50+
def _get_json_scan_result(
51+
self, scan_ids: List[str], detections: dict, report_urls: List[str], errors: List[dict]
52+
) -> str:
4353
result = {
44-
'scan_id': 'DEPRECATED', # FIXME(MarshalX): we need change JSON struct to support multiple scan results
54+
'scan_id': 'DEPRECATED', # backward compatibility
55+
'scan_ids': scan_ids,
4556
'detections': detections,
57+
'report_urls': report_urls,
4658
'errors': errors,
4759
}
4860

0 commit comments

Comments
 (0)