Skip to content

Commit 9d409c5

Browse files
authored
Add support for include_license_details for the streaming diff endpoint (#27)
* Add support for include_license_details for the streaming diff endpoint * Fixed readme formatting
1 parent a743ff5 commit 9d409c5

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ Delete an existing full scan.
201201
- **org_slug (str)** - The organization name
202202
- **full_scan_id (str)** - The ID of the full scan
203203

204-
fullscans.stream_diff(org_slug, before, after, preview)
205-
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
204+
fullscans.stream_diff(org_slug, before, after, preview, include_license_details)
205+
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
206206
Stream a diff between two full scans. Returns a scan diff.
207207

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

223223
fullscans.stream(org_slug, full_scan_id)
224224
""""""""""""""""""""""""""""""""""""""""

socketdev/fullscans/__init__.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,16 @@ def from_dict(cls, data: dict) -> "DiffArtifact":
486486

487487
score_data = data.get("score") or data.get("scores")
488488
score = SocketScore.from_dict(score_data) if score_data else None
489+
license_details_source = data.get("licenseDetails")
490+
if license_details_source:
491+
license_details = [LicenseDetail.from_dict(detail) for detail in license_details_source]
492+
else:
493+
license_details = []
494+
license_attrib_source = data.get("licenseAttrib")
495+
if license_attrib_source:
496+
license_attrib = [LicenseAttribution.from_dict(attrib) for attrib in license_attrib_source]
497+
else:
498+
license_attrib = []
489499

490500
return cls(
491501
diffType=DiffType(data["diffType"]),
@@ -495,7 +505,7 @@ def from_dict(cls, data: dict) -> "DiffArtifact":
495505
score=score,
496506
version=data["version"],
497507
alerts=[SocketAlert.from_dict(alert) for alert in data.get("alerts", [])],
498-
licenseDetails=[LicenseDetail.from_dict(detail) for detail in data["licenseDetails"]],
508+
licenseDetails=license_details,
499509
files=data.get("files"),
500510
license=data.get("license"),
501511
capabilities=SecurityCapabilities.from_dict(data["capabilities"]) if data.get("capabilities") else None,
@@ -510,7 +520,7 @@ def from_dict(cls, data: dict) -> "DiffArtifact":
510520
author=data.get("author", []),
511521
state=data.get("state"),
512522
error=data.get("error"),
513-
licenseAttrib=[LicenseAttribution.from_dict(attrib) for attrib in data["licenseAttrib"]]
523+
licenseAttrib=license_attrib
514524
if data.get("licenseAttrib")
515525
else None,
516526
)
@@ -766,9 +776,18 @@ def delete(self, org_slug: str, full_scan_id: str) -> dict:
766776
return {}
767777

768778
def stream_diff(
769-
self, org_slug: str, before: str, after: str, use_types: bool = False
779+
self,
780+
org_slug: str,
781+
before: str,
782+
after: str,
783+
use_types: bool = True,
784+
include_license_details: bool = False,
785+
**kwargs,
770786
) -> Union[dict, StreamDiffResponse]:
771-
path = f"orgs/{org_slug}/full-scans/diff?before={before}&after={after}"
787+
path = f"orgs/{org_slug}/full-scans/diff?before={before}&after={after}&{include_license_details}"
788+
if kwargs:
789+
for key, value in kwargs.items():
790+
path += f"&{key}={value}"
772791

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

socketdev/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.0.10"
1+
__version__ = "2.0.11"

0 commit comments

Comments
 (0)