From 1c6340b3e97d3501983210c32caac1518b20db74 Mon Sep 17 00:00:00 2001 From: SafetyQuincyF Date: Thu, 31 Oct 2024 15:47:54 -0700 Subject: [PATCH] fix --- safety/auth/cli_utils.py | 16 +++++----------- safety/cli.py | 10 +++------- safety/scan/constants.py | 2 +- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/safety/auth/cli_utils.py b/safety/auth/cli_utils.py index cc0cca43..439c8811 100644 --- a/safety/auth/cli_utils.py +++ b/safety/auth/cli_utils.py @@ -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 @@ -136,13 +136,10 @@ 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. """ @@ -150,13 +147,10 @@ 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 diff --git a/safety/cli.py b/safety/cli.py index 6732c81c..6b864360 100644 --- a/safety/cli.py +++ b/safety/cli.py @@ -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, @@ -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), @@ -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 @@ -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: diff --git a/safety/scan/constants.py b/safety/scan/constants.py index 817d3aa3..7cd029f8 100644 --- a/safety/scan/constants.py +++ b/safety/scan/constants.py @@ -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]"