Skip to content
Merged
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
16 changes: 10 additions & 6 deletions scripts/sbom_scraper.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Scrape a docker image and upload as SBOM file
# Scrape a docker image and upload as public or private SBOM file
#
# Preparation:
#
Expand Down Expand Up @@ -48,20 +48,22 @@ FORMAT=cyclonedx
# credentials directory has 0600 permissions
CLIENTSECRET_FILE=credentials/client_secret
SBOM=false
PRIVACY=PUBLIC

URL=https://app.rkvst.io

usage() {
cat >&2 <<EOF

Scrape an SBOM from a docker image
Scrape an SBOM from a docker image and upload to abom archivist

Usage: $SCRIPTNAME [-c clientsecretfile] [-o output format] [-s sbomFile ] [-u url] client_id [docker-image|sbom file]
Usage: $SCRIPTNAME [-p] [-c clientsecretfile] [-o output format] [-s sbomFile ] [-u url] client_id [docker-image|sbom file]

-c clientsecretfile containing client secret (default ${CLIENTSECRET_FILE})
-o FORMAT default ($FORMAT) [cyclonedx]
-s default ($SBOM) if specified the second argument is an sbom file
and -o is ignored.
-p upload private SBOM
-u URL URL Default ($URL)

Example:
Expand All @@ -73,12 +75,14 @@ EOF
exit 1
}

while getopts "c:ho:su:" o; do
while getopts "c:ho:psu:" o; do
case "${o}" in
c) CLIENTSECRET_FILE="${OPTARG}"
;;
o) FORMAT=${OPTARG}
;;
p) PRIVACY=PRIVATE
;;
s) SBOM=true
;;
u) URL=$OPTARG
Expand Down Expand Up @@ -165,14 +169,14 @@ EOF
# ----------------------------------------------------------------------------
# Upload SBOM
# ----------------------------------------------------------------------------
log "Upload ${OUTPUT}"
log "Upload ${PRIVACY} ${OUTPUT}"

HTTP_STATUS=$(curl -s -w "%{http_code}" -X POST \
-o "${TEMPDIR}/upload" \
-H "@${BEARER_TOKEN_FILE}" \
-H "content_type=text/xml" \
-F "sbom=@${OUTPUT}" \
"${URL}/archivist/v1/sboms")
"${URL}/archivist/v1/sboms?privacy=${PRIVACY}")

if [ "${HTTP_STATUS}" != "200" ]
then
Expand Down