Skip to content

Commit e8891a3

Browse files
CM-60184-Cleanup
1 parent 22cbc67 commit e8891a3

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

cycode/cli/apps/scan/code_scanner.py

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
if TYPE_CHECKING:
3838
from cycode.cli.files_collector.models.in_memory_zip import InMemoryZip
39+
from cycode.cli.printers.console_printer import ConsolePrinter
40+
from cycode.cli.utils.progress_bar import BaseProgressBar
3941
from cycode.cyclient.scan_client import ScanClient
4042

4143
start_scan_time = time.time()
@@ -184,6 +186,36 @@ def _scan_batch_thread_func(batch: list[Document]) -> tuple[str, CliError, Local
184186
return _scan_batch_thread_func
185187

186188

189+
def _run_presigned_upload_scan(
190+
scan_batch_thread_func: Callable,
191+
scan_type: str,
192+
documents_to_scan: list[Document],
193+
progress_bar: 'BaseProgressBar',
194+
printer: 'ConsolePrinter',
195+
) -> tuple:
196+
try:
197+
# Try to zip all documents as a single batch; ZipTooLargeError raised if it exceeds the scan type's limit
198+
zip_documents(scan_type, documents_to_scan)
199+
# It fits: skip batching and upload everything as one ZIP
200+
return run_parallel_batched_scan(
201+
scan_batch_thread_func,
202+
scan_type,
203+
documents_to_scan,
204+
progress_bar=progress_bar,
205+
skip_batching=True,
206+
)
207+
except custom_exceptions.ZipTooLargeError:
208+
printer.print_warning(
209+
'The scan is too large to upload as a single file. This may result in corrupted scan results.'
210+
)
211+
return run_parallel_batched_scan(
212+
scan_batch_thread_func,
213+
scan_type,
214+
documents_to_scan,
215+
progress_bar=progress_bar,
216+
)
217+
218+
187219
def scan_documents(
188220
ctx: typer.Context,
189221
documents_to_scan: list[Document],
@@ -209,28 +241,9 @@ def scan_documents(
209241
scan_batch_thread_func = _get_scan_documents_thread_func(ctx, is_git_diff, is_commit_range, scan_parameters)
210242

211243
if should_use_presigned_upload(scan_type):
212-
try:
213-
# Try to zip all documents as a single batch; ZipTooLargeError raised if it exceeds the scan type's limit
214-
zip_documents(scan_type, documents_to_scan)
215-
# It fits: skip batching and upload everything as one ZIP
216-
errors, local_scan_results = run_parallel_batched_scan(
217-
scan_batch_thread_func,
218-
scan_type,
219-
documents_to_scan,
220-
progress_bar=progress_bar,
221-
skip_batching=True,
222-
)
223-
except custom_exceptions.ZipTooLargeError:
224-
printer.print_warning(
225-
'The repository is too large to upload as a single file. '
226-
'Falling back to batched scanning. This may result in multiple scan results.'
227-
)
228-
errors, local_scan_results = run_parallel_batched_scan(
229-
scan_batch_thread_func,
230-
scan_type,
231-
documents_to_scan,
232-
progress_bar=progress_bar,
233-
)
244+
errors, local_scan_results = _run_presigned_upload_scan(
245+
scan_batch_thread_func, scan_type, documents_to_scan, progress_bar, printer
246+
)
234247
else:
235248
errors, local_scan_results = run_parallel_batched_scan(
236249
scan_batch_thread_func, scan_type, documents_to_scan, progress_bar=progress_bar
@@ -263,7 +276,10 @@ def _perform_scan_v4_async(
263276
scan_async_result = cycode_client.scan_repository_from_upload_id(
264277
scan_type, upload_link.upload_id, scan_parameters, is_git_diff, is_commit_range
265278
)
266-
logger.debug('V4 scan request triggered, %s', {'scan_id': scan_async_result.scan_id})
279+
logger.debug(
280+
'Presigned upload scan request triggered, %s',
281+
{'scan_id': scan_async_result.scan_id, 'upload_id': upload_link.upload_id},
282+
)
267283

268284
return poll_scan_results(cycode_client, scan_async_result.scan_id, scan_type, scan_parameters)
269285

cycode/cyclient/scan_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def commit_range_scan_from_upload_ids(
209209
is_git_diff: bool = False,
210210
) -> models.ScanInitializationResponse:
211211
async_scan_type = self.scan_config.get_async_scan_type(scan_type)
212-
url_path = f'{self.get_scan_service_v4_url_path(scan_type)}/{async_scan_type}/repository/commit-range'
212+
url_path = f'{self.get_scan_service_v4_url_path(scan_type)}/{async_scan_type}/commit-range'
213213
response = self.scan_cycode_client.post(
214214
url_path=url_path,
215215
body={

0 commit comments

Comments
 (0)