Skip to content

Commit f2c918c

Browse files
committed
revret printer
1 parent f6e3777 commit f2c918c

1 file changed

Lines changed: 16 additions & 35 deletions

File tree

cli/code_scanner.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from datetime import datetime
2-
31
import click
42
import json
53
import logging
@@ -11,7 +9,10 @@
119
from uuid import uuid4, UUID
1210
from git import Repo, NULL_TREE, InvalidGitRepositoryError
1311
from sys import getsizeof
12+
<<<<<<< HEAD
1413

14+
=======
15+
>>>>>>> parent of 17c2efe (CM-20731 Cycode CLI - print update status to console by printer (#72))
1516
from cli.printers import ResultsPrinter
1617
from cli.models import Document, DocumentDetections, Severity
1718
from cli.ci_integrations import get_commit_range
@@ -258,8 +259,12 @@ def scan_documents(context: click.Context, documents_to_scan: List[Document], is
258259

259260
try:
260261
zipped_documents = zip_documents_to_scan(scan_type, zipped_documents, documents_to_scan)
262+
<<<<<<< HEAD
261263
scan_result = perform_scan(context, cycode_client, zipped_documents, scan_type, scan_id, is_git_diff,
262264
is_commit_range,
265+
=======
266+
scan_result = perform_scan(cycode_client, zipped_documents, scan_type, scan_id, is_git_diff, is_commit_range,
267+
>>>>>>> parent of 17c2efe (CM-20731 Cycode CLI - print update status to console by printer (#72))
263268
scan_parameters)
264269
all_detections_count, output_detections_count = \
265270
handle_scan_result(context, scan_result, command_scan_type, scan_type, severity_threshold,
@@ -295,13 +300,11 @@ def scan_commit_range_documents(context: click.Context, from_documents_to_scan:
295300
try:
296301
scan_result = init_default_scan_result(str(scan_id))
297302
if should_scan_documents(from_documents_to_scan, to_documents_to_scan):
298-
logger.debug("Preparing from-commit zip")
299303
from_commit_zipped_documents = zip_documents_to_scan(scan_type, from_commit_zipped_documents,
300304
from_documents_to_scan)
301-
logger.debug("Preparing to-commit zip")
302305
to_commit_zipped_documents = zip_documents_to_scan(scan_type, to_commit_zipped_documents,
303306
to_documents_to_scan)
304-
scan_result = perform_commit_range_scan_async(context, cycode_client, from_commit_zipped_documents,
307+
scan_result = perform_commit_range_scan_async(cycode_client, from_commit_zipped_documents,
305308
to_commit_zipped_documents, scan_type, scan_parameters,
306309
timeout)
307310
all_detections_count, output_detections_count = \
@@ -344,14 +347,11 @@ def handle_scan_result(context, scan_result, command_scan_type, scan_type, sever
344347
def perform_pre_scan_documents_actions(context: click.Context, scan_type: str, documents_to_scan: List[Document],
345348
is_git_diff: bool = False):
346349
if scan_type == SCA_SCAN_TYPE:
347-
logger.debug(
348-
f"Perform pre scan document actions")
349350
sca_code_scanner.add_dependencies_tree_document(context, documents_to_scan, is_git_diff)
350351

351352

352353
def zip_documents_to_scan(scan_type: str, zip: InMemoryZip, documents: List[Document]):
353354
start_zip_creation_time = time.time()
354-
355355
for index, document in enumerate(documents):
356356
zip_file_size = getsizeof(zip.in_memory_zip)
357357
validate_zip_file_size(scan_type, zip_file_size)
@@ -376,11 +376,10 @@ def validate_zip_file_size(scan_type, zip_file_size):
376376
raise ZipTooLargeError(ZIP_MAX_SIZE_LIMIT_IN_BYTES)
377377

378378

379-
def perform_scan(context, cycode_client, zipped_documents: InMemoryZip, scan_type: str, scan_id: UUID,
380-
is_git_diff: bool,
379+
def perform_scan(cycode_client, zipped_documents: InMemoryZip, scan_type: str, scan_id: UUID, is_git_diff: bool,
381380
is_commit_range: bool, scan_parameters: dict):
382381
if scan_type == SCA_SCAN_TYPE or scan_type == SAST_SCAN_TYPE:
383-
return perform_scan_async(context, cycode_client, zipped_documents, scan_type, scan_parameters)
382+
return perform_scan_async(cycode_client, zipped_documents, scan_type, scan_parameters)
384383

385384
scan_result = cycode_client.commit_range_zipped_file_scan(scan_type, zipped_documents, scan_id) \
386385
if is_commit_range else cycode_client.zipped_file_scan(scan_type, zipped_documents, scan_id,
@@ -389,55 +388,41 @@ def perform_scan(context, cycode_client, zipped_documents: InMemoryZip, scan_typ
389388
return scan_result
390389

391390

392-
def perform_scan_async(context: click.Context, cycode_client, zipped_documents: InMemoryZip, scan_type: str,
391+
def perform_scan_async(cycode_client, zipped_documents: InMemoryZip, scan_type: str,
393392
scan_parameters: dict) -> ZippedFileScanResult:
394393
scan_async_result = cycode_client.zipped_file_scan_async(zipped_documents, scan_type, scan_parameters)
395394
logger.debug("scan request has been triggered successfully, scan id: %s", scan_async_result.scan_id)
396395

397-
return poll_scan_results(context, cycode_client, scan_async_result.scan_id)
396+
return poll_scan_results(cycode_client, scan_async_result.scan_id)
398397

399398

400-
def perform_commit_range_scan_async(context: click.Context, cycode_client, from_commit_zipped_documents: InMemoryZip,
399+
def perform_commit_range_scan_async(cycode_client, from_commit_zipped_documents: InMemoryZip,
401400
to_commit_zipped_documents: InMemoryZip, scan_type: str,
402401
scan_parameters: dict, timeout: int = None) -> ZippedFileScanResult:
403402
scan_async_result = \
404403
cycode_client.multiple_zipped_file_scan_async(from_commit_zipped_documents, to_commit_zipped_documents,
405404
scan_type, scan_parameters)
406405
logger.debug("scan request has been triggered successfully, scan id: %s", scan_async_result.scan_id)
407-
return poll_scan_results(context, cycode_client, scan_async_result.scan_id, timeout)
406+
return poll_scan_results(cycode_client, scan_async_result.scan_id, timeout)
408407

409408

410-
def poll_scan_results(context: click.Context, cycode_client, scan_id: str, polling_timeout: int = None):
409+
def poll_scan_results(cycode_client, scan_id: str, polling_timeout: int = None):
411410
if polling_timeout is None:
412411
polling_timeout = configuration_manager.get_scan_polling_timeout_in_seconds()
413412

414-
last_scan_update_at = None
415413
end_polling_time = time.time() + polling_timeout
416-
spinner = Halo(spinner='dots')
417-
spinner.start("Scan in progress")
418414
while time.time() < end_polling_time:
415+
logger.debug("scan in progress")
419416
scan_details = cycode_client.get_scan_details(scan_id)
420-
if scan_details.scan_update_at is not None and scan_details.scan_update_at != last_scan_update_at:
421-
last_scan_update_at = scan_details.scan_update_at
422-
print_scan_details(scan_details)
423417
if scan_details.scan_status == SCAN_STATUS_COMPLETED:
424-
spinner.succeed()
425418
return _get_scan_result(cycode_client, scan_id, scan_details)
426419
if scan_details.scan_status == SCAN_STATUS_ERROR:
427-
spinner.fail()
428420
raise ScanAsyncError(f'error occurred while trying to scan zip file. {scan_details.message}')
429421
time.sleep(SCAN_POLLING_WAIT_INTERVAL_IN_SECONDS)
430422

431-
spinner.stop_and_persist(symbol="⏰".encode('utf-8'))
432423
raise ScanAsyncError(f'Failed to complete scan after {polling_timeout} seconds')
433424

434425

435-
def print_scan_details(scan_details_response: ScanDetailsResponse):
436-
logger.info(f"Scan update: (scan_id: {scan_details_response.id})")
437-
logger.info(f"Scan status: {scan_details_response.scan_status}")
438-
if scan_details_response.message is not None:
439-
logger.info(f"Scan message: {scan_details_response.message}")
440-
441426
def print_results(context: click.Context, document_detections_list: List[DocumentDetections]):
442427
output_type = context.obj['output']
443428
printer = ResultsPrinter()
@@ -903,15 +888,11 @@ def wait_for_detections_creation(cycode_client, scan_id: str, expected_detection
903888
logger.debug("waiting for detections to be created")
904889
scan_persisted_detections_count = 0
905890
end_polling_time = time.time() + DETECTIONS_COUNT_VERIFICATION_TIMEOUT_IN_SECONDS
906-
spinner = Halo(spinner='dots')
907-
spinner.start("Please wait until printing scan result...")
908891
while time.time() < end_polling_time:
909892
scan_persisted_detections_count = cycode_client.get_scan_detections_count(scan_id)
910893
if scan_persisted_detections_count == expected_detections_count:
911-
spinner.succeed()
912894
return
913895
time.sleep(DETECTIONS_COUNT_VERIFICATION_WAIT_INTERVAL_IN_SECONDS)
914-
spinner.stop_and_persist(symbol="⏰".encode('utf-8'))
915896
logger.debug("%i detections has been created", scan_persisted_detections_count)
916897

917898

0 commit comments

Comments
 (0)