Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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