Skip to content

Commit

Permalink
Add varible to control bom upload.
Browse files Browse the repository at this point in the history
  • Loading branch information
vasile.baluta committed Jun 2, 2022
1 parent 70b34dc commit b85442c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>meta-dependencytrack</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
11 changes: 9 additions & 2 deletions classes/dependency-track.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ DEPENDENCYTRACK_SBOM ??= "${DEPENDENCYTRACK_DIR}/bom.json"
DEPENDENCYTRACK_TMP ??= "${TMPDIR}/dependency-track"
DEPENDENCYTRACK_LOCK ??= "${DEPENDENCYTRACK_TMP}/bom.lock"

# Set DEPENDENCYTRACK_UPLOAD to False if you want to control the upload in other
# steps.
DEPENDENCYTRACK_UPLOAD ??= "True"
DEPENDENCYTRACK_PROJECT ??= ""
DEPENDENCYTRACK_API_URL ??= "http://localhost:8081/api"
DEPENDENCYTRACK_API_KEY ??= ""
Expand Down Expand Up @@ -74,6 +77,10 @@ python do_dependencytrack_upload () {
import urllib
from pathlib import Path

dt_upload = bb.utils.to_boolean(d.getVar('DEPENDENCYTRACK_UPLOAD'))
if not dt_upload:
return

sbom_path = d.getVar("DEPENDENCYTRACK_SBOM")
dt_project = d.getVar("DEPENDENCYTRACK_PROJECT")
dt_url = f"{d.getVar('DEPENDENCYTRACK_API_URL')}/v1/bom"
Expand All @@ -86,7 +93,7 @@ python do_dependencytrack_upload () {
"bom": base64.b64encode(sbom.encode()).decode('ascii')
}).encode()
bb.debug(2, f"Uploading SBOM to project {dt_project} at {dt_url}")

headers = {
"Content-Type": "application/json",
"X-API-Key": d.getVar("DEPENDENCYTRACK_API_KEY")
Expand All @@ -96,7 +103,7 @@ python do_dependencytrack_upload () {
data=payload,
headers=headers,
method="PUT")

try:
urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
Expand Down

0 comments on commit b85442c

Please sign in to comment.