From 6d81c625da0235154540a0df85b6bdf0dc6335c2 Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Thu, 23 Oct 2025 15:25:10 -0400 Subject: [PATCH 1/2] fix: avoid proxy by default in get_index_url This aligns with get_artifact_url. Typically if you're building a url rather than actually fetching something, then it's because the downloading will happen in a downstream task, where the proxy might not be available, or might have a different url. So defaulting to not using it makes the most sense. --- src/taskgraph/util/taskcluster.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/taskgraph/util/taskcluster.py b/src/taskgraph/util/taskcluster.py index 1560ff7c5..479817878 100644 --- a/src/taskgraph/util/taskcluster.py +++ b/src/taskgraph/util/taskcluster.py @@ -194,8 +194,10 @@ def get_artifact_path(task, path): return f"{get_artifact_prefix(task)}/{path}" -def get_index_url(index_path, multiple=False): - index_tmpl = liburls.api(get_root_url(), "index", "v1", "task{}/{}") +def get_index_url(index_path, multiple=False, use_proxy=False): + index_tmpl = liburls.api( + get_root_url(block_proxy=not use_proxy), "index", "v1", "task{}/{}" + ) return index_tmpl.format("s" if multiple else "", index_path) From 327e97bd00de9b1a003e8188d236dcf319fcbc13 Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Thu, 23 Oct 2025 15:25:10 -0400 Subject: [PATCH 2/2] refactor: simplify get_artifact_url get_root_url already normalizes the url, so no need for the if/else here. --- src/taskgraph/util/taskcluster.py | 15 +-------------- test/test_util_taskcluster.py | 14 ++++---------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/taskgraph/util/taskcluster.py b/src/taskgraph/util/taskcluster.py index 479817878..a8e6e2e6f 100644 --- a/src/taskgraph/util/taskcluster.py +++ b/src/taskgraph/util/taskcluster.py @@ -141,20 +141,7 @@ def get_session(): def get_artifact_url(task_id, path, use_proxy=False): - if use_proxy: - try: - url = liburls.normalize_root_url(os.environ["TASKCLUSTER_PROXY_URL"]) - except KeyError: - if "TASK_ID" not in os.environ: - raise RuntimeError( - "taskcluster-proxy is not available when not executing in a task" - ) - else: - raise RuntimeError("taskcluster-proxy is not enabled for this task") - - else: - url = get_root_url(block_proxy=True) - + url = get_root_url(block_proxy=not use_proxy) artifact_tmpl = liburls.api(url, "queue", "v1", "task/{}/artifacts/{}") return artifact_tmpl.format(task_id, path) diff --git a/test/test_util_taskcluster.py b/test/test_util_taskcluster.py index 6d9e7d3a5..e2c926a99 100644 --- a/test/test_util_taskcluster.py +++ b/test/test_util_taskcluster.py @@ -65,9 +65,9 @@ def test_get_artifact_url(monkeypatch): tc.get_root_url.cache_clear() task_id = "abc" path = "public/log.txt" - expected = "https://tc.example.com/api/queue/v1/task/abc/artifacts/public/log.txt" + expected = f"https://tc.example.com/api/queue/v1/task/{task_id}/artifacts/{path}" expected_proxy = ( - "https://taskcluster-proxy.net/api/queue/v1/task/abc/artifacts/public/log.txt" + f"https://taskcluster-proxy.net/api/queue/v1/task/{task_id}/artifacts/{path}" ) # Test with default root URL (no proxy) @@ -86,17 +86,11 @@ def test_get_artifact_url(monkeypatch): monkeypatch.delenv("TASKCLUSTER_PROXY_URL") monkeypatch.delenv("TASK_ID", raising=False) tc.get_root_url.cache_clear() - with pytest.raises(RuntimeError) as exc: - tc.get_artifact_url(task_id, path, use_proxy=True) - assert "taskcluster-proxy is not available when not executing in a task" in str( - exc.value - ) + assert tc.get_artifact_url(task_id, path, use_proxy=True) == expected # Test with use_proxy=True but proxy not enabled (in a task without proxy) monkeypatch.setenv("TASK_ID", "some-task-id") - with pytest.raises(RuntimeError) as exc: - tc.get_artifact_url(task_id, path, use_proxy=True) - assert "taskcluster-proxy is not enabled for this task" in str(exc.value) + assert tc.get_artifact_url(task_id, path, use_proxy=True) == expected def test_get_artifact(responses, root_url):