Skip to content

Commit 75d0a5f

Browse files
committed
refactor: simplify get_artifact_url
get_root_url already normalizes the url, so no need for the if/else here.
1 parent d1ef368 commit 75d0a5f

File tree

2 files changed

+5
-24
lines changed

2 files changed

+5
-24
lines changed

src/taskgraph/util/taskcluster.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,7 @@ def get_session():
141141

142142

143143
def get_artifact_url(task_id, path, use_proxy=False):
144-
if use_proxy:
145-
try:
146-
url = liburls.normalize_root_url(os.environ["TASKCLUSTER_PROXY_URL"])
147-
except KeyError:
148-
if "TASK_ID" not in os.environ:
149-
raise RuntimeError(
150-
"taskcluster-proxy is not available when not executing in a task"
151-
)
152-
else:
153-
raise RuntimeError("taskcluster-proxy is not enabled for this task")
154-
155-
else:
156-
url = get_root_url(block_proxy=True)
157-
144+
url = get_root_url(block_proxy=not use_proxy)
158145
artifact_tmpl = liburls.api(url, "queue", "v1", "task/{}/artifacts/{}")
159146
return artifact_tmpl.format(task_id, path)
160147

test/test_util_taskcluster.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def test_get_artifact_url(monkeypatch):
6565
tc.get_root_url.cache_clear()
6666
task_id = "abc"
6767
path = "public/log.txt"
68-
expected = "https://tc.example.com/api/queue/v1/task/abc/artifacts/public/log.txt"
68+
expected = f"https://tc.example.com/api/queue/v1/task/{task_id}/artifacts/{path}"
6969
expected_proxy = (
70-
"https://taskcluster-proxy.net/api/queue/v1/task/abc/artifacts/public/log.txt"
70+
f"https://taskcluster-proxy.net/api/queue/v1/task/{task_id}/artifacts/{path}"
7171
)
7272

7373
# Test with default root URL (no proxy)
@@ -86,17 +86,11 @@ def test_get_artifact_url(monkeypatch):
8686
monkeypatch.delenv("TASKCLUSTER_PROXY_URL")
8787
monkeypatch.delenv("TASK_ID", raising=False)
8888
tc.get_root_url.cache_clear()
89-
with pytest.raises(RuntimeError) as exc:
90-
tc.get_artifact_url(task_id, path, use_proxy=True)
91-
assert "taskcluster-proxy is not available when not executing in a task" in str(
92-
exc.value
93-
)
89+
assert tc.get_artifact_url(task_id, path, use_proxy=True) == expected
9490

9591
# Test with use_proxy=True but proxy not enabled (in a task without proxy)
9692
monkeypatch.setenv("TASK_ID", "some-task-id")
97-
with pytest.raises(RuntimeError) as exc:
98-
tc.get_artifact_url(task_id, path, use_proxy=True)
99-
assert "taskcluster-proxy is not enabled for this task" in str(exc.value)
93+
assert tc.get_artifact_url(task_id, path, use_proxy=True) == expected
10094

10195

10296
def test_get_artifact(responses, root_url):

0 commit comments

Comments
 (0)