Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only publish to Dependency Track when URL is provided #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions classes/dependency-track.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DEPENDENCYTRACK_TMP ??= "${TMPDIR}/dependency-track"
DEPENDENCYTRACK_LOCK ??= "${DEPENDENCYTRACK_TMP}/bom.lock"

DEPENDENCYTRACK_PROJECT ??= ""
DEPENDENCYTRACK_API_URL ??= "http://localhost:8081/api"
DEPENDENCYTRACK_API_URL ??= ""
DEPENDENCYTRACK_API_KEY ??= ""

python do_dependencytrack_init() {
Expand Down Expand Up @@ -74,9 +74,15 @@ python do_dependencytrack_upload () {
import urllib
from pathlib import Path

var_api_url = "DEPENDENCYTRACK_API_URL"

if d.getVar(var_api_url) == "":
bb.debug(2, f"Not uploading to Dependency Track, no API URL set in {var_api_url}")
return

sbom_path = d.getVar("DEPENDENCYTRACK_SBOM")
dt_project = d.getVar("DEPENDENCYTRACK_PROJECT")
dt_url = f"{d.getVar('DEPENDENCYTRACK_API_URL')}/v1/bom"
dt_url = f"{d.getVar(var_api_url)}/v1/bom"

bb.debug(2, f"Loading final SBOM: {sbom_path}")
sbom = Path(sbom_path).read_text()
Expand All @@ -86,7 +92,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 +102,7 @@ python do_dependencytrack_upload () {
data=payload,
headers=headers,
method="PUT")

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