Skip to content

Commit f82ba4e

Browse files
authored
CM-12769 - add scan_id to printed results (#18)
add scan_id to printed results
1 parent ac2cb70 commit f82ba4e

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

cli/code_scanner.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def scan_documents(context: click.Context, documents_to_scan: List[Document],
142142
error_message = None
143143
all_detections_count = 0
144144
output_detections_count = 0
145-
scan_id = uuid4()
145+
scan_id = _get_scan_id(context)
146146
zipped_documents = InMemoryZip()
147147

148148
try:
@@ -452,3 +452,9 @@ def _report_scan_status(context: click.Context, scan_type: str, scan_id: str, sc
452452
except Exception as e:
453453
logger.debug('Failed to report scan status, %s', {'exception_message': str(e)})
454454
pass
455+
456+
457+
def _get_scan_id(context: click.Context):
458+
scan_id = uuid4()
459+
context.obj['scan_id'] = scan_id
460+
return scan_id

cli/printers/json_printer.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,14 @@ def print_results(self, context: click.Context, results: List[DocumentDetections
1111
detections = [detection for document_detections in results for detection in document_detections.detections]
1212
detections_schema = DetectionSchema(many=True)
1313
detections_dict = detections_schema.dump(detections)
14-
json_result = json.dumps(detections_dict, indent=4)
15-
click.secho(json_result, fg='white')
14+
json_result = self._get_json_result(context, detections_dict)
15+
click.secho(json_result)
16+
17+
def _get_json_result(self, context, detections):
18+
scan_id = context.obj.get('scan_id')
19+
result = {
20+
'scan_id': str(scan_id),
21+
'detections': detections
22+
}
23+
24+
return json.dumps(result, indent=4)

cli/printers/text_printer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ class TextPrinter(BasePrinter):
1414
GREEN_COLOR_NAME = 'green'
1515

1616
def print_results(self, context: click.Context, results: List[DocumentDetections]):
17+
scan_id = context.obj.get('scan_id')
18+
click.secho(f"Scan Results: (scan_id: {scan_id})")
19+
1720
if not results:
18-
click.secho("Good job! No issues were found!!! 👏👏👏", fg='green')
21+
click.secho("Good job! No issues were found!!! 👏👏👏", fg=self.GREEN_COLOR_NAME)
1922
return
2023

2124
scan_type = context.obj.get('scan_type')

0 commit comments

Comments
 (0)