File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -124,11 +124,16 @@ function validate-hash {
124
124
}
125
125
126
126
# Get default service account credentials of the VM.
127
+ GCE_METADATA_INTERNAL=" http://metadata.google.internal/computeMetadata/v1/instance"
127
128
function get-credentials {
128
- curl " http://metadata.google.internal/computeMetadata/v1/instance /service-accounts/default/token" -H " Metadata-Flavor: Google" -s | python -c \
129
+ curl " ${GCE_METADATA_INTERNAL} /service-accounts/default/token" -H " Metadata-Flavor: Google" -s | python -c \
129
130
' import sys; import json; print(json.loads(sys.stdin.read())["access_token"])'
130
131
}
131
132
133
+ function valid-storage-scope {
134
+ curl " ${GCE_METADATA_INTERNAL} /service-accounts/default/scopes" -H " Metadata-Flavor: Google" -s | grep -q " auth/devstorage"
135
+ }
136
+
132
137
# Retry a download until we get it. Takes a hash and a set of URLs.
133
138
#
134
139
# $1 is the sha1 of the URL. Can be "" if the sha1 is unknown.
@@ -144,7 +149,7 @@ function download-or-bust {
144
149
rm -f " ${file} "
145
150
# if the url belongs to GCS API we should use oauth2_token in the headers
146
151
local curl_headers=" "
147
- if [[ " $url " =~ ^https://storage.googleapis.com.* ]]; then
152
+ if [[ " $url " =~ ^https://storage.googleapis.com.* ]] && valid-storage-scope ; then
148
153
curl_headers=" Authorization: Bearer $( get-credentials) "
149
154
fi
150
155
if ! curl ${curl_headers: +-H " ${curl_headers} " } -f --ipv4 -Lo " ${file} " --connect-timeout 20 --max-time 300 --retry 6 --retry-delay 10 ${CURL_RETRY_CONNREFUSED} " ${url} " ; then
You can’t perform that action at this time.
0 commit comments