Skip to content

Commit 2e61ab4

Browse files
committed
update downloadSbom api accordingly
Signed-off-by: Vivek Kumar Sahu <[email protected]>
1 parent 27766f9 commit 2e61ab4

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

lynkctx.py

+39-9
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,31 @@
8484
"""
8585

8686
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) {
8998
download(
9099
sbomId: $sbomId
91100
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+
}
93112
__typename
94113
}
95114
}
@@ -311,11 +330,16 @@ def download(self):
311330
self.env_id, self.ver_id)
312331

313332
variables = {
314-
"envId": self.env_id,
333+
"projectId": self.env_id,
315334
"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
317341
}
318-
342+
logging.debug("Variables for request: %s", variables)
319343
request_data = {
320344
"query": QUERY_SBOM_DOWNLOAD,
321345
"variables": variables,
@@ -341,10 +365,14 @@ def download(self):
341365
print('No SBOM matched with the given ID')
342366
logging.debug(data)
343367
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')
346374
logging.debug('Completed download and decoding')
347-
return decoded_content.decode('utf-8')
375+
return decoded_content
348376
except json.JSONDecodeError:
349377
logging.error("Failed to parse JSON response.")
350378
else:
@@ -392,6 +420,7 @@ def upload(self, sbom_file):
392420
if response.status_code == 200:
393421
resp_json = response.json()
394422
version_id = resp_json.get('data', {}).get('sbomUpload', {}).get('id')
423+
logging.debug("version_id or sbom_id: %s", version_id)
395424
errors = resp_json.get('data', {}).get(
396425
'sbomUpload', {}).get('errors')
397426
if errors:
@@ -407,6 +436,7 @@ def upload(self, sbom_file):
407436
print('Uploaded successfully')
408437
logging.debug("SBOM Uploading response: %s", response.text)
409438
return 0
439+
print("Error uploading sbom")
410440
logging.error("Error uploading sbom: %d", response.status_code)
411441
except requests.exceptions.RequestException as ex:
412442
logging.error("RequestException: %s", ex)

0 commit comments

Comments
 (0)