Skip to content

Commit

Permalink
CM-32925 - Add Report URLs and Scan IDs to JSON output (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshalX authored Feb 28, 2024
1 parent ae85c8f commit 383f389
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cycode/cli/printers/json_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ def print_error(self, error: CliError) -> None:
def print_scan_results(
self, local_scan_results: List['LocalScanResult'], errors: Optional[Dict[str, 'CliError']] = None
) -> None:
scan_ids = []
report_urls = []
detections = []

for local_scan_result in local_scan_results:
scan_ids.append(local_scan_result.scan_id)

if local_scan_result.report_url:
report_urls.append(local_scan_result.report_url)

for document_detections in local_scan_result.document_detections:
detections.extend(document_detections.detections)

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

click.echo(self._get_json_scan_result(detections_dict, inlined_errors))
click.echo(self._get_json_scan_result(scan_ids, detections_dict, report_urls, inlined_errors))

def _get_json_scan_result(self, detections: dict, errors: List[dict]) -> str:
def _get_json_scan_result(
self, scan_ids: List[str], detections: dict, report_urls: List[str], errors: List[dict]
) -> str:
result = {
'scan_id': 'DEPRECATED', # FIXME(MarshalX): we need change JSON struct to support multiple scan results
'scan_id': 'DEPRECATED', # backward compatibility
'scan_ids': scan_ids,
'detections': detections,
'report_urls': report_urls,
'errors': errors,
}

Expand Down

0 comments on commit 383f389

Please sign in to comment.