@@ -100,12 +100,17 @@ def _should_use_scan_service(scan_type: str, scan_parameters: dict) -> bool:
100
100
return scan_type == consts .SECRET_SCAN_TYPE and scan_parameters .get ('report' ) is True
101
101
102
102
103
- def _should_use_sync_flow (scan_type : str , sync_option : bool , scan_parameters : Optional [dict ] = None ) -> bool :
103
+ def _should_use_sync_flow (
104
+ command_scan_type : str , scan_type : str , sync_option : bool , scan_parameters : Optional [dict ] = None
105
+ ) -> bool :
104
106
if not sync_option :
105
107
return False
106
108
107
- if scan_type not in (consts .SCA_SCAN_TYPE ,):
108
- raise ValueError (f'Sync scan is not available for { scan_type } scan type.' )
109
+ if command_scan_type not in {'path' , 'repository' }:
110
+ raise ValueError (f'Sync flow is not available for "{ command_scan_type } " command type. Remove --sync option.' )
111
+
112
+ if scan_type is consts .SAST_SCAN_TYPE :
113
+ raise ValueError ('Sync scan is not available for SAST scan type.' )
109
114
110
115
if scan_parameters .get ('report' ) is True :
111
116
raise ValueError ('You can not use sync flow with report option. Either remove "report" or "sync" option.' )
@@ -163,7 +168,7 @@ def _scan_batch_thread_func(batch: List[Document]) -> Tuple[str, CliError, Local
163
168
scan_completed = False
164
169
165
170
should_use_scan_service = _should_use_scan_service (scan_type , scan_parameters )
166
- should_use_sync_flow = _should_use_sync_flow (scan_type , sync_option , scan_parameters )
171
+ should_use_sync_flow = _should_use_sync_flow (command_scan_type , scan_type , sync_option , scan_parameters )
167
172
168
173
try :
169
174
logger .debug ('Preparing local files, %s' , {'batch_size' : len (batch )})
@@ -217,7 +222,7 @@ def _scan_batch_thread_func(batch: List[Document]) -> Tuple[str, CliError, Local
217
222
zip_file_size ,
218
223
command_scan_type ,
219
224
error_message ,
220
- should_use_scan_service ,
225
+ should_use_scan_service or should_use_sync_flow , # sync flow implies scan service
221
226
)
222
227
223
228
return scan_id , error , local_scan_result
@@ -359,6 +364,8 @@ def scan_commit_range_documents(
359
364
scan_parameters : Optional [dict ] = None ,
360
365
timeout : Optional [int ] = None ,
361
366
) -> None :
367
+ """Used by SCA only"""
368
+
362
369
cycode_client = context .obj ['client' ]
363
370
scan_type = context .obj ['scan_type' ]
364
371
severity_threshold = context .obj ['severity_threshold' ]
@@ -484,7 +491,8 @@ def perform_scan(
484
491
should_use_sync_flow : bool = False ,
485
492
) -> ZippedFileScanResult :
486
493
if should_use_sync_flow :
487
- return perform_scan_sync (cycode_client , zipped_documents , scan_type , scan_parameters )
494
+ # it does not support commit range scans; should_use_sync_flow handles it
495
+ return perform_scan_sync (cycode_client , zipped_documents , scan_type , scan_parameters , is_git_diff )
488
496
489
497
if scan_type in (consts .SCA_SCAN_TYPE , consts .SAST_SCAN_TYPE ) or should_use_scan_service :
490
498
return perform_scan_async (cycode_client , zipped_documents , scan_type , scan_parameters , is_commit_range )
@@ -520,12 +528,13 @@ def perform_scan_sync(
520
528
zipped_documents : 'InMemoryZip' ,
521
529
scan_type : str ,
522
530
scan_parameters : dict ,
531
+ is_git_diff : bool = False ,
523
532
) -> ZippedFileScanResult :
524
- scan_results = cycode_client .zipped_file_scan_sync (zipped_documents , scan_type , scan_parameters )
533
+ scan_results = cycode_client .zipped_file_scan_sync (zipped_documents , scan_type , scan_parameters , is_git_diff )
525
534
logger .debug ('Sync scan request has been triggered successfully, %s' , {'scan_id' : scan_results .id })
526
535
return ZippedFileScanResult (
527
536
did_detect = True ,
528
- detections_per_file = _map_detections_per_file_and_commit_id (scan_results .detection_messages ),
537
+ detections_per_file = _map_detections_per_file_and_commit_id (scan_type , scan_results .detection_messages ),
529
538
scan_id = scan_results .id ,
530
539
)
531
540
@@ -610,7 +619,7 @@ def get_document_detections(
610
619
commit_id = detections_per_file .commit_id
611
620
612
621
logger .debug (
613
- 'Going to find the document of the violated file. , %s' , {'file_name' : file_name , 'commit_id' : commit_id }
622
+ 'Going to find the document of the violated file, %s' , {'file_name' : file_name , 'commit_id' : commit_id }
614
623
)
615
624
616
625
document = _get_document_by_file_name (documents_to_scan , file_name , commit_id )
@@ -874,7 +883,7 @@ def _get_scan_result(
874
883
875
884
return ZippedFileScanResult (
876
885
did_detect = True ,
877
- detections_per_file = _map_detections_per_file_and_commit_id (scan_raw_detections ),
886
+ detections_per_file = _map_detections_per_file_and_commit_id (scan_type , scan_raw_detections ),
878
887
scan_id = scan_id ,
879
888
report_url = _try_get_report_url_if_needed (cycode_client , should_get_report , scan_id , scan_type ),
880
889
)
@@ -904,7 +913,7 @@ def _try_get_report_url_if_needed(
904
913
logger .debug ('Failed to get report URL' , exc_info = e )
905
914
906
915
907
- def _map_detections_per_file_and_commit_id (raw_detections : List [dict ]) -> List [DetectionsPerFile ]:
916
+ def _map_detections_per_file_and_commit_id (scan_type : str , raw_detections : List [dict ]) -> List [DetectionsPerFile ]:
908
917
"""Converts list of detections (async flow) to list of DetectionsPerFile objects (sync flow).
909
918
910
919
Args:
@@ -923,7 +932,7 @@ def _map_detections_per_file_and_commit_id(raw_detections: List[dict]) -> List[D
923
932
# FIXME(MarshalX): investigate this field mapping
924
933
raw_detection ['message' ] = raw_detection ['correlation_message' ]
925
934
926
- file_name = _get_file_name_from_detection (raw_detection )
935
+ file_name = _get_file_name_from_detection (scan_type , raw_detection )
927
936
detection : Detection = DetectionSchema ().load (raw_detection )
928
937
commit_id : Optional [str ] = detection .detection_details .get ('commit_id' ) # could be None
929
938
group_by_key = (file_name , commit_id )
@@ -942,12 +951,10 @@ def _map_detections_per_file_and_commit_id(raw_detections: List[dict]) -> List[D
942
951
]
943
952
944
953
945
- def _get_file_name_from_detection (raw_detection : dict ) -> str :
946
- category = raw_detection .get ('category' )
947
-
948
- if category == 'SAST' :
954
+ def _get_file_name_from_detection (scan_type : str , raw_detection : dict ) -> str :
955
+ if scan_type == consts .SAST_SCAN_TYPE :
949
956
return raw_detection ['detection_details' ]['file_path' ]
950
- if category == 'SecretDetection' :
957
+ if scan_type == consts . SECRET_SCAN_TYPE :
951
958
return _get_secret_file_name_from_detection (raw_detection )
952
959
953
960
return raw_detection ['detection_details' ]['file_name' ]
0 commit comments