Skip to content

Commit

Permalink
Merge pull request #418 from btel/implement-proxylist-for-proxy-channels
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Jul 2, 2021
2 parents 08f2c4a + 42c6317 commit cc4fdec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
22 changes: 11 additions & 11 deletions quetz/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,17 +1560,6 @@ def serve_path(
dao: Dao = Depends(get_dao),
):

if channel.mirror_channel_url and channel.mirror_mode == "proxy":
repository = RemoteRepository(channel.mirror_channel_url, session)
if not pkgstore.file_exists(channel.name, path):
download_remote_file(repository, pkgstore, channel.name, path)
elif path.endswith(".json"):
# repodata.json and current_repodata.json are cached locally
# for channel.ttl seconds
_, fmtime, _ = pkgstore.get_filemetadata(channel.name, path)
if time.time() - fmtime >= channel.ttl:
download_remote_file(repository, pkgstore, channel.name, path)

chunk_size = 10_000

is_package_request = path.endswith((".tar.bz2", ".conda"))
Expand Down Expand Up @@ -1598,6 +1587,17 @@ def serve_path(
if channel_proxylist and package_name and package_name in channel_proxylist:
return RedirectResponse(f"{channel.mirror_channel_url}/{path}")

if channel.mirror_channel_url and channel.mirror_mode == "proxy":
repository = RemoteRepository(channel.mirror_channel_url, session)
if not pkgstore.file_exists(channel.name, path):
download_remote_file(repository, pkgstore, channel.name, path)
elif path.endswith(".json"):
# repodata.json and current_repodata.json are cached locally
# for channel.ttl seconds
_, fmtime, _ = pkgstore.get_filemetadata(channel.name, path)
if time.time() - fmtime >= channel.ttl:
download_remote_file(repository, pkgstore, channel.name, path)

if (
is_package_request or pkgstore.kind == "LocalStore"
) and pkgstore.support_redirect:
Expand Down
28 changes: 28 additions & 0 deletions quetz/tests/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,34 @@ def test_includelist_and_excludelist_mirror_channel(owner, client):
assert response.status_code == 422


@pytest.mark.parametrize("mirror_mode", ["proxy", "mirror"])
def test_proxylist_mirror_channel(owner, client, mirror_mode):
response = client.get("/api/dummylogin/bartosz")
assert response.status_code == 200

response = client.post(
"/api/channels",
json={
"name": "mirror-channel-btel",
"private": False,
"mirror_channel_url": "https://conda.anaconda.org/btel",
"mirror_mode": mirror_mode,
"metadata": {"proxylist": ["nrnpython"]},
},
)
assert response.status_code == 201

response = client.get(
"/get/mirror-channel-btel/linux-64/nrnpython-0.1-0.tar.bz2",
allow_redirects=False,
)
assert response.status_code == 307
assert (
response.headers.get("location")
== "https://conda.anaconda.org/btel/linux-64/nrnpython-0.1-0.tar.bz2"
)


def test_sync_local_channel(local_channel, user, client, dummy_repo):
response = client.put(
f"/api/channels/{local_channel.name}/actions", json={"action": "synchronize"}
Expand Down

0 comments on commit cc4fdec

Please sign in to comment.