Skip to content

Commit 678fb1e

Browse files
author
Shane Wright
committed
note a situation that needs to get fixed in scan matching. added code to handle multiple ext refs more cleanly / non purl extrefs
1 parent a84ed4e commit 678fb1e

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

examples/client/parse_spdx.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def poll_for_upload(sbom_name):
160160
# -- operatinName: Scanning
161161
# Search for the latest scan matching our SBOM
162162
# This might be a risk for a race condition
163+
# TODO Annoyingly, the sbom_name is not necessarily precisely our document
164+
# name! Found a case where BD swaps a space for a "-" in the
165+
# document name.
163166
params = {
164167
'q': [f"name:{sbom_name}"],
165168
'sort': ["updatedAt: ASC"]
@@ -551,11 +554,20 @@ def add_to_sbom(proj_version_url, comp_ver_url):
551554
packages[matchname+matchver] = packages.get(matchname+matchver, 0) + 1
552555

553556
if package.external_references:
554-
# TODO need to handle the possiblity of:
555-
# A) multiple extrefs
556-
# B) an extref that is not a purl
557-
# -- referenceType should be "purl" - ignore others?
558-
kb_match = find_comp_in_kb(package.external_references[0].locator)
557+
foundpurl = False
558+
kb_match = None
559+
for ref in package.external_references:
560+
# There can be multiple extrefs - try to locate a purl
561+
if (ref.reference_type == "purl"):
562+
# TODO are we guaranteed only 1 purl?
563+
# what would it mean to have >1?
564+
foundpurl = True
565+
kb_match = find_comp_in_kb(ref.locator)
566+
extref = ref.locator
567+
break
568+
if not foundpurl:
569+
nopurl += 1
570+
print(f" No pURL provided for {package.name} {package.version}")
559571
if (kb_match):
560572
# Update package name and version to reflect the KB name/ver
561573
print(f" KB match for {package.name} {package.version}")

0 commit comments

Comments
 (0)