-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsbom_from_asdf.py
More file actions
81 lines (65 loc) · 2.39 KB
/
sbom_from_asdf.py
File metadata and controls
81 lines (65 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
"""Generate an SBOM-looking document for our asdf dependencies"""
import json
from pathlib import Path
import fire
def parse_tool_versions(file_path=".tool-versions"):
tools = []
if not Path(file_path).exists():
return tools
with open(file_path, "r") as f:
for line in f:
line = line.strip()
if not line or line.startswith("#"):
continue
parts = line.split()
if len(parts) >= 2:
tool_name = parts[0]
version = parts[1]
tools.append({"name": tool_name, "version": version})
return tools
def generate_asdf_sbom(output_file="sbom-asdf.spdx.json"):
tools = parse_tool_versions()
print(f"Found {len(tools)} ASDF-managed tools")
sbom = {
"spdxVersion": "SPDX-2.3",
"dataLicense": "CC0-1.0",
"SPDXID": "SPDXRef-DOCUMENT",
"name": "asdf-tools",
"packages": [
{
"name": tool["name"],
"SPDXID": f"SPDXRef-Package-asdf-{tool['name']}-{index}",
"versionInfo": tool["version"],
"supplier": "NOASSERTION",
"downloadLocation": "NOASSERTION",
"filesAnalyzed": False,
"sourceInfo": "ASDF-managed tool: acquired package info from /.tool-versions",
"licenseConcluded": "NOASSERTION",
"licenseDeclared": "NOASSERTION",
"copyrightText": "NOASSERTION",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceType": "purl",
"referenceLocator": f"pkg:asdf/{tool['name']}@{tool['version']}",
}
],
}
for index, tool in enumerate(tools)
],
"relationships": [
{
"spdxElementId": "SPDXRef-DOCUMENT",
"relationshipType": "DESCRIBES",
"relatedSpdxElement": f"SPDXRef-Package-asdf-{tool['name']}-{index}",
}
for index, tool in enumerate(tools)
],
}
with open(output_file, "w") as f:
json.dump(sbom, f, indent=2)
print(f"Generated SBOM with {len(tools)} ASDF-managed tools")
return output_file
if __name__ == "__main__":
fire.Fire(generate_asdf_sbom)