From bcff8b972d65cc4c93116bd291da4d5268e97d78 Mon Sep 17 00:00:00 2001 From: Ilya Siamionau Date: Wed, 10 Jan 2024 16:40:04 +0100 Subject: [PATCH] CM-31107 - Fix detections endpoint suffix for SCA --- cycode/cyclient/scan_client.py | 14 ++++++++++---- tests/cyclient/mocked_responses/scan_client.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cycode/cyclient/scan_client.py b/cycode/cyclient/scan_client.py index 67291997..2b62ef62 100644 --- a/cycode/cyclient/scan_client.py +++ b/cycode/cyclient/scan_client.py @@ -171,6 +171,13 @@ def get_detection_rules( def get_scan_detections_path(self, scan_type: str) -> str: return f'{self.scan_config.get_detections_prefix()}/{self.get_detections_service_controller_path(scan_type)}' + def get_scan_detections_list_path(self, scan_type: str) -> str: + suffix = '' + if scan_type == consts.SCA_SCAN_TYPE: + suffix = '/detections' + + return f'{self.get_scan_detections_path(scan_type)}{suffix}' + def get_scan_detections(self, scan_type: str, scan_id: str) -> List[dict]: params = {'scan_id': scan_id} @@ -184,9 +191,8 @@ def get_scan_detections(self, scan_type: str, scan_id: str) -> List[dict]: params['page_size'] = page_size params['page_number'] = page_number - path = f'{self.get_scan_detections_path(scan_type)}/detections' response = self.scan_cycode_client.get( - url_path=path, + url_path=self.get_scan_detections_list_path(scan_type), params=params, hide_response_content_log=self._hide_response_log, ).json() @@ -197,12 +203,12 @@ def get_scan_detections(self, scan_type: str, scan_id: str) -> List[dict]: return detections - def get_get_scan_detections_count_path(self, scan_type: str) -> str: + def get_scan_detections_count_path(self, scan_type: str) -> str: return f'{self.get_scan_detections_path(scan_type)}/count' def get_scan_detections_count(self, scan_type: str, scan_id: str) -> int: response = self.scan_cycode_client.get( - url_path=self.get_get_scan_detections_count_path(scan_type), params={'scan_id': scan_id} + url_path=self.get_scan_detections_count_path(scan_type), params={'scan_id': scan_id} ) return response.json().get('count', 0) diff --git a/tests/cyclient/mocked_responses/scan_client.py b/tests/cyclient/mocked_responses/scan_client.py index 55528e8f..b632dc3b 100644 --- a/tests/cyclient/mocked_responses/scan_client.py +++ b/tests/cyclient/mocked_responses/scan_client.py @@ -109,7 +109,7 @@ def get_scan_details_response(url: str, scan_id: Optional[UUID] = None) -> respo def get_scan_detections_count_url(scan_client: ScanClient) -> str: api_url = scan_client.scan_cycode_client.api_url - service_url = scan_client.get_get_scan_detections_count_path() + service_url = scan_client.get_scan_detections_count_path() return f'{api_url}/{service_url}'