Skip to content

Commit 73a2e92

Browse files
committed
improve UX
1 parent 9575cc9 commit 73a2e92

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

cycode/cli/commands/scan/code_scanner.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,21 @@ def set_issue_detected_by_scan_results(context: click.Context, scan_results: Lis
9898
set_issue_detected(context, any(scan_result.issue_detected for scan_result in scan_results))
9999

100100

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
103103

104104

105-
def _should_use_sync_flow(scan_type: str, sync_options: bool, scan_parameters: Optional[dict] = None) -> bool:
106-
return sync_options and scan_type == consts.SCA_SCAN_TYPE and scan_parameters.get('report') is not True
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
107116

108117

109118
def _enrich_scan_result_with_data_from_detection_rules(
@@ -156,6 +165,7 @@ def _scan_batch_thread_func(batch: List[Document]) -> Tuple[str, CliError, Local
156165

157166
scan_id = str(_generate_unique_id())
158167
scan_completed = False
168+
159169
should_use_scan_service = _should_use_scan_service(scan_type, scan_parameters)
160170
should_use_sync_flow = _should_use_sync_flow(scan_type, sync_option, scan_parameters)
161171

cycode/cyclient/cycode_client_base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ def _execute(
6262
url = self.build_full_url(self.api_url, endpoint)
6363
logger.debug(f'Executing {method.upper()} request to {url}')
6464

65+
timeout = self.timeout
66+
if 'timeout' in kwargs:
67+
timeout = kwargs['timeout']
68+
del kwargs['timeout']
69+
6570
try:
6671
headers = self.get_request_headers(headers, without_auth=without_auth)
67-
response = request(method=method, url=url, timeout=self.timeout, headers=headers, **kwargs)
72+
response = request(method=method, url=url, timeout=timeout, headers=headers, **kwargs)
6873

6974
content = 'HIDDEN' if hide_response_content_log else response.text
7075
logger.debug(f'Response {response.status_code} from {url}. Content: {content}')

cycode/cyclient/scan_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def zipped_file_scan_sync(
105105
data={'scan_parameters': json.dumps(scan_parameters)},
106106
files=files,
107107
hide_response_content_log=self._hide_response_log,
108+
timeout=60,
108109
)
109110
return models.ScanResultsSyncFlowSchema().load(response.json())
110111

0 commit comments

Comments
 (0)