Skip to content

Commit

Permalink
chore(CLI): start working on CLI (#4067)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrooot committed May 24, 2024
1 parent 3aa2832 commit e9670d7
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
Empty file added cli/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions cli/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# CLI
To show the banner, use:
`python cli/cli.py banner`
## Listing
List services by provider.
`python cli/cli.py <provider> list-services`
63 changes: 63 additions & 0 deletions cli/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import typer

from prowler.lib.banner import print_banner
from prowler.lib.check.check import (
list_fixers,
list_services,
print_fixers,
print_services,
)

app = typer.Typer()
aws = typer.Typer(name="aws")
azure = typer.Typer(name="azure")
gcp = typer.Typer(name="gcp")
kubernetes = typer.Typer(name="kubernetes")

app.add_typer(aws, name="aws")
app.add_typer(azure, name="azure")
app.add_typer(gcp, name="gcp")
app.add_typer(kubernetes, name="kubernetes")


def list_resources(provider: str, resource_type: str):
if resource_type == "services":
print_services(list_services(provider))
elif resource_type == "fixers":
print_fixers(list_fixers(provider))


def create_list_commands(provider_typer: typer.Typer):
provider_name = provider_typer.info.name

@provider_typer.command(
"list-services",
help=f"List the {provider_name} services that are supported by Prowler.",
)
def list_services_command():
list_resources(provider_name, "services")

@provider_typer.command(
"list-fixers",
help=f"List the {provider_name} fixers that are supported by Prowler.",
)
def list_fixers_command():
list_resources(provider_name, "fixers")


create_list_commands(aws)
create_list_commands(azure)
create_list_commands(gcp)
create_list_commands(kubernetes)


@app.command("banner", help="Prints the banner of the tool.")
def banner(show: bool = True):
if show:
print_banner(show)
else:
print("Banner is not shown.")


if __name__ == "__main__":
app()
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ slack-sdk = "3.27.2"
tabulate = "0.9.0"
tzlocal = "5.2"

[tool.poetry.group.cli]
optional = true

[tool.poetry.group.cli.dependencies]
typer = "0.12.3"

[tool.poetry.group.dev.dependencies]
bandit = "1.7.8"
black = "24.4.2"
Expand Down

0 comments on commit e9670d7

Please sign in to comment.