@@ -100,24 +100,27 @@ def set_issue_detected_by_scan_results(ctx: typer.Context, scan_results: List[Lo
100100 set_issue_detected (ctx , any (scan_result .issue_detected for scan_result in scan_results ))
101101
102102
103- def _should_use_scan_service ( scan_type : str , scan_parameters : dict ) -> bool :
104- return scan_type == consts . SECRET_SCAN_TYPE and scan_parameters . get ( 'report' ) is True
103+ def _should_use_sync_flow ( command_scan_type : str , scan_type : str , sync_option : bool ) -> bool :
104+ """Decide whether to use sync flow or async flow for the scan.
105105
106-
107- def _should_use_sync_flow (
108- command_scan_type : str , scan_type : str , sync_option : bool , scan_parameters : Optional [dict ] = None
109- ) -> bool :
110- if not sync_option :
106+ The logic:
107+ - for IAC scan, sync flow is always used
108+ - for SAST scan, sync flow is not supported
109+ - for SCA and Secrets scan, sync flow is supported only for path/repository scan
110+ """
111+ if not sync_option and scan_type != consts .IAC_SCAN_TYPE :
111112 return False
112113
113114 if command_scan_type not in {'path' , 'repository' }:
114115 raise ValueError (f'Sync flow is not available for "{ command_scan_type } " command type. Remove --sync option.' )
115116
116- if scan_type is consts .SAST_SCAN_TYPE :
117- raise ValueError ('Sync scan is not available for SAST scan type.' )
117+ if scan_type == consts .IAC_SCAN_TYPE :
118+ # sync in the only available flow for IAC scan; we do not use detector directly anymore
119+ return True
118120
119- if scan_parameters .get ('report' ) is True :
120- raise ValueError ('You can not use sync flow with report option. Either remove "report" or "sync" option.' )
121+ if scan_type is consts .SAST_SCAN_TYPE : # noqa: SIM103
122+ # SAST does not support sync flow
123+ return False
121124
122125 return True
123126
@@ -169,8 +172,7 @@ def _scan_batch_thread_func(batch: List[Document]) -> Tuple[str, CliError, Local
169172 scan_id = str (_generate_unique_id ())
170173 scan_completed = False
171174
172- should_use_scan_service = _should_use_scan_service (scan_type , scan_parameters )
173- should_use_sync_flow = _should_use_sync_flow (command_scan_type , scan_type , sync_option , scan_parameters )
175+ should_use_sync_flow = _should_use_sync_flow (command_scan_type , scan_type , sync_option )
174176
175177 try :
176178 logger .debug ('Preparing local files, %s' , {'batch_files_count' : len (batch )})
@@ -180,11 +182,9 @@ def _scan_batch_thread_func(batch: List[Document]) -> Tuple[str, CliError, Local
180182 cycode_client ,
181183 zipped_documents ,
182184 scan_type ,
183- scan_id ,
184185 is_git_diff ,
185186 is_commit_range ,
186187 scan_parameters ,
187- should_use_scan_service ,
188188 should_use_sync_flow ,
189189 )
190190
@@ -224,7 +224,6 @@ def _scan_batch_thread_func(batch: List[Document]) -> Tuple[str, CliError, Local
224224 zip_file_size ,
225225 command_scan_type ,
226226 error_message ,
227- should_use_scan_service or should_use_sync_flow , # sync flow implies scan service
228227 )
229228
230229 return scan_id , error , local_scan_result
@@ -456,24 +455,16 @@ def perform_scan(
456455 cycode_client : 'ScanClient' ,
457456 zipped_documents : 'InMemoryZip' ,
458457 scan_type : str ,
459- scan_id : str ,
460458 is_git_diff : bool ,
461459 is_commit_range : bool ,
462460 scan_parameters : dict ,
463- should_use_scan_service : bool = False ,
464461 should_use_sync_flow : bool = False ,
465462) -> ZippedFileScanResult :
466463 if should_use_sync_flow :
467464 # it does not support commit range scans; should_use_sync_flow handles it
468465 return perform_scan_sync (cycode_client , zipped_documents , scan_type , scan_parameters , is_git_diff )
469466
470- if scan_type in (consts .SCA_SCAN_TYPE , consts .SAST_SCAN_TYPE ) or should_use_scan_service :
471- return perform_scan_async (cycode_client , zipped_documents , scan_type , scan_parameters , is_commit_range )
472-
473- if is_commit_range :
474- return cycode_client .commit_range_zipped_file_scan (scan_type , zipped_documents , scan_id )
475-
476- return cycode_client .zipped_file_scan (scan_type , zipped_documents , scan_id , scan_parameters , is_git_diff )
467+ return perform_scan_async (cycode_client , zipped_documents , scan_type , scan_parameters , is_commit_range )
477468
478469
479470def perform_scan_async (
@@ -823,7 +814,6 @@ def _report_scan_status(
823814 zip_size : int ,
824815 command_scan_type : str ,
825816 error_message : Optional [str ],
826- should_use_scan_service : bool = False ,
827817) -> None :
828818 try :
829819 end_scan_time = time .time ()
@@ -840,12 +830,15 @@ def _report_scan_status(
840830 'scan_type' : scan_type ,
841831 }
842832
843- cycode_client .report_scan_status (scan_type , scan_id , scan_status , should_use_scan_service )
833+ cycode_client .report_scan_status (scan_type , scan_id , scan_status )
844834 except Exception as e :
845835 logger .debug ('Failed to report scan status' , exc_info = e )
846836
847837
848838def _generate_unique_id () -> UUID :
839+ if 'PYTEST_TEST_UNIQUE_ID' in os .environ :
840+ return UUID (os .environ ['PYTEST_TEST_UNIQUE_ID' ])
841+
849842 return uuid4 ()
850843
851844
@@ -868,13 +861,13 @@ def _get_scan_result(
868861 if not scan_details .detections_count :
869862 return init_default_scan_result (scan_id )
870863
871- scan_raw_detections = cycode_client .get_scan_raw_detections (scan_type , scan_id )
864+ scan_raw_detections = cycode_client .get_scan_raw_detections (scan_id )
872865
873866 return ZippedFileScanResult (
874867 did_detect = True ,
875868 detections_per_file = _map_detections_per_file_and_commit_id (scan_type , scan_raw_detections ),
876869 scan_id = scan_id ,
877- report_url = _try_get_any_report_url_if_needed ( cycode_client , scan_id , scan_type , scan_parameters ),
870+ report_url = _try_get_aggregation_report_url_if_needed ( scan_parameters , cycode_client , scan_type ),
878871 )
879872
880873
@@ -886,37 +879,6 @@ def init_default_scan_result(scan_id: str) -> ZippedFileScanResult:
886879 )
887880
888881
889- def _try_get_any_report_url_if_needed (
890- cycode_client : 'ScanClient' ,
891- scan_id : str ,
892- scan_type : str ,
893- scan_parameters : dict ,
894- ) -> Optional [str ]:
895- """Tries to get aggregation report URL if needed, otherwise tries to get report URL."""
896- aggregation_report_url = None
897- if scan_parameters :
898- _try_get_report_url_if_needed (cycode_client , scan_id , scan_type , scan_parameters )
899- aggregation_report_url = _try_get_aggregation_report_url_if_needed (scan_parameters , cycode_client , scan_type )
900-
901- if aggregation_report_url :
902- return aggregation_report_url
903-
904- return _try_get_report_url_if_needed (cycode_client , scan_id , scan_type , scan_parameters )
905-
906-
907- def _try_get_report_url_if_needed (
908- cycode_client : 'ScanClient' , scan_id : str , scan_type : str , scan_parameters : dict
909- ) -> Optional [str ]:
910- if not scan_parameters .get ('report' , False ):
911- return None
912-
913- try :
914- report_url_response = cycode_client .get_scan_report_url (scan_id , scan_type )
915- return report_url_response .report_url
916- except Exception as e :
917- logger .debug ('Failed to get report URL' , exc_info = e )
918-
919-
920882def _set_aggregation_report_url (ctx : typer .Context , aggregation_report_url : Optional [str ] = None ) -> None :
921883 ctx .obj ['aggregation_report_url' ] = aggregation_report_url
922884
0 commit comments