@@ -98,8 +98,21 @@ def set_issue_detected_by_scan_results(context: click.Context, scan_results: Lis
98
98
set_issue_detected (context , any (scan_result .issue_detected for scan_result in scan_results ))
99
99
100
100
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
103
116
104
117
105
118
def _enrich_scan_result_with_data_from_detection_rules (
@@ -141,6 +154,7 @@ def _get_scan_documents_thread_func(
141
154
cycode_client = context .obj ['client' ]
142
155
scan_type = context .obj ['scan_type' ]
143
156
severity_threshold = context .obj ['severity_threshold' ]
157
+ sync_option = context .obj ['sync' ]
144
158
command_scan_type = context .info_name
145
159
146
160
scan_parameters ['aggregation_id' ] = str (_generate_unique_id ())
@@ -151,7 +165,9 @@ def _scan_batch_thread_func(batch: List[Document]) -> Tuple[str, CliError, Local
151
165
152
166
scan_id = str (_generate_unique_id ())
153
167
scan_completed = False
168
+
154
169
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 )
155
171
156
172
try :
157
173
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
166
182
is_commit_range ,
167
183
scan_parameters ,
168
184
should_use_scan_service ,
185
+ should_use_sync_flow ,
169
186
)
170
187
171
188
_enrich_scan_result_with_data_from_detection_rules (cycode_client , scan_type , scan_result )
@@ -439,7 +456,11 @@ def perform_scan(
439
456
is_commit_range : bool ,
440
457
scan_parameters : dict ,
441
458
should_use_scan_service : bool = False ,
459
+ should_use_sync_flow : bool = False ,
442
460
) -> ZippedFileScanResult :
461
+ if should_use_sync_flow :
462
+ return perform_scan_sync (cycode_client , zipped_documents , scan_type , scan_parameters )
463
+
443
464
if scan_type in (consts .SCA_SCAN_TYPE , consts .SAST_SCAN_TYPE ) or should_use_scan_service :
444
465
return perform_scan_async (cycode_client , zipped_documents , scan_type , scan_parameters )
445
466
@@ -466,6 +487,21 @@ def perform_scan_async(
466
487
)
467
488
468
489
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
+
469
505
def perform_commit_range_scan_async (
470
506
cycode_client : 'ScanClient' ,
471
507
from_commit_zipped_documents : 'InMemoryZip' ,
@@ -888,10 +924,10 @@ def _map_detections_per_file(detections: List[dict]) -> List[DetectionsPerFile]:
888
924
889
925
890
926
def _get_file_name_from_detection (detection : dict ) -> str :
891
- if detection [ 'category' ] == 'SAST' :
927
+ if detection . get ( 'category' ) == 'SAST' :
892
928
return detection ['detection_details' ]['file_path' ]
893
929
894
- if detection [ 'category' ] == 'SecretDetection' :
930
+ if detection . get ( 'category' ) == 'SecretDetection' :
895
931
return _get_secret_file_name_from_detection (detection )
896
932
897
933
return detection ['detection_details' ]['file_name' ]
0 commit comments