@@ -98,8 +98,21 @@ def set_issue_detected_by_scan_results(context: click.Context, scan_results: Lis
9898 set_issue_detected (context , any (scan_result .issue_detected for scan_result in scan_results ))
9999
100100
101- def _should_use_scan_service (scan_type : str , scan_parameters : Optional [dict ] = None ) -> bool :
102- return scan_type == consts .SECRET_SCAN_TYPE and scan_parameters is not None and scan_parameters ['report' ] is True
101+ def _should_use_scan_service (scan_type : str , scan_parameters : dict ) -> bool :
102+ return scan_type == consts .SECRET_SCAN_TYPE and scan_parameters .get ('report' ) is True
103+
104+
105+ def _should_use_sync_flow (scan_type : str , sync_option : bool , scan_parameters : Optional [dict ] = None ) -> bool :
106+ if not sync_option :
107+ return False
108+
109+ if scan_type not in (consts .SCA_SCAN_TYPE ,):
110+ raise ValueError (f'Sync scan is not available for { scan_type } scan type.' )
111+
112+ if scan_parameters .get ('report' ) is True :
113+ raise ValueError ('You can not use sync flow with report option. Either remove "report" or "sync" option.' )
114+
115+ return True
103116
104117
105118def _enrich_scan_result_with_data_from_detection_rules (
@@ -141,6 +154,7 @@ def _get_scan_documents_thread_func(
141154 cycode_client = context .obj ['client' ]
142155 scan_type = context .obj ['scan_type' ]
143156 severity_threshold = context .obj ['severity_threshold' ]
157+ sync_option = context .obj ['sync' ]
144158 command_scan_type = context .info_name
145159
146160 scan_parameters ['aggregation_id' ] = str (_generate_unique_id ())
@@ -151,7 +165,9 @@ def _scan_batch_thread_func(batch: List[Document]) -> Tuple[str, CliError, Local
151165
152166 scan_id = str (_generate_unique_id ())
153167 scan_completed = False
168+
154169 should_use_scan_service = _should_use_scan_service (scan_type , scan_parameters )
170+ should_use_sync_flow = _should_use_sync_flow (scan_type , sync_option , scan_parameters )
155171
156172 try :
157173 logger .debug ('Preparing local files, %s' , {'batch_size' : len (batch )})
@@ -166,6 +182,7 @@ def _scan_batch_thread_func(batch: List[Document]) -> Tuple[str, CliError, Local
166182 is_commit_range ,
167183 scan_parameters ,
168184 should_use_scan_service ,
185+ should_use_sync_flow ,
169186 )
170187
171188 _enrich_scan_result_with_data_from_detection_rules (cycode_client , scan_type , scan_result )
@@ -439,7 +456,11 @@ def perform_scan(
439456 is_commit_range : bool ,
440457 scan_parameters : dict ,
441458 should_use_scan_service : bool = False ,
459+ should_use_sync_flow : bool = False ,
442460) -> ZippedFileScanResult :
461+ if should_use_sync_flow :
462+ return perform_scan_sync (cycode_client , zipped_documents , scan_type , scan_parameters )
463+
443464 if scan_type in (consts .SCA_SCAN_TYPE , consts .SAST_SCAN_TYPE ) or should_use_scan_service :
444465 return perform_scan_async (cycode_client , zipped_documents , scan_type , scan_parameters )
445466
@@ -466,6 +487,21 @@ def perform_scan_async(
466487 )
467488
468489
490+ def perform_scan_sync (
491+ cycode_client : 'ScanClient' ,
492+ zipped_documents : 'InMemoryZip' ,
493+ scan_type : str ,
494+ scan_parameters : dict ,
495+ ) -> ZippedFileScanResult :
496+ scan_results = cycode_client .zipped_file_scan_sync (zipped_documents , scan_type , scan_parameters )
497+ logger .debug ('scan request has been triggered successfully, scan id: %s' , scan_results .id )
498+ return ZippedFileScanResult (
499+ did_detect = True ,
500+ detections_per_file = _map_detections_per_file (scan_results .detection_messages ),
501+ scan_id = scan_results .id ,
502+ )
503+
504+
469505def perform_commit_range_scan_async (
470506 cycode_client : 'ScanClient' ,
471507 from_commit_zipped_documents : 'InMemoryZip' ,
@@ -888,10 +924,10 @@ def _map_detections_per_file(detections: List[dict]) -> List[DetectionsPerFile]:
888924
889925
890926def _get_file_name_from_detection (detection : dict ) -> str :
891- if detection [ 'category' ] == 'SAST' :
927+ if detection . get ( 'category' ) == 'SAST' :
892928 return detection ['detection_details' ]['file_path' ]
893929
894- if detection [ 'category' ] == 'SecretDetection' :
930+ if detection . get ( 'category' ) == 'SecretDetection' :
895931 return _get_secret_file_name_from_detection (detection )
896932
897933 return detection ['detection_details' ]['file_name' ]
0 commit comments