mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 14:55:00 +00:00
feat(quiet): Add -q option. (#1211)
Co-authored-by: sergargar <sergio@verica.io>
This commit is contained in:
@@ -3,6 +3,7 @@ import pkgutil
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
|
|
||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
|
|
||||||
from config.config import groups_file
|
from config.config import groups_file
|
||||||
@@ -158,11 +159,22 @@ def recover_modules_from_provider(provider: str, service: str = None) -> list:
|
|||||||
return modules
|
return modules
|
||||||
|
|
||||||
|
|
||||||
|
def set_output_options(quiet):
|
||||||
|
global output_options
|
||||||
|
output_options = Output_From_Options(
|
||||||
|
is_quiet=quiet
|
||||||
|
# set input options here
|
||||||
|
)
|
||||||
|
return output_options
|
||||||
|
|
||||||
|
|
||||||
def run_check(check):
|
def run_check(check):
|
||||||
print(f"\nCheck Name: {check.CheckName} - {Fore.MAGENTA}{check.ServiceName}{Fore.YELLOW}[{check.Severity}]{Style.RESET_ALL}")
|
print(
|
||||||
|
f"\nCheck Name: {check.CheckName} - {Fore.MAGENTA}{check.ServiceName}{Fore.YELLOW}[{check.Severity}]{Style.RESET_ALL}"
|
||||||
|
)
|
||||||
logger.debug(f"Executing check: {check.CheckName}")
|
logger.debug(f"Executing check: {check.CheckName}")
|
||||||
findings = check.execute()
|
findings = check.execute()
|
||||||
report(findings)
|
report(findings, output_options)
|
||||||
|
|
||||||
|
|
||||||
def import_check(check_path: str) -> ModuleType:
|
def import_check(check_path: str) -> ModuleType:
|
||||||
@@ -182,6 +194,11 @@ class Check_Report:
|
|||||||
self.result_extended = ""
|
self.result_extended = ""
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Output_From_Options:
|
||||||
|
is_quiet: bool
|
||||||
|
|
||||||
|
|
||||||
class Check(ABC):
|
class Check(ABC):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
|
|
||||||
|
|
||||||
def report(check_findings):
|
def report(check_findings, output_options):
|
||||||
check_findings.sort(key=lambda x: x.region)
|
check_findings.sort(key=lambda x: x.region)
|
||||||
for finding in check_findings:
|
for finding in check_findings:
|
||||||
color = set_report_color(finding.status)
|
color = set_report_color(finding.status)
|
||||||
print(
|
if output_options.is_quiet and "FAIL" in finding.status:
|
||||||
f"{color}{finding.status}{Style.RESET_ALL} {finding.region}: {finding.result_extended}"
|
print(
|
||||||
)
|
f"{color}{finding.status}{Style.RESET_ALL} {finding.region}: {finding.result_extended}"
|
||||||
|
)
|
||||||
|
elif not output_options.is_quiet:
|
||||||
|
print(
|
||||||
|
f"{color}{finding.status}{Style.RESET_ALL} {finding.region}: {finding.result_extended}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def set_report_color(status):
|
def set_report_color(status):
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from lib.check.check import (
|
|||||||
import_check,
|
import_check,
|
||||||
load_checks_to_execute,
|
load_checks_to_execute,
|
||||||
run_check,
|
run_check,
|
||||||
|
set_output_options,
|
||||||
)
|
)
|
||||||
from lib.logger import logger, logging_levels
|
from lib.logger import logger, logging_levels
|
||||||
from providers.aws.aws_provider import provider_set_session
|
from providers.aws.aws_provider import provider_set_session
|
||||||
@@ -40,6 +41,9 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v", "--version", action="store_true", help="Show Prowler version"
|
"-v", "--version", action="store_true", help="Show Prowler version"
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-q", "--quiet", action="store_true", help="Show only Prowler failed findings"
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--log-level",
|
"--log-level",
|
||||||
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
||||||
@@ -119,13 +123,16 @@ if __name__ == "__main__":
|
|||||||
if args.no_banner:
|
if args.no_banner:
|
||||||
print_banner()
|
print_banner()
|
||||||
|
|
||||||
|
# Setting output options
|
||||||
|
set_output_options(args.quiet)
|
||||||
|
|
||||||
# Set global session
|
# Set global session
|
||||||
provider_set_session(
|
provider_set_session(
|
||||||
args.profile,
|
args.profile,
|
||||||
args.role,
|
args.role,
|
||||||
args.session_duration,
|
args.session_duration,
|
||||||
args.external_id,
|
args.external_id,
|
||||||
args.filter_region,
|
args.filter_region
|
||||||
)
|
)
|
||||||
|
|
||||||
# Load checks to execute
|
# Load checks to execute
|
||||||
|
|||||||
Reference in New Issue
Block a user