Skip to content

Commit

Permalink
download-sbom: make auth work with curl < 7.83.0
Browse files Browse the repository at this point in the history
Curl versions lower than 7.83.0 do not support the %header{...} syntax.
Write out all the headers and pick out the one we need using sed.

Signed-off-by: Adam Cmiel <[email protected]>
  • Loading branch information
chmeliik committed Aug 12, 2024
1 parent bbff7eb commit ee02206
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,31 @@ spec:
local tmp_dest=$(mktemp --tmpdir)
local headers_file
headers_file=$(mktemp --tmpdir download-sbom-task.headers.XXXXXX)
local common_curl_opts=(--silent --show-error --retry "${HTTP_RETRIES:-3}")
echo "GET $blob_url" >&2
local outputs
mapfile -t outputs < <(curl \
local response_code
response_code=$(curl \
"${common_curl_opts[@]}" \
-L \
--write-out '%header{www-authenticate}\n%{response_code}' \
--write-out '%{response_code}' \
--output "$tmp_dest" \
--dump-header "$headers_file" \
"$blob_url"
)
local www_authenticate=${outputs[0]}
local response_code=${outputs[1]}
if [[ "$response_code" -eq 200 ]]; then
# Blob download didn't require auth, we're done
:
elif [[ "$response_code" -eq 401 ]]; then
echo "Got 401, trying to authenticate" >&2
local www_authenticate
www_authenticate=$(sed -n 's/^www-authenticate:\s*//ip' "$headers_file")
local realm service scope token_url
realm=$(get_from_www_auth_header "$www_authenticate" realm)
service=$(get_from_www_auth_header "$www_authenticate" service)
Expand Down

0 comments on commit ee02206

Please sign in to comment.