Skip to content

Commit

Permalink
feat: api keys now work without specifing the env
Browse files Browse the repository at this point in the history
  • Loading branch information
SafetyQuincyF committed Oct 31, 2024
1 parent 9ee0b67 commit ae0b14f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 31 deletions.
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
],
"console": "integratedTerminal"
},
{
"name": "Safety Scan API Key",
"type": "debugpy",
"request": "launch",
"module": "safety",
"args": [
"--key","ADD-YOUR-KEY", "scan"
],
"console": "integratedTerminal"
},
{
"name": "Safety License",
"type": "debugpy",
Expand Down
3 changes: 0 additions & 3 deletions safety/cli.py
Original file line number Diff line number Diff line change
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
8 changes: 1 addition & 7 deletions safety/scan/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down
21 changes: 0 additions & 21 deletions safety/scan/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ae0b14f

Please sign in to comment.