mirror of
https://github.com/prowler-cloud/prowler.git
synced 2025-12-19 05:17:47 +00:00
chore(dashboard): Use Prowler CLI parser (#3722)
This commit is contained in:
2
dashboard/__init__.py
Normal file
2
dashboard/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
DASHBOARD_PORT = 11666
|
||||
DASHBOARD_ARGS = {"debug": True, "port": DASHBOARD_PORT, "use_reloader": False}
|
||||
0
dashboard/lib/arguments/__init__.py
Normal file
0
dashboard/lib/arguments/__init__.py
Normal file
5
dashboard/lib/arguments/arguments.py
Normal file
5
dashboard/lib/arguments/arguments.py
Normal 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")
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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} ..."
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user