Skip to content

Commit e85aa02

Browse files
committed
scripts: syft-license-summary: Add rootfs option
Signed-off-by: Loïc Minier <[email protected]>
1 parent 0cb8913 commit e85aa02

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

.github/workflows/debos.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ jobs:
149149
- name: Generate license summary from Syft report
150150
run: |
151151
set -ux
152-
scripts/syft-license-summary.py rootfs-sbom.syft.json |
153-
tee rootfs-sbom.syft-license-summary.csv.txt
152+
scripts/syft-license-summary.py \
153+
--rootfs rootfs rootfs-sbom.syft.json |
154+
tee rootfs-sbom.syft-license-summary.csv.txt
154155
155156
- name: Stage SBOMs for publishing
156157
run: |

scripts/syft-license-summary.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
# format
88

99
import json
10-
import sys
1110
import hashlib
11+
import argparse
12+
import os
1213
from collections import defaultdict
1314

1415

@@ -32,7 +33,6 @@ def group_by_source_package(data):
3233
"copyrights": {},
3334
"source_version": None
3435
})
35-
3636
for artifact in data.get("artifacts", []):
3737
metadata = artifact.get("metadata", {})
3838
binary = metadata.get("package", "unknown")
@@ -41,40 +41,37 @@ def group_by_source_package(data):
4141
source_version = metadata.get("sourceVersion") or version
4242
grouped[source]["binaries"].add(binary)
4343
grouped[source]["source_version"] = source_version
44-
4544
for lic in artifact.get("licenses", []):
4645
grouped[source]["licenses"].add(lic.get("value", "unknown"))
47-
4846
for loc in artifact.get("locations", []):
4947
path = loc.get("path", "")
5048
if "copyright" in path:
5149
grouped[source]["copyrights"][binary] = path
52-
5350
return grouped
5451

5552

56-
def print_table(grouped):
53+
def print_table(grouped, rootfs_path):
5754
print("source,version,binaries,licenses,copyright_sha256")
5855
for source, data in grouped.items():
5956
binaries = " ".join(sorted(data["binaries"]))
6057
licenses = " ".join(sorted(data["licenses"]))
6158
version = data["source_version"] or "unknown"
62-
63-
# Compute SHA256 hashes
6459
hashes = set()
6560
for path in data["copyrights"].values():
66-
hashes.add(sha256_of_file(path.lstrip('/')))
61+
full_path = os.path.join(rootfs_path, path.lstrip('/'))
62+
hashes.add(sha256_of_file(full_path))
6763
hash_summary = " ".join(sorted(hashes))
68-
6964
print(f"{source},{version},{binaries},{licenses},{hash_summary}")
7065

7166

7267
if __name__ == "__main__":
73-
if len(sys.argv) != 2:
74-
print("Usage: syft-license-summary.py <syft-json-file>")
75-
sys.exit(1)
76-
77-
syft_file = sys.argv[1]
78-
syft_data = load_syft_json(syft_file)
68+
parser = argparse.ArgumentParser(
69+
description="Summarize Syft license data.")
70+
parser.add_argument("syft_json", help="Path to the Syft JSON file")
71+
parser.add_argument("--rootfs", required=True,
72+
help="Base path to the root filesystem")
73+
args = parser.parse_args()
74+
75+
syft_data = load_syft_json(args.syft_json)
7976
syft_grouped = group_by_source_package(syft_data)
80-
print_table(syft_grouped)
77+
print_table(syft_grouped, args.rootfs)

0 commit comments

Comments
 (0)