Skip to content

Commit

Permalink
feat: Support safety v3 in safety callable
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Jan 31, 2024
1 parent 2e72586 commit 5f832b1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/duty/callables/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ def check(
if isinstance(requirements, (list, tuple, set)):
requirements = "\n".join(requirements)
packages = list(read_requirements(StringIO(cast(str, requirements))))
vulns, db_full = check(packages=packages, ignore_vulns=ignore_vulns)

# TODO: Safety 3 support, merge once support for v2 is dropped.
check_kwargs = {"packages": packages, "ignore_vulns": ignore_vulns}
try:
from safety.auth.cli_utils import build_client_session

client_session, _ = build_client_session()
check_kwargs["session"] = client_session
except ImportError:
pass

vulns, db_full = check(**check_kwargs)
remediations = calculate_remediations(vulns, db_full)
output_report = SafetyFormatter(formatter).render_vulnerabilities(
announcements=[],
Expand Down

0 comments on commit 5f832b1

Please sign in to comment.