bomprobe 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bomprobe/__init__.py +69 -0
- bomprobe/__main__.py +16 -0
- bomprobe-1.1.0.dist-info/METADATA +65 -0
- bomprobe-1.1.0.dist-info/RECORD +8 -0
- bomprobe-1.1.0.dist-info/WHEEL +5 -0
- bomprobe-1.1.0.dist-info/entry_points.txt +2 -0
- bomprobe-1.1.0.dist-info/top_level.txt +2 -0
- tests/test_bomprobe.py +67 -0
bomprobe/__init__.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""bomprobe - SBOM quality auditor for CycloneDX and SPDX."""
|
|
2
|
+
|
|
3
|
+
__version__ = "1.0.0"
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import subprocess
|
|
7
|
+
import shutil
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _find_bomprobe():
|
|
12
|
+
npx = shutil.which("npx")
|
|
13
|
+
if npx:
|
|
14
|
+
return [npx, "bomprobe"]
|
|
15
|
+
bomprobe = shutil.which("bomprobe")
|
|
16
|
+
if bomprobe:
|
|
17
|
+
return [bomprobe]
|
|
18
|
+
raise FileNotFoundError(
|
|
19
|
+
"bomprobe not found. Install with: npm install -g bomprobe"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def audit(sbom_path, format="json", profile=None, threshold=None, config=None):
|
|
24
|
+
"""Run bomprobe audit on an SBOM file.
|
|
25
|
+
|
|
26
|
+
Returns parsed JSON when format='json', raw string otherwise.
|
|
27
|
+
"""
|
|
28
|
+
cmd = _find_bomprobe()
|
|
29
|
+
cmd.append(str(sbom_path))
|
|
30
|
+
cmd.extend(["--format", format])
|
|
31
|
+
if profile:
|
|
32
|
+
cmd.extend(["--profile", profile])
|
|
33
|
+
if threshold is not None:
|
|
34
|
+
cmd.extend(["--threshold", str(threshold)])
|
|
35
|
+
if config:
|
|
36
|
+
cmd.extend(["--config", str(config)])
|
|
37
|
+
|
|
38
|
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
|
39
|
+
|
|
40
|
+
if format == "json":
|
|
41
|
+
return json.loads(result.stdout)
|
|
42
|
+
return result.stdout
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def audit_dict(sbom_dict, **kwargs):
|
|
46
|
+
"""Audit an SBOM passed as a Python dict.
|
|
47
|
+
|
|
48
|
+
Writes to a temp file, runs bomprobe, cleans up.
|
|
49
|
+
"""
|
|
50
|
+
import tempfile
|
|
51
|
+
|
|
52
|
+
with tempfile.NamedTemporaryFile(
|
|
53
|
+
mode="w", suffix=".json", delete=False
|
|
54
|
+
) as f:
|
|
55
|
+
json.dump(sbom_dict, f)
|
|
56
|
+
tmp = Path(f.name)
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
return audit(tmp, **kwargs)
|
|
60
|
+
finally:
|
|
61
|
+
tmp.unlink(missing_ok=True)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def checks():
|
|
65
|
+
"""List all available checks."""
|
|
66
|
+
cmd = _find_bomprobe()
|
|
67
|
+
cmd.append("--list-checks")
|
|
68
|
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
|
|
69
|
+
return result.stdout
|
bomprobe/__main__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Allow running bomprobe as: python -m bomprobe <args>"""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import subprocess
|
|
5
|
+
from . import _find_bomprobe
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
cmd = _find_bomprobe()
|
|
10
|
+
cmd.extend(sys.argv[1:])
|
|
11
|
+
result = subprocess.run(cmd)
|
|
12
|
+
sys.exit(result.returncode)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
if __name__ == "__main__":
|
|
16
|
+
main()
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bomprobe
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: SBOM quality auditor for CycloneDX and SPDX
|
|
5
|
+
Author: Aditya S.
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/aks-builds/bomprobe
|
|
8
|
+
Project-URL: Repository, https://github.com/aks-builds/bomprobe
|
|
9
|
+
Project-URL: Issues, https://github.com/aks-builds/bomprobe/issues
|
|
10
|
+
Keywords: sbom,cyclonedx,spdx,bom,software-bill-of-materials,supply-chain,security,audit,ntia,compliance
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Security
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# bomprobe (Python wrapper)
|
|
26
|
+
|
|
27
|
+
Python wrapper for [bomprobe](https://www.npmjs.com/package/bomprobe), the SBOM quality auditor.
|
|
28
|
+
|
|
29
|
+
Requires Node.js 18+ and bomprobe installed globally (`npm install -g bomprobe`).
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install bomprobe
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## CLI usage
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
bomprobe-py sbom.json
|
|
41
|
+
bomprobe-py sbom.json --format markdown --profile ntia
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or as a module:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
python -m bomprobe sbom.json --format json
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Python API
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import bomprobe
|
|
54
|
+
|
|
55
|
+
# Audit a file
|
|
56
|
+
result = bomprobe.audit("sbom.json")
|
|
57
|
+
print(result["score"])
|
|
58
|
+
|
|
59
|
+
# Audit a dict
|
|
60
|
+
sbom = {"bomFormat": "CycloneDX", "components": [...]}
|
|
61
|
+
result = bomprobe.audit_dict(sbom, profile="ntia")
|
|
62
|
+
|
|
63
|
+
# List checks
|
|
64
|
+
print(bomprobe.checks())
|
|
65
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
bomprobe/__init__.py,sha256=M-kgj8p6QWJiem9x0d7-owI6QnUQO2v7JF5TDFF-LU4,1741
|
|
2
|
+
bomprobe/__main__.py,sha256=6NSalk6fKYW0N4b6zD3nvpEMln4H7UoZO4Ss5nSQPRQ,293
|
|
3
|
+
tests/test_bomprobe.py,sha256=oUAfnilGBtq3MemyRMiIPyM9ixWTY3mdT9ySKxC5XDo,2380
|
|
4
|
+
bomprobe-1.1.0.dist-info/METADATA,sha256=x0v3749Aka7b7JPNEDsZ7trtZNHyVr8UxEqbKRGTmZc,1759
|
|
5
|
+
bomprobe-1.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
6
|
+
bomprobe-1.1.0.dist-info/entry_points.txt,sha256=ST4aLpY1kYPBSeGF5FWLsb9zRtMXaldGOaEhbNMAo8M,55
|
|
7
|
+
bomprobe-1.1.0.dist-info/top_level.txt,sha256=xMAqm9E78PJpInDgpQz9uuagRX98YhxSZijPa4kXexs,15
|
|
8
|
+
bomprobe-1.1.0.dist-info/RECORD,,
|
tests/test_bomprobe.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Tests for the bomprobe Python wrapper."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import tempfile
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from unittest.mock import patch, MagicMock
|
|
7
|
+
import bomprobe
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_version():
|
|
11
|
+
assert bomprobe.__version__ == "1.0.0"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_find_bomprobe_with_npx():
|
|
15
|
+
with patch("shutil.which") as mock_which:
|
|
16
|
+
mock_which.side_effect = lambda x: "/usr/bin/npx" if x == "npx" else None
|
|
17
|
+
result = bomprobe._find_bomprobe()
|
|
18
|
+
assert result == ["/usr/bin/npx", "bomprobe"]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_find_bomprobe_with_global():
|
|
22
|
+
with patch("shutil.which") as mock_which:
|
|
23
|
+
mock_which.side_effect = lambda x: "/usr/bin/bomprobe" if x == "bomprobe" else None
|
|
24
|
+
result = bomprobe._find_bomprobe()
|
|
25
|
+
assert result == ["/usr/bin/bomprobe"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_find_bomprobe_not_found():
|
|
29
|
+
with patch("shutil.which", return_value=None):
|
|
30
|
+
try:
|
|
31
|
+
bomprobe._find_bomprobe()
|
|
32
|
+
assert False, "Should have raised"
|
|
33
|
+
except FileNotFoundError as e:
|
|
34
|
+
assert "npm install" in str(e)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_audit_builds_command():
|
|
38
|
+
with patch("subprocess.run") as mock_run, \
|
|
39
|
+
patch.object(bomprobe, "_find_bomprobe", return_value=["bomprobe"]):
|
|
40
|
+
mock_run.return_value = MagicMock(stdout='{"score": 85}', returncode=0)
|
|
41
|
+
result = bomprobe.audit("test.json", format="json", profile="ntia", threshold=70)
|
|
42
|
+
cmd = mock_run.call_args[0][0]
|
|
43
|
+
assert "test.json" in cmd
|
|
44
|
+
assert "--format" in cmd
|
|
45
|
+
assert "json" in cmd
|
|
46
|
+
assert "--profile" in cmd
|
|
47
|
+
assert "ntia" in cmd
|
|
48
|
+
assert "--threshold" in cmd
|
|
49
|
+
assert "70" in cmd
|
|
50
|
+
assert result == {"score": 85}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_audit_text_format():
|
|
54
|
+
with patch("subprocess.run") as mock_run, \
|
|
55
|
+
patch.object(bomprobe, "_find_bomprobe", return_value=["bomprobe"]):
|
|
56
|
+
mock_run.return_value = MagicMock(stdout="Score: 85/100", returncode=0)
|
|
57
|
+
result = bomprobe.audit("test.json", format="text")
|
|
58
|
+
assert result == "Score: 85/100"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_audit_dict():
|
|
62
|
+
with patch("subprocess.run") as mock_run, \
|
|
63
|
+
patch.object(bomprobe, "_find_bomprobe", return_value=["bomprobe"]):
|
|
64
|
+
mock_run.return_value = MagicMock(stdout='{"score": 90}', returncode=0)
|
|
65
|
+
sbom = {"bomFormat": "CycloneDX", "components": []}
|
|
66
|
+
result = bomprobe.audit_dict(sbom, format="json")
|
|
67
|
+
assert result == {"score": 90}
|