chore(dashboard): Use Prowler CLI parser (#3722)

This commit is contained in:
Pepe Fagoaga
2024-04-10 15:49:21 +02:00
committed by GitHub
parent 8758ecae97
commit c7f09df4e7
6 changed files with 31 additions and 12 deletions

2
dashboard/__init__.py Normal file
View File

@@ -0,0 +1,2 @@
DASHBOARD_PORT = 11666
DASHBOARD_ARGS = {"debug": True, "port": DASHBOARD_PORT, "use_reloader": False}

View File

View File

@@ -0,0 +1,5 @@
def init_dashboard_parser(self):
"""Init the Dashboard CLI parser"""
# If we don't set `help="Dashboard"` this won't be rendered
# We don't want the dashboard to inherit from the common providers parser since it's a different component
self.subparsers.add_parser("dashboard")

View File

@@ -53,16 +53,18 @@ from prowler.providers.common.quick_inventory import run_provider_quick_inventor
def prowler():
if len(sys.argv) > 1 and sys.argv[1] == "dashboard":
from dashboard.__main__ import dashboard
sys.exit(dashboard.run(debug=True, port=11666, use_reloader=False))
# Parse Arguments
parser = ProwlerArgumentParser()
args = parser.parse()
# Save Arguments
provider = args.provider
if provider == "dashboard":
from dashboard import DASHBOARD_ARGS
from dashboard.__main__ import dashboard
sys.exit(dashboard.run(**DASHBOARD_ARGS))
checks = args.check
excluded_checks = args.excluded_check
excluded_services = args.excluded_service

View File

@@ -2,6 +2,7 @@ import argparse
import sys
from argparse import RawTextHelpFormatter
from dashboard.lib.arguments.arguments import init_dashboard_parser
from prowler.config.config import (
available_compliance_frameworks,
check_current_version,
@@ -24,10 +25,17 @@ class ProwlerArgumentParser:
self.parser = argparse.ArgumentParser(
prog="prowler",
formatter_class=RawTextHelpFormatter,
usage="prowler [-h] [--version] {aws,azure,gcp,kubernetes,dashboard} ...",
epilog="""
Available components:
dashboard Prowler local dashboard
Available Cloud Providers:
{aws,azure,gcp,kubernetes}
aws AWS Provider
azure Azure Provider
gcp GCP Provider
kubernetes Kubernetes Provider
Available components:
dashboard Local dashboard
To see the different available options on a specific component, run:
prowler {provider|dashboard} -h|--help
@@ -40,15 +48,14 @@ Detailed documentation at https://docs.prowler.com
"--version",
"-v",
action="store_true",
help="Show Prowler version",
help="show Prowler version",
)
# Common arguments parser
self.common_providers_parser = argparse.ArgumentParser(add_help=False)
# Providers Parser
self.subparsers = self.parser.add_subparsers(
title="Available cloud providers",
dest="provider",
title="Available Cloud Providers", dest="provider", help=argparse.SUPPRESS
)
self.__init_outputs_parser__()
@@ -64,6 +71,9 @@ Detailed documentation at https://docs.prowler.com
# Init Providers Arguments
init_providers_parser(self)
# Dahboard Parser
init_dashboard_parser(self)
def parse(self, args=None) -> argparse.Namespace:
"""
parse is a wrapper to call parse_args() and do some validation
@@ -97,11 +107,11 @@ Detailed documentation at https://docs.prowler.com
# A provider is always required
if not args.provider:
self.parser.error(
"A provider is required to see its specific help options."
"A provider/component is required to see its specific help options."
)
# Only Logging Configuration
if args.only_logs or args.list_checks_json:
if args.provider != "dashboard" and (args.only_logs or args.list_checks_json):
args.no_banner = True
# Extra validation for provider arguments

View File

@@ -17,7 +17,7 @@ prowler_command = "prowler"
# capsys
# https://docs.pytest.org/en/7.1.x/how-to/capture-stdout-stderr.html
prowler_default_usage_error = (
"usage: prowler [-h] [--version] {aws,azure,gcp,kubernetes} ..."
"usage: prowler [-h] [--version] {aws,azure,gcp,kubernetes,dashboard} ..."
)