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

fix/parse-server-errors #660

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
24 changes: 13 additions & 11 deletions safety/scan/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def print_detected_ecosystems_section(console: Console, file_paths: Dict[str, Se
msg = f"{ecosystem.name.replace('_', ' ').title()} detected. {brief}"

console.print(msg)



def print_fixes_section(console: Console, requirements_txt_found: bool = False, is_detailed_output: bool = False) -> None:
Expand Down Expand Up @@ -167,7 +167,7 @@ def print_summary(
Prints a concise summary of scan results including vulnerabilities, fixes, and ignored vulnerabilities.

This function summarizes the results of a security scan, displaying the number of dependencies scanned,
vulnerabilities found, suggested fixes, and the impact of those fixes. It also optionally provides a
vulnerabilities found, suggested fixes, and the impact of those fixes. It also optionally provides a
detailed breakdown of ignored vulnerabilities based on predefined policies.

Args:
Expand All @@ -190,7 +190,7 @@ def print_summary(
print_summary(console, unique_issues, 10, 2, project_model, dependencies_count=5, fixes_count=2)

"""

from ..util import pluralize

# Set the policy message based on the project source
Expand All @@ -210,7 +210,7 @@ def print_summary(

console.print(
f"[number]{fixes_count}[/number] {pluralize('fix', fixes_count)} suggested, resolving [number]{resolved_vulns_per_fix}[/number] vulnerabilities.")

if is_detailed_output:
if not ignored_vulns_data:
ignored_vulns_data = iter([])
Expand Down Expand Up @@ -253,14 +253,14 @@ def print_summary(
"of their severity or exploitability impacted the following" \
f" {pluralize('package', len(cvss_severity_ignored_pkgs))}: {', '.join(cvss_severity_ignored_pkgs)}"
)

if environment_ignored:
count = len(environment_ignored)
console.print(
f"[number]{count}[/number] {pluralize('vulnerability', count)} {pluralize('was', count)} ignored because " \
"they are inside an environment dependency."
)

if unpinned_ignored:
count = len(unpinned_ignored)
console.print(
Expand All @@ -269,7 +269,7 @@ def print_summary(
f"{', '.join(unpinned_ignored_pkgs)}"
)



def print_wait_project_verification(console: Console, project_id: str, closure: Tuple[Any, Dict[str, Any]], on_error_delay: int = 1) -> Any:
"""
Expand All @@ -293,10 +293,12 @@ def print_wait_project_verification(console: Console, project_id: str, closure:
status = f(**kwargs)
except Exception as e:
LOG.exception(f'Unable to verify the project, reason: {e}')
reason = "We are currently unable to verify the project, " \
"and it is necessary to link the scan to a specific " \
f"project. Reason: {e}"
raise SafetyException(message=reason)
reason = (
"We are currently unable to verify the project. "
f"Reason: {str(e) if str(e) else 'Unknown error'}"
)
console.print(f"[red]{reason}[/red]")
return None # Gracefully return None instead of raising

if not status:
wait_msg = f'Unable to verify "{project_id}". Starting again...'
Expand Down
10 changes: 8 additions & 2 deletions safety/scan/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def check_project(console, ctx: typer.Context, session: SafetyAuthSession,
status = print_wait_project_verification(console, data[PRJ_SLUG_KEY] if data.get(PRJ_SLUG_KEY, None) else "-",
(session.check_project, data), on_error_delay=1)

if status is None:
console.print("[yellow]Project verification skipped due to an error.[/yellow]")
return {}

return status


Expand All @@ -143,14 +147,16 @@ def verify_project(console, ctx: typer.Context, session: SafetyAuthSession,
"""

verified_prj = False

link_prj = True

while not verified_prj:
result = check_project(console, ctx, session, unverified_project, stage, git_origin, ask_project_id=not link_prj)

unverified_slug = result.get("slug")
if not result:
console.print("[red]Verification failed. Exiting...[/red]")
return # Gracefully exit if verification fails.

unverified_slug = result.get("slug")
project = result.get("project", None)
user_confirm = result.get("user_confirm", False)

Expand Down