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

chore(CLI): start working on CLI #4067

Merged
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an __init__.py file in this folder please.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get the provider_name from typer.Typer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done

)
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