@@ -153,15 +153,15 @@ def poll_for_upload(sbom_name):
153
153
sleep_time = 10
154
154
matched_scan = False
155
155
156
+ # Replace any spaces in the name with a dash to match BD
157
+ sbom_name = sbom_name .replace (' ' , '-' )
158
+
156
159
# TODO also check for api/projects/<ver>/versions/<ver>/codelocations
157
160
# -- status - operationNameCode = ServerScanning, operationName=Scanning, status
158
161
# -- should be COMPLETED, not IN_PROGRESS
159
162
# -- operatinName: Scanning
160
163
# Search for the latest scan matching our SBOM
161
164
# This might be a risk for a race condition
162
- # TODO Annoyingly, the sbom_name is not necessarily precisely our document
163
- # name! Found a case where BD swaps a space for a "-" in the
164
- # document name. Need to be more general in the match.
165
165
params = {
166
166
'q' : [f"name:{ sbom_name } " ],
167
167
'sort' : ["updatedAt: ASC" ]
@@ -237,7 +237,7 @@ def upload_sbom_file(filename, project, version):
237
237
try :
238
238
pprint (response .json ()['errorMessage' ])
239
239
except :
240
- logging .error (f"Status code { response .status_code } " )
240
+ logging .error (f"Status code: { response .status_code } " )
241
241
sys .exit (1 )
242
242
243
243
# Lookup the given pURL in the BD KB.
@@ -282,6 +282,9 @@ def find_comp_in_bom(compname, compver, projver):
282
282
if comp ['componentName' ].lower () != compname .lower ():
283
283
# The BD API search is inexact. Force our match to be precise.
284
284
continue
285
+ if compver == "UNKNOWN" :
286
+ # We did not have a version specified in the first place
287
+ return True
285
288
# Check component name + version name
286
289
try :
287
290
if comp ['componentVersionName' ].lower () == compver .lower ():
@@ -370,15 +373,10 @@ def create_cust_comp(name, version, license):
370
373
}
371
374
response = bd .session .post ("api/components" , json = data )
372
375
logging .debug (response )
373
- if response .status_code == 412 :
374
- # Shouldn't be possible. We checked for existence earlier.
375
- logging .error (f"Component { name } already exists" )
376
- sys .exit (1 )
377
-
378
376
if response .status_code != 201 :
379
377
# Shouldn't be possible. We checked for existence earlier.
380
378
logging .error (response .json ()['errors' ][0 ]['errorMessage' ])
381
- logging .error (f"Status code { response .status_code } " )
379
+ logging .error (f"Status code: { response .status_code } " )
382
380
sys .exit (1 )
383
381
384
382
# Should be guaranteed 1 version because we just created it!
@@ -427,7 +425,7 @@ def add_to_sbom(proj_version_url, comp_ver_url):
427
425
response = bd .session .post (proj_version_url + "/components" , json = data )
428
426
if (response .status_code != 200 ):
429
427
logging .error (response .json ()['errors' ][0 ]['errorMessage' ])
430
- logging .error (f"Status code { response .status_code } " )
428
+ logging .error (f"Status code: { response .status_code } " )
431
429
sys .exit (1 )
432
430
433
431
@@ -521,9 +519,14 @@ def add_to_sbom(proj_version_url, comp_ver_url):
521
519
# We hope we'll have an external reference (pURL), but we might not.
522
520
extref = None
523
521
purlmatch = False
522
+ # matchname/matchver can change, depending on the KB lookup step.
523
+ # These are stored separately so that we have the original names available.
524
524
matchname = package .name
525
+ if package .version is None :
526
+ # Default in case one is not specified in SPDX
527
+ package .version = "UNKNOWN"
525
528
matchver = package .version
526
- print (f"Processing SPDX package: { matchname } { matchver } ...." )
529
+ print (f"Processing SPDX package: { matchname } version: { matchver } ...." )
527
530
# Tracking unique package name + version from spdx file
528
531
packages [matchname + matchver ] = packages .get (matchname + matchver , 0 ) + 1
529
532
0 commit comments