Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SafetyQuincyF committed Oct 31, 2024
1 parent cc676e5 commit 1c6340b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
16 changes: 5 additions & 11 deletions safety/auth/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from safety.auth.models import Organization, Auth
from safety.auth.utils import S3PresignedAdapter, SafetyAuthSession, get_keys, is_email_verified
from safety.constants import REQUEST_TIMEOUT
from safety.scan.constants import CLI_KEY_HELP, CLI_PROXY_HOST_HELP, CLI_PROXY_PORT_HELP, CLI_PROXY_PROTOCOL_HELP, CLI_STAGE_HELP
from safety.scan.constants import CLI_HEADLESS_AUTH_HELP, CLI_KEY_HELP, CLI_PROXY_HOST_HELP, CLI_PROXY_PORT_HELP, CLI_PROXY_PROTOCOL_HELP, CLI_STAGE_HELP
from safety.scan.util import Stage
from safety.util import DependentOption, SafetyContext, get_proxy_dict

Expand Down Expand Up @@ -136,27 +136,21 @@ def proxy_options(func: Callable) -> Callable:

return func

def auth_options(stage: bool = True) -> Callable:
def auth_options() -> Callable:
"""
Decorator that defines authentication options for Click commands.
Args:
stage (bool): Whether to include the stage option.
Returns:
Callable: The decorator function.
"""
def decorator(func: Callable) -> Callable:

func = click.option("--key", default=None, envvar="SAFETY_API_KEY",
help=CLI_KEY_HELP)(func)

if stage:
func = click.option("--stage", default=None, envvar="SAFETY_STAGE",
help=CLI_STAGE_HELP)(func)

func = click.option("--headless",
help=CLI_HEADLESS_AUTH_HELP)(func)
return func

return decorator


Expand Down
10 changes: 3 additions & 7 deletions safety/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def print_deprecation_message(

@cli.command(cls=SafetyCLILegacyCommand, utility_command=True, help=CLI_CHECK_COMMAND_HELP)
@proxy_options
@auth_options(stage=False)
@auth_options()
@click.option("--db", default="",
help="Path to a local or remote vulnerability database. Default: empty")
@click.option("--full-report/--short-report", default=False, cls=MutuallyExclusiveOption,
Expand Down Expand Up @@ -467,7 +467,7 @@ def inner(ctx, *args, **kwargs):

@cli.command(cls=SafetyCLILegacyCommand, utility_command=True, help=CLI_LICENSES_COMMAND_HELP)
@proxy_options
@auth_options(stage=False)
@auth_options()
@click.option("--db", default="",
help="Path to a local license database. Default: empty")
@click.option('--output', "-o", type=click.Choice(['screen', 'text', 'json', 'bare'], case_sensitive=False),
Expand Down Expand Up @@ -644,9 +644,6 @@ def fail_validation(e):
cls=DependentOption,
required_options=['organization_id'],
help=CLI_CONFIGURE_ORGANIZATION_NAME)
@click.option("--stage", "-stg", multiple=False, default=Stage.development.value,
type=click.Choice([stage.value for stage in Stage]),
help="The project development stage to be tied to the current device.")
@click.option("--save-to-system/--save-to-user", default=False, is_flag=True,
help=CLI_CONFIGURE_SAVE_TO_SYSTEM)
@click.pass_context
Expand Down Expand Up @@ -706,8 +703,7 @@ def configure(ctx, proxy_protocol, proxy_host, proxy_port, proxy_timeout,
for key, value in proxy_config.items():
config.set(PROXY_SECTION_NAME, key, value)

if stage:
config['host'] = {'stage': "development" if stage == "dev" else stage}


try:
with open(CONFIG_FILE, 'w') as configfile:
Expand Down
2 changes: 1 addition & 1 deletion safety/scan/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"[nhc]For development stage scans unset the API key and authenticate using [bold]safety auth[/bold].[/nhc]\n\n" \
"[nhc]Tip: the API key can also be set using the environment variable: SAFETY_API_KEY[/nhc]\n\n"\
"[bold]Example: safety --key API_KEY --stage cicd scan[/bold]"

CLI_HEADLESS_AUTH_HELP = "For headless authentication, you will receive a URL to paste into an external browser, \n\n [bold]Example: safety auth login --headless[/bold]\n\n"
CLI_STAGE_HELP = "Assign a development lifecycle stage to your scan (default: development).\n\n" \
"[nhc]This labels the scan and its findings in Safety Platform with this stage.[/nhc]\n\n" \
"[bold]Example: safety --stage production scan[/bold]"
Expand Down

0 comments on commit 1c6340b

Please sign in to comment.