From 89863037ef21457354707bc5a1943a893970d3f0 Mon Sep 17 00:00:00 2001 From: SafetyQuincyF Date: Wed, 30 Oct 2024 17:47:52 -0700 Subject: [PATCH] feat: api keys now work without specifying the env --- .vscode/launch.json | 10 ++++++++++ safety/cli.py | 3 --- safety/scan/constants.py | 2 +- safety/scan/decorators.py | 8 +------- safety/scan/validators.py | 21 --------------------- 5 files changed, 12 insertions(+), 32 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c3d91a7c..9b39f4d8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -32,6 +32,16 @@ ], "console": "integratedTerminal" }, + { + "name": "Safety Scan API Key", + "type": "debugpy", + "request": "launch", + "module": "safety", + "args": [ + "--key","ADD-YOUR-API-KEY", "scan" + ], + "console": "integratedTerminal" + }, { "name": "Safety License", "type": "debugpy", diff --git a/safety/cli.py b/safety/cli.py index 6732c81c..36099f3b 100644 --- a/safety/cli.py +++ b/safety/cli.py @@ -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 diff --git a/safety/scan/constants.py b/safety/scan/constants.py index 9cddb67a..f07b5aaa 100644 --- a/safety/scan/constants.py +++ b/safety/scan/constants.py @@ -60,7 +60,7 @@ CLI_KEY_HELP = "The API key required for cicd stage or production stage scans.\n\n" \ "[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]" +"[bold]Example: safety --key API_KEY scan[/bold]" 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" \ diff --git a/safety/scan/decorators.py b/safety/scan/decorators.py index 29c9e7c9..72d7e4e1 100644 --- a/safety/scan/decorators.py +++ b/safety/scan/decorators.py @@ -21,7 +21,7 @@ from safety.scan.render import print_announcements, print_header, print_project_info, print_wait_policy_download from safety.scan.util import GIT -from safety.scan.validators import fail_if_not_allowed_stage, verify_project +from safety.scan.validators import verify_project from safety.util import build_telemetry_data, pluralize from safety_schemas.models import MetadataModel, ScanType, ReportSchemaVersion, \ PolicySource @@ -70,8 +70,6 @@ def inner(ctx, policy_file_path: Optional[Path], target: Path, upload_request_id = kwargs.pop("upload_request_id", None) - fail_if_not_allowed_stage(ctx=ctx) - # Run the initialize if it was not fired by a system-scan if not upload_request_id: initialize_scan(ctx, console) @@ -208,10 +206,6 @@ def inner(ctx, policy_file_path: Optional[Path], targets: List[Path], console.print() print_header(console=console, targets=targets, is_system_scan=True) - wait_msg = "Checking authentication and system scan policies" - - with console.status(wait_msg, spinner=DEFAULT_SPINNER): - fail_if_not_allowed_stage(ctx=ctx) if not policy_file_path: if SYSTEM_POLICY_FILE.exists(): diff --git a/safety/scan/validators.py b/safety/scan/validators.py index 0bfb81ea..a118b47e 100644 --- a/safety/scan/validators.py +++ b/safety/scan/validators.py @@ -57,27 +57,6 @@ def output_callback(output: ScanOutput) -> str: return output.value -def fail_if_not_allowed_stage(ctx: typer.Context): - """ - Fail the command if the authentication type is not allowed in the current stage. - - Args: - ctx (typer.Context): The context of the Typer command. - """ - if ctx.resilient_parsing: - return - - stage = ctx.obj.auth.stage - auth_type: AuthenticationType = ctx.obj.auth.client.get_authentication_type() - - if os.getenv("SAFETY_DB_DIR"): - return - - if not auth_type.is_allowed_in(stage): - raise typer.BadParameter(f"'{auth_type.value}' auth type isn't allowed with " \ - f"the '{stage}' stage.") - - def save_verified_project(ctx: typer.Context, slug: str, name: Optional[str], project_path: Path, url_path: Optional[str]): """ Save the verified project information to the context and project info file.