anthonyharrison / lib4sbom

Library to ingest and generate SBOMs
Apache License 2.0
16 stars 11 forks source link

Error on parsing CyclonDX #3

Closed zakrush closed 1 year ago

zakrush commented 1 year ago

Hello again. Other error it's:

>>> from lib4sbom.parser import SBOMParser
>>> test = SBOMParser()
>>> test.parse_file("test_data/cyclondx/node-alma.json")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dm/Job/R-Vision/tools/cronjobs/src/trivy/plugin/venv/lib/python3.11/site-packages/lib4sbom/parser.py", line 80, in parse_file
    ) = self.parser.parse(filename)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dm/Job/R-Vision/tools/cronjobs/src/trivy/plugin/venv/lib/python3.11/site-packages/lib4sbom/cyclonedx/cyclonedx_parser.py", line 18, in parse
    return self.parse_cyclonedx_json(sbom_file)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dm/Job/R-Vision/tools/cronjobs/src/trivy/plugin/venv/lib/python3.11/site-packages/lib4sbom/cyclonedx/cyclonedx_parser.py", line 143, in parse_cyclonedx_json
    target = id[target_id]
             ~~^^^^^^^^^^^
KeyError: 'pkg:npm/agent-base@4.3.0?file_path=usr%2Flocal%2Flib%2Fnode_modules%2Fnpm%2Fnode_modules%2Fagent-base%2Fpackage.json'

file for parsing in attachment(it's should be json)

node-alma.txt

anthonyharrison commented 1 year ago

@zakrush The issue is because there are multiple versions of the agent-base component in the SBOM. Will look in to how to handle this.