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

feat: api keys now work without specifying the env #630

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-API-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
2 changes: 1 addition & 1 deletion safety/scan/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
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
Loading