Skip to content

Commit 0533c7d

Browse files
authored
CM-37160 - Remove legacy flow via detection count (#232)
1 parent e63c1db commit 0533c7d

File tree

4 files changed

+8
-59
lines changed

4 files changed

+8
-59
lines changed

cycode/cli/commands/scan/code_scanner.py

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,14 @@ def scan_documents(
317317
errors, local_scan_results = run_parallel_batched_scan(
318318
scan_batch_thread_func, documents_to_scan, progress_bar=progress_bar
319319
)
320-
aggregation_report_url = _try_get_aggregation_report_url_if_needed(
321-
scan_parameters, context.obj['client'], context.obj['scan_type']
322-
)
323-
set_aggregation_report_url(context, aggregation_report_url)
320+
321+
if len(local_scan_results) > 1:
322+
# if we used more than one batch, we need to fetch aggregate report url
323+
aggregation_report_url = _try_get_aggregation_report_url_if_needed(
324+
scan_parameters, context.obj['client'], context.obj['scan_type']
325+
)
326+
set_aggregation_report_url(context, aggregation_report_url)
327+
324328
progress_bar.set_section_length(ScanProgressBarSection.GENERATE_REPORT, 1)
325329
progress_bar.update(ScanProgressBarSection.GENERATE_REPORT)
326330
progress_bar.stop()
@@ -863,8 +867,6 @@ def _get_scan_result(
863867
if not scan_details.detections_count:
864868
return init_default_scan_result(cycode_client, scan_id, scan_type, should_get_report)
865869

866-
wait_for_detections_creation(cycode_client, scan_type, scan_id, scan_details.detections_count)
867-
868870
scan_detections = cycode_client.get_scan_detections(scan_type, scan_id)
869871

870872
return ZippedFileScanResult(
@@ -899,35 +901,6 @@ def _try_get_report_url_if_needed(
899901
logger.debug('Failed to get report URL', exc_info=e)
900902

901903

902-
def wait_for_detections_creation(
903-
cycode_client: 'ScanClient', scan_type: str, scan_id: str, expected_detections_count: int
904-
) -> None:
905-
logger.debug('Waiting for detections to be created')
906-
907-
scan_persisted_detections_count = 0
908-
polling_timeout = consts.DETECTIONS_COUNT_VERIFICATION_TIMEOUT_IN_SECONDS
909-
end_polling_time = time.time() + polling_timeout
910-
911-
while time.time() < end_polling_time:
912-
scan_persisted_detections_count = cycode_client.get_scan_detections_count(scan_type, scan_id)
913-
logger.debug(
914-
'Excepting %s detections, got %s detections (%s more; %s seconds left)',
915-
expected_detections_count,
916-
scan_persisted_detections_count,
917-
expected_detections_count - scan_persisted_detections_count,
918-
round(end_polling_time - time.time()),
919-
)
920-
if scan_persisted_detections_count == expected_detections_count:
921-
return
922-
923-
time.sleep(consts.DETECTIONS_COUNT_VERIFICATION_WAIT_INTERVAL_IN_SECONDS)
924-
925-
logger.debug('%s detections has been created', scan_persisted_detections_count)
926-
raise custom_exceptions.ScanAsyncError(
927-
f'Failed to wait for detections to be created after {polling_timeout} seconds'
928-
)
929-
930-
931904
def _map_detections_per_file(detections: List[dict]) -> List[DetectionsPerFile]:
932905
detections_per_files = {}
933906
for detection in detections:

cycode/cli/consts.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@
151151
SCAN_POLLING_WAIT_INTERVAL_IN_SECONDS = 5
152152
DEFAULT_SCAN_POLLING_TIMEOUT_IN_SECONDS = 3600
153153
SCAN_POLLING_TIMEOUT_IN_SECONDS_ENV_VAR_NAME = 'SCAN_POLLING_TIMEOUT_IN_SECONDS'
154-
DETECTIONS_COUNT_VERIFICATION_TIMEOUT_IN_SECONDS = 600
155-
DETECTIONS_COUNT_VERIFICATION_WAIT_INTERVAL_IN_SECONDS = 10
156154
DEFAULT_SCA_PRE_COMMIT_TIMEOUT_IN_SECONDS = 600
157155
SCA_PRE_COMMIT_TIMEOUT_IN_SECONDS_ENV_VAR_NAME = 'SCA_PRE_COMMIT_TIMEOUT_IN_SECONDS'
158156

cycode/cyclient/scan_client.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,6 @@ def get_scan_detections(self, scan_type: str, scan_id: str) -> List[dict]:
245245

246246
return detections
247247

248-
def get_scan_detections_count_path(self, scan_type: str) -> str:
249-
return f'{self.get_scan_detections_path(scan_type)}/count'
250-
251-
def get_scan_detections_count(self, scan_type: str, scan_id: str) -> int:
252-
response = self.scan_cycode_client.get(
253-
url_path=self.get_scan_detections_count_path(scan_type), params={'scan_id': scan_id}
254-
)
255-
return response.json().get('count', 0)
256-
257248
def commit_range_zipped_file_scan(
258249
self, scan_type: str, zip_file: InMemoryZip, scan_id: str
259250
) -> models.ZippedFileScanResult:

tests/cyclient/mocked_responses/scan_client.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,6 @@ def get_scan_details_response(url: str, scan_id: Optional[UUID] = None) -> respo
135135
return responses.Response(method=responses.GET, url=url, json=json_response, status=200)
136136

137137

138-
def get_scan_detections_count_url(scan_client: ScanClient) -> str:
139-
api_url = scan_client.scan_cycode_client.api_url
140-
service_url = scan_client.get_scan_detections_count_path()
141-
return f'{api_url}/{service_url}'
142-
143-
144-
def get_scan_detections_count_response(url: str) -> responses.Response:
145-
json_response = {'count': 1}
146-
147-
return responses.Response(method=responses.GET, url=url, json=json_response, status=200)
148-
149-
150138
def get_scan_detections_url(scan_client: ScanClient, scan_type: str) -> str:
151139
api_url = scan_client.scan_cycode_client.api_url
152140
service_url = scan_client.get_scan_detections_path(scan_type)
@@ -195,7 +183,6 @@ def mock_scan_async_responses(
195183
)
196184
responses_module.add(get_scan_details_response(get_scan_details_url(scan_id, scan_client), scan_id))
197185
responses_module.add(get_detection_rules_response(get_detection_rules_url(scan_client)))
198-
responses_module.add(get_scan_detections_count_response(get_scan_detections_count_url(scan_client)))
199186
responses_module.add(
200187
get_scan_detections_response(get_scan_detections_url(scan_client, scan_type), scan_id, zip_content_path)
201188
)

0 commit comments

Comments
 (0)