@@ -238,6 +238,7 @@ def poll_for_sbom_complete(sbom_name, proj_version_url):
238
238
retries = MAX_RETRIES
239
239
sleep_time = SLEEP
240
240
matched_scan = False
241
+ latest_url = None
241
242
cl_url = None
242
243
243
244
# Replace any spaces in the name with a dash to match BD
@@ -248,32 +249,56 @@ def poll_for_sbom_complete(sbom_name, proj_version_url):
248
249
'q' : [f"name:{ sbom_name } " ],
249
250
'sort' : ["updatedAt: ASC" ]
250
251
}
251
- cls = bd .get_resource ('codeLocations' , params = params )
252
- for cl in cls :
252
+
253
+ while (retries ):
254
+ cls = bd .get_resource ('codeLocations' , params = params )
255
+ retries -= 1
253
256
if matched_scan :
257
+ # Exit the while()
254
258
break
255
- # Force exact match of: spdx_doc_name + " spdx/sbom"
256
- # BD appends the "spdx/sbom" string to the name.
257
- if cl ['name' ] != sbom_name + " spdx/sbom" :
258
- continue
259
-
260
- matched_scan = True
261
- cl_url = cl ['_meta' ]['href' ]
262
-
263
- for link in (cl ['_meta' ]['links' ]):
264
- # Locate the scans URL to check for status
265
- if link ['rel' ] == "latest-scan" :
266
- latest_url = link ['href' ]
259
+ # Save the CL data as we go for debugging
260
+ backupcls = []
261
+ for cl in cls :
262
+ backupcls .append (cl )
263
+ if matched_scan :
264
+ # Exit the inner for()
267
265
break
266
+ print (f"Searching scans for { sbom_name } ..." )
267
+ # Force exact match of: spdx_doc_name + " spdx/sbom"
268
+ # BD appends the "spdx/sbom" string to the name.
269
+ if cl ['name' ] != sbom_name + " spdx/sbom" :
270
+ # No match, keep searching
271
+ print (f" { cl ['name' ]} != { sbom_name } " + " spdx/sbom" )
272
+ continue
273
+
274
+ print (" Scan located" )
275
+ matched_scan = True
276
+ cl_url = cl ['_meta' ]['href' ]
277
+
278
+ print ("Checking for latest-scan info..." )
279
+ for link in (cl ['_meta' ]['links' ]):
280
+ # Locate the scans URL to check for status
281
+ if link ['rel' ] == "latest-scan" :
282
+ print (" Located latest-scan" )
283
+ latest_url = link ['href' ]
284
+ break
285
+
286
+ # We walked the list of code locations and didn't find a match
287
+ if not matched_scan :
288
+ print (f" Waiting to locate scan..." )
289
+ time .sleep (sleep_time )
268
290
269
291
if not matched_scan :
270
292
logging .error (f"No scan found for SBOM: { sbom_name } " )
293
+ print ("\n Codelocations API data:\n " )
294
+ pprint (backupcls )
271
295
sys .exit (1 )
272
296
273
297
assert latest_url , "Failed to locate latest-scan reference"
274
298
assert cl_url , "Failed to locate codelocation reference"
275
299
276
300
# Wait for scanState = SUCCESS
301
+ retries = MAX_RETRIES
277
302
while (retries ):
278
303
json_data = bd .get_json (latest_url )
279
304
retries -= 1
@@ -288,6 +313,7 @@ def poll_for_sbom_complete(sbom_name, proj_version_url):
288
313
print (f"Waiting for scan completion, currently: { json_data ['scanState' ]} " )
289
314
time .sleep (sleep_time )
290
315
316
+ assert json_data , "Failed to locate scanState data"
291
317
# If there were ZERO matches, there will never be a notification of
292
318
# BOM import success. Short-circuit the check and treat this as success.
293
319
if json_data ['matchCount' ] == 0 :
0 commit comments