Skip to content

Add support for include_license_details for the streaming diff endpoint #27

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

Merged
merged 2 commits into from
Mar 15, 2025
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
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ Delete an existing full scan.
- **org_slug (str)** - The organization name
- **full_scan_id (str)** - The ID of the full scan

fullscans.stream_diff(org_slug, before, after, preview)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
fullscans.stream_diff(org_slug, before, after, preview, include_license_details)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Stream a diff between two full scans. Returns a scan diff.

**Usage:**
Expand All @@ -218,7 +218,7 @@ Stream a diff between two full scans. Returns a scan diff.
- **org_slug (str)** - The organization name
- **before (str)** - The base full scan ID
- **after (str)** - The comparison full scan ID
- **preview (bool)** - Create a diff-scan that is not persisted. Defaults to False
- **include_license_details (bool)** - Include license details. Can greatly increase response size. Defaults to False.

fullscans.stream(org_slug, full_scan_id)
""""""""""""""""""""""""""""""""""""""""
Expand Down
27 changes: 23 additions & 4 deletions socketdev/fullscans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@ def from_dict(cls, data: dict) -> "DiffArtifact":

score_data = data.get("score") or data.get("scores")
score = SocketScore.from_dict(score_data) if score_data else None
license_details_source = data.get("licenseDetails")
if license_details_source:
license_details = [LicenseDetail.from_dict(detail) for detail in license_details_source]
else:
license_details = []
license_attrib_source = data.get("licenseAttrib")
if license_attrib_source:
license_attrib = [LicenseAttribution.from_dict(attrib) for attrib in license_attrib_source]
else:
license_attrib = []

return cls(
diffType=DiffType(data["diffType"]),
Expand All @@ -495,7 +505,7 @@ def from_dict(cls, data: dict) -> "DiffArtifact":
score=score,
version=data["version"],
alerts=[SocketAlert.from_dict(alert) for alert in data.get("alerts", [])],
licenseDetails=[LicenseDetail.from_dict(detail) for detail in data["licenseDetails"]],
licenseDetails=license_details,
files=data.get("files"),
license=data.get("license"),
capabilities=SecurityCapabilities.from_dict(data["capabilities"]) if data.get("capabilities") else None,
Expand All @@ -510,7 +520,7 @@ def from_dict(cls, data: dict) -> "DiffArtifact":
author=data.get("author", []),
state=data.get("state"),
error=data.get("error"),
licenseAttrib=[LicenseAttribution.from_dict(attrib) for attrib in data["licenseAttrib"]]
licenseAttrib=license_attrib
if data.get("licenseAttrib")
else None,
)
Expand Down Expand Up @@ -766,9 +776,18 @@ def delete(self, org_slug: str, full_scan_id: str) -> dict:
return {}

def stream_diff(
self, org_slug: str, before: str, after: str, use_types: bool = False
self,
org_slug: str,
before: str,
after: str,
use_types: bool = True,
include_license_details: bool = False,
**kwargs,
) -> Union[dict, StreamDiffResponse]:
path = f"orgs/{org_slug}/full-scans/diff?before={before}&after={after}"
path = f"orgs/{org_slug}/full-scans/diff?before={before}&after={after}&{include_license_details}"
if kwargs:
for key, value in kwargs.items():
path += f"&{key}={value}"

response = self.api.do_request(path=path, method="GET")

Expand Down
2 changes: 1 addition & 1 deletion socketdev/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.10"
__version__ = "2.0.11"
Loading