Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(general): add flag for summary position #3497

Merged
merged 4 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion checkov/common/output/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def print_console(
created_baseline_path: str | None = None,
baseline: Baseline | None = None,
use_bc_ids: bool = False,
summary_position: str = 'top'
) -> str:
summary = self.get_summary()
output_data = colored(f"{self.check_type} scan results:\n", "blue")
Expand All @@ -193,7 +194,8 @@ def print_console(
message = f"\nFailed checks: {summary['failed']}, Skipped checks: {summary['skipped']}\n\n"
else:
message = f"\nPassed checks: {summary['passed']}, Failed checks: {summary['failed']}, Skipped checks: {summary['skipped']}\n\n"
output_data += colored(message, "cyan")
if summary_position == 'top':
output_data += colored(message, "cyan")
# output for vulnerabilities is different
if self.check_type in (CheckType.SCA_PACKAGE, CheckType.SCA_IMAGE):
if self.failed_checks or self.skipped_checks:
Expand Down Expand Up @@ -222,6 +224,8 @@ def print_console(
f"Baseline analysis report using {baseline.path} - only new failed checks with respect to the baseline are reported",
"blue",
)
if summary_position == 'bottom':
output_data += colored(message, "cyan")
return output_data

@staticmethod
Expand Down
3 changes: 3 additions & 0 deletions checkov/common/runners/runner_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

CHECK_BLOCK_TYPES = frozenset(["resource", "data", "provider", "module"])
OUTPUT_CHOICES = ["cli", "cyclonedx", "json", "junitxml", "github_failed_only", "sarif", "csv"]
SUMMARY_POSITIONS = frozenset(['top', 'bottom'])
OUTPUT_DELIMITER = "\n--- OUTPUT DELIMITER ---\n"


Expand Down Expand Up @@ -249,6 +250,7 @@ def print_reports(
created_baseline_path=created_baseline_path,
baseline=baseline,
use_bc_ids=config.output_bc_ids,
summary_position=config.summary_position
)
print(cli_output)
# Remove colors from the cli output
Expand All @@ -269,6 +271,7 @@ def print_reports(
created_baseline_path=created_baseline_path,
baseline=baseline,
use_bc_ids=config.output_bc_ids,
summary_position=config.summary_position
))
master_report.failed_checks += report.failed_checks
master_report.skipped_checks += report.skipped_checks
Expand Down
5 changes: 4 additions & 1 deletion checkov/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from checkov.common.images.image_referencer import enable_image_referencer
from checkov.common.output.baseline import Baseline
from checkov.common.bridgecrew.check_type import CheckType
from checkov.common.runners.runner_registry import RunnerRegistry, OUTPUT_CHOICES
from checkov.common.runners.runner_registry import RunnerRegistry, OUTPUT_CHOICES, SUMMARY_POSITIONS
from checkov.common.util import prompt
from checkov.common.util.banner import banner as checkov_banner
from checkov.common.util.config_utils import get_default_config_paths
Expand Down Expand Up @@ -574,6 +574,9 @@ def add_parser_args(parser: ArgumentParser) -> None:
env_var='CKV_SECRETS_SCAN_BLACK_LIST',
action='append',
help='black file list to filter out from the secret scanner')
parser.add('--summary-position', default='top', choices=SUMMARY_POSITIONS,
help='Chose whether the summary will be appended on top (before the checks results) or on bottom '
'(after check results), default is on top.')


def get_external_checks_dir(config: Any) -> Any:
Expand Down
1 change: 1 addition & 0 deletions docs/2.Basics/CLI Command Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ nav_order: 2
| `--output-baseline-as-skipped` | Output checks that are skipped due to baseline file presence |
| `--skip-cve-package SKIP_CVE_PACKAGE` | Filter scan to run on all packages but a specific package identifier (deny list), You can specify this argument multiple times to skip multiple packages |
| `--policy-metadata-filter POLICY_METADATA_FILTER` | Comma separated key:value string to filter policies based on Prisma Cloud policy metadata. See https://prisma.pan.dev/api/cloud/cspm/policy#operation/get-policy-filters-and-options for information on allowed filters. Format: policy.label=test,cloud.type=aws |
| `--summary-position` | Chose whether the summary will be appended on top (before the checks results) or on bottom (after check results), default is on top. |