Skip to content

Commit

Permalink
add comments, fix type, fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeurbanski1 committed Oct 25, 2023
1 parent b9e37b6 commit cd74b8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions checkov/common/bridgecrew/platform_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def set_s3_integration(self) -> None:
try:
self.skip_fixes = True # no need to run fixes on CI integration
repo_full_path, support_path, response = self.get_s3_role(self.repo_id) # type: ignore
if not repo_full_path:
if not repo_full_path: # happens if the setup fails with something other than an auth error - we continue locally
return

self.bucket, self.repo_path = repo_full_path.split("/", 1)
Expand Down Expand Up @@ -363,7 +363,7 @@ def set_s3_integration(self) -> None:
logging.error("Received an error response during authentication")
raise

def get_s3_role(self, repo_id: str) -> tuple[str | None, str | None, dict[str, Any]]:
def get_s3_role(self, repo_id: str) -> tuple[str, str, dict[str, Any]] | tuple[None, None, dict[str, Any]]:
token = self.get_auth_token()

if not self.http:
Expand All @@ -385,8 +385,8 @@ def get_s3_role(self, repo_id: str) -> tuple[str | None, str | None, dict[str, A
tries += 1
response = self._get_s3_creds(repo_id, token)
else:
logging.error(f'Checkov got an unexpected error that may be due to backend issues. The scan will continue, '
f'but results will not be sent to the platform. Please contact support for assistance.')
logging.error('Checkov got an unexpected error that may be due to backend issues. The scan will continue, '
'but results will not be sent to the platform. Please contact support for assistance.')
logging.error(f'Error from platform: {response.get("message") or response.get("Message")}')
self.s3_setup_failed = True
return None, None, response
Expand Down Expand Up @@ -661,7 +661,7 @@ def commit_repository(self, branch: str) -> str | None:
self.s3_setup_failed = True
except JSONDecodeError:
if request:
logging.warning(f"Response (status: {request.status}) of {self.integrations_api_url}: {request.data.decode('utf8')}")
logging.warning(f"Response (status: {request.status}) of {self.integrations_api_url}: {request.data.decode('utf8')}") # nosec
logging.error(f"Response of {self.integrations_api_url} is not a valid JSON", exc_info=True)
self.s3_setup_failed = True
finally:
Expand Down
3 changes: 2 additions & 1 deletion checkov/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ def run(self, banner: str = checkov_banner, tool: str = checkov_tool, source_typ
self.url = self.commit_repository()
except Exception:
logging.error('An error occurred while uploading scan results to the platform', exc_info=True)
bc_integration.s3_setup_failed = True

should_run_contributor_metrics = bc_integration.bc_api_key and self.config.repo_id and self.config.prisma_api_url
logger.debug(f"Should run contributor metrics report: {should_run_contributor_metrics}")
Expand Down Expand Up @@ -689,7 +690,7 @@ def run(self, banner: str = checkov_banner, tool: str = checkov_tool, source_typ
if bc_integration.support_flag_enabled:
if bc_integration.s3_setup_failed:
print_to_stderr = os.getenv('CKV_STDERR_DEBUG', 'FALSE').upper() == 'TRUE'
log_level = os.getenv('LOG_LEVEL', '').upper()
log_level = os.getenv('LOG_LEVEL', '')
if log_level == 'DEBUG':
print('Unable to upload support logs. However, LOG_LEVEL is already set to DEBUG, so debug logs are available locally.')
elif print_to_stderr:
Expand Down

0 comments on commit cd74b8c

Please sign in to comment.