Skip to content

Commit

Permalink
Don't add Authorization header to redirected download request
Browse files Browse the repository at this point in the history
Don't add Authorization header to redirected GitHub artifact download
request. It seems that the place upload-artifacts@v4 now stores things
doesn't like being given an unnecessary Authorization header.

Also: Log any error response to these requests
Also: provide a simple way to test examine_run_artifacts
  • Loading branch information
jon-turney committed Mar 23, 2024
1 parent 2d58a9b commit 5f26594
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ def fetch():
req = urllib.request.Request(url)

if backend == 'github':
req.add_header('Authorization', 'Bearer ' + gh_token.fetch_iat())
req.add_unredirected_header('Authorization', 'Bearer ' + gh_token.fetch_iat())

_LOGGER.info('fetching %s' % url)

try:
with urllib.request.urlopen(req, timeout=60) as response:
shutil.copyfileobj(response, tmpfile)
except (socket.timeout, urllib.error.URLError):
except (socket.timeout, urllib.error.URLError) as e:
logging.info("archive download response %s" % e)
incomplete = True
break

Expand Down
14 changes: 12 additions & 2 deletions gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ def examine_run_artifacts(wfr_id, u):
if a['name'] == 'metadata':
url = a['archive_download_url']
req = urllib.request.Request(url)
req.add_header('Authorization', 'Bearer ' + gh_token.fetch_iat())
req.add_unredirected_header('Authorization', 'Bearer ' + gh_token.fetch_iat())

# occasionally, the metadata file is 404, despite appearing in the
# list of artifacts. it seems we need to wait a little while after
# the run has completed before that URL becomes valid, so we'll try
# again later.
try:
response = urllib.request.urlopen(req)
except urllib.error.URLError:
except urllib.error.URLError as e:
logging.info("metadata download REST API response %s" % e)
break

# fetch to a temporary file as zipfile needs to seek
Expand Down Expand Up @@ -83,3 +84,12 @@ def examine_run_artifacts(wfr_id, u):
# if we couldn't retrieve, or didn't find the metadata file in the workflow
# artifacts, try again later
return found_metadata


if __name__ == '__main__':
import sys
import types

u = types.SimpleNamespace()
examine_run_artifacts(sys.argv[1], u)
print(u)

0 comments on commit 5f26594

Please sign in to comment.