Skip to content

Commit b3e49aa

Browse files
committed
Script did not report failure corectly
Problem: When curling to archivist endpoint the details of the error on failure are not explicitly displayed. Solution: Checked status code is not "2XX" and if so then display a json map of paramaters. Signed-off-by: Paul Hewlett <[email protected]>
1 parent 9e3dcaf commit b3e49aa

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

scripts/sbom_scraper.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,13 @@ else
498498
HTTP_STATUS=""
499499
# get token
500500
log "Get token ..."
501-
HTTP_STATUS=$(curl -sS -w "%{http_code}" \
501+
HTTP_STATUS=$(curl -sS -w "%{http_code} %{json}" \
502502
-o "${TEMPDIR}/access_token" \
503503
--data-urlencode "grant_type=client_credentials" \
504504
--data-urlencode "client_id=${CLIENT_ID}" \
505505
--data-urlencode "client_secret=${SECRET}" \
506506
"${URL}/archivist/iam/v1/appidp/token")
507-
if [ "${HTTP_STATUS}" != "200" ]
507+
if [ "${HTTP_STATUS:0:1}" != "2" ]
508508
then
509509
log "Get token failure ${HTTP_STATUS}"
510510
exit 2
@@ -524,7 +524,7 @@ EOF
524524
log "Upload ${PRIVACY} ${OUTPUT} ..."
525525

526526
HTTP_STATUS=$(timeout ${SBOM_UPLOAD_TIMEOUT} \
527-
curl -s -w "%{http_code}" -X POST \
527+
curl -s -w "%{http_code} %{json}" -X POST \
528528
-o "${TEMPDIR}/upload" \
529529
-H "@${BEARER_TOKEN_FILE}" \
530530
-H "content_type=text/xml" \
@@ -545,9 +545,9 @@ EOF
545545
exit 4
546546
fi
547547

548-
if [ "${HTTP_STATUS}" != "200" ]
548+
if [ "${HTTP_STATUS:0:1}" != "2" ]
549549
then
550-
log "Upload failure: HTTP ${HTTP_STATUS}"
550+
log "Upload failure ${HTTP_STATUS}"
551551
exit 5
552552
fi
553553
log "Upload success: "

0 commit comments

Comments
 (0)