Commit 4b373aea authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Job artifacts: dealing with S3 redirection

This changes how to find the file name from the download
response.

--HG--
branch : stable
parent 3586d39dbc8e
Pipeline #18077 passed with stages
in 22 minutes and 10 seconds
......@@ -8,7 +8,10 @@ import py
import re
import requests
import time
from urllib.parse import urlencode
from urllib.parse import (
urlencode,
urlparse,
)
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
......@@ -1176,14 +1179,25 @@ class Project(object):
"""Return filename, artifacts (archive) as bytes."""
resp = self.owner_api_get(subpath='jobs/%d/artifacts' % job['id'])
assert resp.status_code == 200
# Finding file name depends on redirections (S3 etc.)
# if we need something more precise, the 302 response is available
# in resp.history
if resp.url.startswith(self.heptapod.url):
# no redirection, filename is in `Content-Disposition`
# Not fully compliant filename parsing.
# Full specification: RFC 6266.
# there's an unsupported lib on PyPI for this (rfc6266)
m = re.match(r'attachment; filename="(.*?)";',
resp.headers['Content-Disposition'])
assert m is not None
filename = m.group(1)
else:
# redirection, e.g, to S3 storage backend.
# If needed, we could check it is really S3 by looking
# for `AWSAccessKeyId` in query params.
filename = urlparse(resp.url).path.rsplit('/', 1)[-1]
# Not fully compliant filename parsing.
# Full specification: RFC 6266.
# there's an unsupported lib on PyPI for this (rfc6266)
m = re.match(r'attachment; filename="(.*?)";',
resp.headers['Content-Disposition'])
assert m is not None
return m.group(1), resp.content
return filename, resp.content
def api_create_mirror(self, **params):
return ProjectMirror.api_create(self, **params)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment