Skip to content

Commit 6bf7be9

Browse files
committed
fix: support 'artifact-reference' with private artifacts
Issue: #90
1 parent 34597b9 commit 6bf7be9

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

src/taskgraph/util/parameterization.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ def repl(match):
8383
f"task '{label}' has no dependency named '{dependency}'"
8484
)
8585

86-
assert artifact_name.startswith(
87-
"public/"
88-
), f"artifact-reference only supports public artifacts, not `{artifact_name}`"
89-
return get_artifact_url(task_id, artifact_name)
86+
use_proxy = False
87+
if not artifact_name.startswith("public/"):
88+
use_proxy = True
89+
90+
return get_artifact_url(task_id, artifact_name, use_proxy=use_proxy)
9091

9192
return ARTIFACT_REFERENCE_PATTERN.sub(repl, val)
9293

src/taskgraph/util/taskcluster.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,9 @@ def _handle_artifact(path, response):
140140

141141
def get_artifact_url(task_id, path, use_proxy=False):
142142
artifact_tmpl = liburls.api(
143-
get_root_url(False), "queue", "v1", "task/{}/artifacts/{}"
143+
get_root_url(use_proxy), "queue", "v1", "task/{}/artifacts/{}"
144144
)
145-
data = artifact_tmpl.format(task_id, path)
146-
if use_proxy:
147-
# Until Bug 1405889 is deployed, we can't download directly
148-
# from the taskcluster-proxy. Work around by using the /bewit
149-
# endpoint instead.
150-
# The bewit URL is the body of a 303 redirect, which we don't
151-
# want to follow (which fetches a potentially large resource).
152-
response = _do_request(
153-
os.environ["TASKCLUSTER_PROXY_URL"] + "/bewit",
154-
data=data,
155-
allow_redirects=False,
156-
)
157-
return response.text
158-
return data
145+
return artifact_tmpl.format(task_id, path)
159146

160147

161148
def get_artifact(task_id, path, use_proxy=False):

test/test_util_parameterization.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ def test_artifact_refs_in_string(assert_artifact_refs):
205205
)
206206

207207

208+
def test_artifact_refs_private(monkeypatch, assert_artifact_refs):
209+
"resolve_task_references resolves private artifact references"
210+
tc_proxy_url = "https://taskcluster-proxy.net"
211+
monkeypatch.setenv("TASKCLUSTER_PROXY_URL", tc_proxy_url)
212+
213+
assert_artifact_refs(
214+
{"artifact-reference": "<edge1/private/foo>"},
215+
f"{tc_proxy_url}/api/queue/v1/task/tid1/artifacts/private/foo",
216+
)
217+
218+
208219
def test_artifact_refs_self():
209220
"resolve_task_references raises keyerror on artifact references to `self`"
210221
with pytest.raises(KeyError):

test/test_util_taskcluster.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ def test_do_request(responses):
106106
tc._do_request("https://example.org")
107107

108108

109+
@pytest.mark.parametrize(
110+
"use_proxy,expected",
111+
(
112+
pytest.param(
113+
False,
114+
"https://tc.example.com/api/queue/v1/task/abc/artifacts/public/log.txt",
115+
id="use_proxy=False",
116+
),
117+
pytest.param(
118+
True,
119+
"https://taskcluster-proxy.net/api/queue/v1/task/abc/artifacts/public/log.txt",
120+
id="use_proxy=True",
121+
),
122+
),
123+
)
124+
def test_get_artifact_url(monkeypatch, use_proxy, expected):
125+
if use_proxy:
126+
monkeypatch.setenv("TASKCLUSTER_PROXY_URL", "https://taskcluster-proxy.net")
127+
128+
task_id = "abc"
129+
path = "public/log.txt"
130+
assert tc.get_artifact_url(task_id, path, use_proxy) == expected
131+
132+
109133
def test_get_artifact(responses, root_url):
110134
tid = 123
111135
responses.add(

0 commit comments

Comments
 (0)