Skip to content

Commit

Permalink
feat(arm): unsupported module soft fail (#6775)
Browse files Browse the repository at this point in the history
* soft fail in case the scanner has unsupported module

* fix lint

---------

Co-authored-by: adam varsano <[email protected]>
  • Loading branch information
AdamDev and adam varsano authored Oct 15, 2024
1 parent 4a3e99a commit 7458179
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion checkov/common/bridgecrew/platform_errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import List


class PlatformConnectionError(Exception):
def __init__(self, message: str) -> None:
self.message = message
Expand All @@ -16,8 +19,9 @@ def __str__(self) -> str:


class ModuleNotEnabledError(Exception):
def __init__(self, message: str) -> None:
def __init__(self, message: str, unsupported_frameworks: List[str]) -> None:
self.message = message
self.unsupported_frameworks = unsupported_frameworks

def __str__(self) -> str:
return f"ModuleNotEnabledError: {self.message}"
7 changes: 4 additions & 3 deletions checkov/common/runners/runner_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def run(
collect_skip_comments=collect_skip_comments)]
else:
# This is the only runner, so raise a clear indication of failure
raise ModuleNotEnabledError(f'The framework "{runner_check_type}" is part of the "{self.licensing_integration.get_subscription_for_runner(runner_check_type).name}" module, which is not enabled in the platform')
raise ModuleNotEnabledError(f'The framework "{runner_check_type}" is part of the "{self.licensing_integration.get_subscription_for_runner(runner_check_type).name}" module, which is not enabled in the platform',
unsupported_frameworks=[runner_check_type])
else:
valid_runners = []
invalid_runners = []
Expand All @@ -150,11 +151,11 @@ def run(
# if some frameworks are disabled and the user used --framework, log a warning so they see it
# if some frameworks are disabled and the user did not use --framework, then log at a lower level so that we have it for troubleshooting
if not valid_runners:
check_types = [runner.check_type for runner in self.runners]
runners_categories = os.linesep.join([f'{runner.check_type}: {self.licensing_integration.get_subscription_for_runner(runner.check_type).name}' for runner in invalid_runners])
error_message = f'All the frameworks are disabled because they are not enabled in the platform. ' \
f'You must subscribe to one or more of the categories below to get results for these frameworks.{os.linesep}{runners_categories}'
logging.error(error_message)
raise ModuleNotEnabledError(error_message)
raise ModuleNotEnabledError(error_message, unsupported_frameworks=check_types)
elif invalid_runners:
for runner in invalid_runners:
level = logging.INFO
Expand Down
4 changes: 2 additions & 2 deletions checkov/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,8 @@ def run(self, banner: str = checkov_banner, tool: str = default_tool, source_typ
print(f"{banner}")
return None
except ModuleNotEnabledError as m:
logging.error(m)
self.exit_run()
if all(framework in self.config.framework for framework in m.unsupported_frameworks):
logging.warning(m)
return None
except PlatformConnectionError:
# we don't want to print all of these stack traces in normal output, as these could be user error
Expand Down

0 comments on commit 7458179

Please sign in to comment.