84
84
"""
85
85
86
86
QUERY_SBOM_DOWNLOAD = """
87
- query downloadSbom($envId: Uuid!, $sbomId: Uuid!, $includeVulns: Boolean) {
88
- sbom(projectId: $envId, sbomId: $sbomId) {
87
+ query downloadSbom(
88
+ $projectId: Uuid!,
89
+ $sbomId: Uuid!,
90
+ $includeVulns: Boolean,
91
+ $spec: SbomSpec,
92
+ $original: Boolean,
93
+ $package: Boolean,
94
+ $lite: Boolean,
95
+ $excludeParts: Boolean
96
+ ) {
97
+ sbom(projectId: $projectId, sbomId: $sbomId) {
89
98
download(
90
99
sbomId: $sbomId
91
100
includeVulns: $includeVulns
92
- )
101
+ spec: $spec
102
+ original: $original
103
+ dontPackageSbom: $package
104
+ lite: $lite
105
+ excludeParts: $excludeParts
106
+ ) {
107
+ content
108
+ contentType
109
+ filename
110
+ __typename
111
+ }
93
112
__typename
94
113
}
95
114
}
@@ -311,11 +330,16 @@ def download(self):
311
330
self .env_id , self .ver_id )
312
331
313
332
variables = {
314
- "envId " : self .env_id ,
333
+ "projectId " : self .env_id ,
315
334
"sbomId" : self .ver_id ,
316
- "includeVulns" : False
335
+ "includeVulns" : False ,
336
+ "spec" : "CycloneDX" ,
337
+ "original" : False ,
338
+ "package" : False ,
339
+ "lite" : False ,
340
+ "excludeParts" : True
317
341
}
318
-
342
+ logging . debug ( "Variables for request: %s" , variables )
319
343
request_data = {
320
344
"query" : QUERY_SBOM_DOWNLOAD ,
321
345
"variables" : variables ,
@@ -341,10 +365,14 @@ def download(self):
341
365
print ('No SBOM matched with the given ID' )
342
366
logging .debug (data )
343
367
return None
344
- b64data = sbom .get ('download' )
345
- decoded_content = base64 .b64decode (b64data )
368
+ download_data = sbom .get ('download' , {})
369
+ b64data = download_data .get ('content' )
370
+ if not b64data :
371
+ logging .error ("No content found in the download response." )
372
+ return None
373
+ decoded_content = base64 .b64decode (b64data ).decode ('utf-8' )
346
374
logging .debug ('Completed download and decoding' )
347
- return decoded_content . decode ( 'utf-8' )
375
+ return decoded_content
348
376
except json .JSONDecodeError :
349
377
logging .error ("Failed to parse JSON response." )
350
378
else :
@@ -392,6 +420,7 @@ def upload(self, sbom_file):
392
420
if response .status_code == 200 :
393
421
resp_json = response .json ()
394
422
version_id = resp_json .get ('data' , {}).get ('sbomUpload' , {}).get ('id' )
423
+ logging .debug ("version_id or sbom_id: %s" , version_id )
395
424
errors = resp_json .get ('data' , {}).get (
396
425
'sbomUpload' , {}).get ('errors' )
397
426
if errors :
@@ -407,6 +436,7 @@ def upload(self, sbom_file):
407
436
print ('Uploaded successfully' )
408
437
logging .debug ("SBOM Uploading response: %s" , response .text )
409
438
return 0
439
+ print ("Error uploading sbom" )
410
440
logging .error ("Error uploading sbom: %d" , response .status_code )
411
441
except requests .exceptions .RequestException as ex :
412
442
logging .error ("RequestException: %s" , ex )
0 commit comments