Skip to content

Commit ee8e36a

Browse files
committed
handle missing SBOM and package data in legal artifacts
Signed-off-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent 1b9f951 commit ee8e36a

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

socketsecurity/output.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,14 @@ def report_pass(self, diff_report: Diff) -> bool:
214214

215215
def save_sbom_file(self, diff_report: Diff, sbom_file_name: Optional[str] = None) -> None:
216216
"""Saves SBOM file if filename is provided"""
217-
if not sbom_file_name or not diff_report.sbom:
217+
if not sbom_file_name:
218218
return
219219

220-
self.write_json_file(sbom_file_name, diff_report.sbom)
220+
sbom_data = getattr(diff_report, "sbom", None)
221+
if sbom_data is None:
222+
sbom_data = []
223+
224+
self.write_json_file(sbom_file_name, sbom_data)
221225

222226
def build_summary_text(self, diff_report: Diff) -> str:
223227
"""Render the console summary text for stdout and file output."""

socketsecurity/socketcli.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@
2626

2727
load_dotenv()
2828

29+
30+
def build_license_artifact_payload(diff: Diff) -> dict:
31+
"""Build the license artifact payload from a diff, tolerating sparse scan paths."""
32+
all_packages = {}
33+
packages = getattr(diff, "packages", {}) or {}
34+
for purl in packages:
35+
package = packages[purl]
36+
output = {
37+
"id": package.id,
38+
"name": package.name,
39+
"version": package.version,
40+
"ecosystem": package.type,
41+
"direct": package.direct,
42+
"url": package.url,
43+
"license": package.license,
44+
"licenseDetails": package.licenseDetails,
45+
"licenseAttrib": package.licenseAttrib,
46+
"purl": package.purl,
47+
}
48+
all_packages[package.id] = output
49+
return all_packages
50+
2951
def cli():
3052
try:
3153
main_code()
@@ -743,22 +765,7 @@ def _is_unprocessed(c):
743765

744766
# Handle license generation
745767
if not should_skip_scan and diff.id != "NO_DIFF_RAN" and diff.id != "NO_SCAN_RAN" and config.generate_license:
746-
all_packages = {}
747-
for purl in diff.packages:
748-
package = diff.packages[purl]
749-
output = {
750-
"id": package.id,
751-
"name": package.name,
752-
"version": package.version,
753-
"ecosystem": package.type,
754-
"direct": package.direct,
755-
"url": package.url,
756-
"license": package.license,
757-
"licenseDetails": package.licenseDetails,
758-
"licenseAttrib": package.licenseAttrib,
759-
"purl": package.purl,
760-
}
761-
all_packages[package.id] = output
768+
all_packages = build_license_artifact_payload(diff)
762769
core.save_file(config.license_file_name, json.dumps(all_packages))
763770

764771
# If we forced API mode due to no supported files, behave as if --disable-blocking was set

0 commit comments

Comments
 (0)