@@ -227,6 +227,7 @@ def resolve_env(self):
227
227
228
228
def resolve_ver (self ):
229
229
env = self .env or 'default'
230
+
230
231
if not self .ver_id :
231
232
for product in self .data .get ('data' , {}).get ('organization' , {}).get ('productNodes' , {}).get ('products' , []):
232
233
if product ['id' ] == self .prod_id :
@@ -237,6 +238,7 @@ def resolve_ver(self):
237
238
self .ver_id = ver ['id' ]
238
239
self .ver_status = self .vuln_status_to_status (
239
240
ver ['vulnRunStatus' ])
241
+
240
242
empty_ver = False
241
243
if not self .ver :
242
244
for product in self .data .get ('data' , {}).get ('organization' , {}).get ('productNodes' , {}).get ('products' , []):
@@ -245,11 +247,26 @@ def resolve_ver(self):
245
247
if env ['id' ] == self .env_id :
246
248
for ver in env ['versions' ]:
247
249
if ver ['id' ] == self .ver_id :
248
- self .ver = ver ['primaryComponent' ]['version' ]
250
+ if ver .get ('primaryComponent' ):
251
+ self .ver = ver ['primaryComponent' ]['version' ]
249
252
if not self .ver :
250
253
empty_ver = True
251
254
self .ver_status = self .vuln_status_to_status (
252
255
ver ['vulnRunStatus' ])
256
+
257
+
258
+ # if ver is not empty
259
+ if not empty_ver :
260
+ print ("MIDDLE COndition" )
261
+ for product in self .data .get ('data' , {}).get ('organization' , {}).get ('productNodes' , {}).get ('products' , []):
262
+ if product ['id' ] == self .prod_id :
263
+ for env in product ['environments' ]:
264
+ if env ['id' ] == self .env_id :
265
+ for ver in env ['versions' ]:
266
+ if ver ['id' ] == self .ver_id :
267
+ if ver .get ('primaryComponent' ):
268
+ self .ver = ver ['primaryComponent' ]['version' ]
269
+ self .ver_status = self .vuln_status_to_status (ver ['vulnRunStatus' ])
253
270
254
271
return (empty_ver or self .ver ) and self .ver_id
255
272
@@ -286,17 +303,13 @@ def versions(self):
286
303
return versions_node
287
304
288
305
def status (self ):
306
+ self .data = self ._fetch_context ()
289
307
self .resolve_ver ()
290
308
return self .ver_status
291
-
292
- def live_status (self ):
293
- self .resolve_ver_status ()
294
- return self .ver_status
295
-
296
309
297
310
def download (self ):
298
311
logging .debug ("Downloading SBOM for environment ID %s, sbom ID %s" ,
299
- self .env_id , self .ver_id )
312
+ self .env_id , self .ver_id )
300
313
301
314
variables = {
302
315
"envId" : self .env_id ,
@@ -310,10 +323,10 @@ def download(self):
310
323
}
311
324
312
325
response = requests .post (self .api_url ,
313
- headers = {
314
- "Authorization" : "Bearer " + self .token },
315
- json = request_data ,
316
- timeout = INTERLYNK_API_TIMEOUT )
326
+ headers = {
327
+ "Authorization" : "Bearer " + self .token },
328
+ json = request_data ,
329
+ timeout = INTERLYNK_API_TIMEOUT )
317
330
318
331
if response .status_code == 200 :
319
332
try :
@@ -325,32 +338,19 @@ def download(self):
325
338
return None
326
339
327
340
sbom = data .get ('data' , {}).get ('sbom' , {})
328
- if not sbom :
341
+ if sbom is None :
329
342
print ('No SBOM matched with the given ID' )
330
- logging .debug ("Response data: %s" , data )
343
+ logging .debug (data )
331
344
return None
332
-
333
345
b64data = sbom .get ('download' )
334
- if not b64data :
335
- print ('SBOM data is not available for download.' )
336
- logging .debug ("SBOM details: %s" , sbom )
337
- return None
338
-
339
- try :
340
- decoded_content = base64 .b64decode (b64data )
341
- logging .debug ('Completed download and decoding' )
342
- return decoded_content .decode ('utf-8' )
343
- except (TypeError , ValueError ) as e :
344
- logging .error ("Error decoding SBOM content: %s" , e )
345
- return None
346
-
346
+ decoded_content = base64 .b64decode (b64data )
347
+ logging .debug ('Completed download and decoding' )
348
+ return decoded_content .decode ('utf-8' )
347
349
except json .JSONDecodeError :
348
350
logging .error ("Failed to parse JSON response." )
349
- return None
350
351
else :
351
352
logging .error ("Failed to send GraphQL request. Status code: %s" ,
352
- response .status_code )
353
- return None
353
+ response .status_code )
354
354
355
355
def upload (self , sbom_file ):
356
356
if os .path .isfile (sbom_file ) is False :
@@ -393,21 +393,18 @@ def upload(self, sbom_file):
393
393
if response .status_code == 200 :
394
394
resp_json = response .json ()
395
395
version_id = resp_json .get ('data' , {}).get ('sbomUpload' , {}).get ('id' )
396
-
397
396
errors = resp_json .get ('data' , {}).get (
398
397
'sbomUpload' , {}).get ('errors' )
399
-
400
398
if errors :
401
399
print (f"Error uploading sbom: { errors } " )
402
400
return 1
403
-
404
401
if version_id :
405
402
self .ver_id = version_id
403
+ print ("SBOM ID successfully returned in the response: " , self .ver_id )
406
404
logging .debug ("SBOM upload response: %s" , response .text )
407
405
else :
408
406
print ("Error: SBOM ID not returned in the response." )
409
- return 0
410
-
407
+ return 1
411
408
print ('Uploaded successfully' )
412
409
logging .debug ("SBOM Uploading response: %s" , response .text )
413
410
return 0
@@ -444,60 +441,3 @@ def vuln_status_to_status(self, status):
444
441
result_dict ['labelingStatus' ] = 'COMPLETED'
445
442
result_dict ['automationStatus' ] = 'COMPLETED'
446
443
return result_dict
447
-
448
-
449
- def resolve_ver_status (self ):
450
- """
451
- Resolve version ID (ver_id) and version (ver) for the current context.
452
- """
453
- self .data = self ._fetch_context ()
454
-
455
- # ver_id is present
456
- if self .ver_id :
457
- self ._update_ver_status ()
458
- return self .ver_id
459
-
460
- # ver_id is not present
461
- self ._resolve_ver_id ()
462
-
463
- # ver is not present
464
- if not self .ver :
465
- self ._resolve_ver_value ()
466
-
467
- return self .ver_id and self .ver
468
-
469
- def _update_ver_status (self ):
470
- """Update the status of the version based on ver_id."""
471
- for product in self .data .get ('data' , {}).get ('organization' , {}).get ('productNodes' , {}).get ('products' , []):
472
- if product ['id' ] == self .prod_id :
473
- for env in product ['environments' ]:
474
- if env ['id' ] == self .env_id :
475
- for ver in env ['versions' ]:
476
- if ver ['id' ] == self .ver_id :
477
- self .ver_status = self .vuln_status_to_status (ver ['vulnRunStatus' ])
478
-
479
- def _resolve_ver_id (self ):
480
- """Resolve ver_id based on ver."""
481
- for product in self .data .get ('data' , {}).get ('organization' , {}).get ('productNodes' , {}).get ('products' , []):
482
- if product ['id' ] == self .prod_id :
483
- for env in product ['environments' ]:
484
- if env ['id' ] == self .env_id :
485
- for ver in env ['versions' ]:
486
- if ver .get ('primaryComponent' ) and ver ['primaryComponent' ].get ('version' ) == self .ver :
487
- self .ver_id = ver ['id' ]
488
- self .ver_status = self .vuln_status_to_status (ver ['vulnRunStatus' ])
489
-
490
- def _resolve_ver_value (self ):
491
- """Resolve the version value (ver) based on ver_id."""
492
- empty_ver = False
493
- for product in self .data .get ('data' , {}).get ('organization' , {}).get ('productNodes' , {}).get ('products' , []):
494
- if product ['id' ] == self .prod_id :
495
- for env in product ['environments' ]:
496
- if env ['id' ] == self .env_id :
497
- for ver in env ['versions' ]:
498
- if ver ['id' ] == self .ver_id :
499
- if ver .get ('primaryComponent' ):
500
- self .ver = ver ['primaryComponent' ].get ('version' )
501
- if not self .ver :
502
- empty_ver = True
503
- return empty_ver
0 commit comments