Skip to content

Commit d7e8f4b

Browse files
authored
Workaround the unsupported new tools format in cyclonedx #1171 (#1172)
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent ef4a41e commit d7e8f4b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

scanpipe/pipes/cyclonedx.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ def get_components(bom):
178178
return list(bom._get_all_components())
179179

180180

181+
def delete_tools(cyclonedx_document_json):
182+
"""
183+
Remove the ``tools`` section, if defined, from the SBOM as it can
184+
be in the way of loading a SBOM that is valid regarding the spec, but fails the
185+
deserialization.
186+
187+
The ``metadata.tools`` as an array was deprecated in 1.5 and replaced by an
188+
object structure where you can define a list of ``components`` and ``services``.
189+
190+
The new structure is not yet supported by the cyclonedx-python-lib, neither for
191+
serialization (output) nor deserialization (input).
192+
193+
The tools are not used anyway in the context of loading the SBOM component data as
194+
packages.
195+
"""
196+
if "tools" in cyclonedx_document_json.get("metadata", {}):
197+
del cyclonedx_document_json["metadata"]["tools"]
198+
199+
return cyclonedx_document_json
200+
201+
181202
def resolve_cyclonedx_packages(input_location):
182203
"""Resolve the packages from the `input_location` CycloneDX document file."""
183204
input_path = Path(input_location)
@@ -194,6 +215,7 @@ def resolve_cyclonedx_packages(input_location):
194215
f'CycloneDX document "{input_path.name}" is not valid:\n{errors}'
195216
)
196217
raise ValueError(error_msg)
218+
cyclonedx_document = delete_tools(cyclonedx_document)
197219
cyclonedx_bom = Bom.from_json(data=cyclonedx_document)
198220

199221
else:

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ install_requires =
9090
# Profiling
9191
pyinstrument==4.6.2
9292
# CycloneDX
93-
cyclonedx-python-lib==7.1.0
93+
cyclonedx-python-lib==7.3.0
9494
jsonschema==4.21.1
9595
# Font Awesome
9696
fontawesomefree==6.5.1
@@ -115,7 +115,7 @@ dev =
115115
# Debug
116116
django-debug-toolbar==4.3.0
117117
# Documentation
118-
Sphinx==7.2.6
118+
Sphinx==7.3.7
119119
sphinx-rtd-theme==2.0.0
120120
sphinx-rtd-dark-mode==1.3.0
121121
sphinxcontrib-django==2.5

0 commit comments

Comments
 (0)