Duplicate reposerver to isolate micromamba tests (#3071)

This commit is contained in:
Antoine Prouvost 2023-12-19 18:30:37 +01:00 committed by GitHub
parent 443c3e35d5
commit 425aef9dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 809 additions and 6 deletions

View File

@ -0,0 +1,53 @@
{
"info": {
"subdir": "linux-64"
},
"packages": {
"A_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "a",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "linux-64",
"timestamp": 1578950023135,
"version": "0.1.0"
},
"A_0.2.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "a",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "linux-64",
"timestamp": 1578950023135,
"version": "0.2.0"
},
"B_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [
"a"
],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "b",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "linux-64",
"timestamp": 1578950023135,
"version": "0.1.0"
}
},
"removed": [],
"repodata_version": 1
}

View File

@ -0,0 +1,55 @@
{
"info": {
"subdir": "linux-64"
},
"packages": {
"A_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [
],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "a",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "linux-64",
"timestamp": 1578950023135,
"version": "0.1.0"
},
"A_0.2.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [
],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "a",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "linux-64",
"timestamp": 1578950023135,
"version": "0.2.0"
},
"B_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [
"a"GLIBC_PLACEHOLDER
],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "b",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "linux-64",
"timestamp": 1578950023135,
"version": "0.1.0"
}
},
"removed": [],
"repodata_version": 1
}

View File

@ -0,0 +1,40 @@
{
"info": {
"subdir": "noarch"
},
"packages": {
"_r-mutex-1.0.1-anacondar_1.tar.bz2": {
"build": "anacondar_1",
"build_number": 1,
"constrains": [],
"depends": [],
"license": "BSD",
"md5": "19f9db5f4f1b7f5ef5f6d67207f25f38",
"name": "_r-mutex",
"noarch": "generic",
"platform": null,
"sha256": "e58f9eeb416b92b550e824bcb1b9fb1958dee69abfe3089dfd1a9173e3a0528a",
"size": 3566,
"subdir": "noarch",
"timestamp": 1562343890778,
"track_features": "",
"version": "1.0.1"
},
"testpkg_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "testpkg",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "noarch",
"timestamp": 1578950023135,
"version": "0.1.0"
}
},
"removed": [],
"repodata_version": 1
}

View File

@ -0,0 +1,53 @@
{
"info": {
"subdir": "win-64"
},
"packages": {
"A_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "a",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "win-64",
"timestamp": 1578950023135,
"version": "0.1.0"
},
"A_0.2.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "a",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "win-64",
"timestamp": 1578950023135,
"version": "0.2.0"
},
"B_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [
"a"
],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "b",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "win-64",
"timestamp": 1578950023135,
"version": "0.1.0"
}
},
"removed": [],
"repodata_version": 1
}

View File

@ -0,0 +1,55 @@
{
"info": {
"subdir": "win-64"
},
"packages": {
"A_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [
],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "a",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "win-64",
"timestamp": 1578950023135,
"version": "0.1.0"
},
"A_0.2.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [
],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "a",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "win-64",
"timestamp": 1578950023135,
"version": "0.2.0"
},
"B_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [
"a"GLIBC_PLACEHOLDER
],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "b",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "win-64",
"timestamp": 1578950023135,
"version": "0.1.0"
}
},
"removed": [],
"repodata_version": 1
}

View File

@ -0,0 +1,23 @@
{
"info": {
"subdir": "linux-64"
},
"packages": {
"A_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "a",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "linux-64",
"timestamp": 1578950023135,
"version": "0.1.0"
}
},
"removed": [],
"repodata_version": 1
}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,23 @@
{
"info": {
"subdir": "win-64"
},
"packages": {
"A_0.1.0.tar.bz2": {
"build": "abc",
"build_number": 0,
"depends": [],
"license": "BSD",
"license_family": "BSD",
"md5": "85107fc10154734ef34a5a75685be684",
"name": "a",
"sha256": "398831eff682d2c975b360d64656d8f475cbc1f1b6d0ee33d86285190e7ee4d1",
"size": 222503,
"subdir": "win-64",
"timestamp": 1578950023135,
"version": "0.1.0"
}
},
"removed": [],
"repodata_version": 1
}

View File

@ -0,0 +1,38 @@
{
"channeldata_version": 1,
"packages": {
"test-package": {
"activate.d": false,
"binary_prefix": false,
"deactivate.d": false,
"description": null,
"dev_url": null,
"doc_source_url": null,
"doc_url": null,
"home": "https://github.com/mamba-org/mamba",
"icon_hash": null,
"icon_url": null,
"identifiers": null,
"keywords": null,
"license": "BSD",
"post_link": false,
"pre_link": false,
"pre_unlink": false,
"recipe_origin": null,
"run_exports": {},
"source_git_url": null,
"source_url": null,
"subdirs": [
"noarch"
],
"summary": "I am just a test package!",
"tags": null,
"text_prefix": false,
"timestamp": 1613117294,
"version": "0.1"
}
},
"subdirs": [
"noarch"
]
}

View File

@ -0,0 +1,90 @@
<html>
<head>
<title>repo</title>
<style type="text/css">
a, a:active {
text-decoration: none; color: blue;
}
a:visited {
color: #48468F;
}
a:hover, a:focus {
text-decoration: underline; color: red;
}
body {
background-color: #F5F5F5;
}
h2 {
margin-bottom: 12px;
}
th, td {
font: 100% monospace; text-align: left;
}
th {
font-weight: bold; padding-right: 14px; padding-bottom: 3px;
}
th.tight {
padding-right: 6px;
}
td {
padding-right: 14px;
}
td.tight {
padding-right: 8px;
}
td.s, th.s {
text-align: right;
}
td.summary {
white-space: nowrap;
overflow: hidden;
}
td.packagename {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
max-width: 180px;
padding-right: 8px;
}
td.version {
//white-space: nowrap;
overflow: hidden;
max-width: 90px;
padding-right: 8px;
}
table {
background-color: white;
border-top: 1px solid #646464;
border-bottom: 1px solid #646464;
padding-top: 10px;
padding-bottom: 14px;
}
address {
color: #787878;
padding-top: 10px;
}
</style>
</head>
<body>
<h2>repo</h2>
<h3><a href="rss.xml">RSS Feed</a>&nbsp;&nbsp;&nbsp;<a href="channeldata.json">channeldata.json</a></h3>
<a href="noarch">noarch</a>&nbsp;&nbsp;&nbsp; <table>
<tr>
<th style="padding-right:18px;">Package</th>
<th>Latest Version</th>
<th>Doc</th>
<th>Dev</th>
<th>License</th>
<th class="tight">noarch</th> <th>Summary</th>
</tr>
<tr>
<td class="packagename"><a href="https://github.com/mamba-org/mamba" alt="test-package">test-package</a></td>
<td class="version">0.1</td>
<td></td>
<td></td>
<td class="tight">BSD</td>
<td>X</td> <td class="summary">I am just a test package!</td>
</tr> </table>
<address>Updated: 2021-02-12 09:02:37 +0000 - Files: 1</address>
</body>
</html>

View File

@ -0,0 +1,25 @@
{
"info": {
"subdir": "noarch"
},
"packages": {
"test-package-0.1-0.tar.bz2": {
"build": "0",
"build_number": 0,
"depends": [],
"license": "BSD",
"license_family": "BSD",
"md5": "2a8595f37faa2950e1b433acbe91d481",
"name": "test-package",
"noarch": "generic",
"sha256": "b908ffce2d26d94c58c968abf286568d4bcf87d1cfe6c994958351724a6f6988",
"size": 5719,
"subdir": "noarch",
"timestamp": 1613117294885,
"version": "0.1"
}
},
"packages.conda": {},
"removed": [],
"repodata_version": 1
}

View File

@ -0,0 +1,88 @@
<html>
<head>
<title>repo/noarch</title>
<style type="text/css">
a, a:active {
text-decoration: none; color: blue;
}
a:visited {
color: #48468F;
}
a:hover, a:focus {
text-decoration: underline; color: red;
}
body {
background-color: #F5F5F5;
}
h2 {
margin-bottom: 12px;
}
th, td {
font: 100% monospace; text-align: left;
}
th {
font-weight: bold; padding-right: 14px; padding-bottom: 3px;
}
td {
padding-right: 20px;
}
td.s, th.s {
text-align: right;
}
table {
background-color: white;
border-top: 1px solid #646464;
border-bottom: 1px solid #646464;
padding-top: 10px;
padding-bottom: 14px;
}
address {
color: #787878;
padding-top: 10px;
}
</style>
</head>
<body>
<h2>repo/noarch</h2>
<table>
<tr>
<th>Filename</th>
<th>Size</th>
<th>Last Modified</th>
<th>SHA256</th>
<th>MD5</th>
</tr>
<tr>
<td><a href="repodata.json" alt="repodata.json">repodata.json</a></td>
<td class="s">586 B</td>
<td>2021-02-12 09:01:48 +0000</td>
<td>cc5f72aaa8d3f508c8adca196fe05cf4b19e1ca1006cfcbb3892d73160bd3b04</td>
<td>7501ec77771889b42a39c615158cb9c4</td>
</tr> <tr>
<td><a href="repodata.json.bz2" alt="repodata.json.bz2">repodata.json.bz2</a></td>
<td class="s">351 B</td>
<td>2021-02-12 09:01:48 +0000</td>
<td>9a0288ca48c6b8caa348d7cafefd0981c2d25dcb4a5837a5187ab200b8b9fb45</td>
<td>0c926155642f0e894d97dc8a5af7007b</td>
</tr> <tr>
<td><a href="repodata_from_packages.json" alt="repodata_from_packages.json">repodata_from_packages.json</a></td>
<td class="s">586 B</td>
<td>2021-02-12 09:01:48 +0000</td>
<td>cc5f72aaa8d3f508c8adca196fe05cf4b19e1ca1006cfcbb3892d73160bd3b04</td>
<td>7501ec77771889b42a39c615158cb9c4</td>
</tr> <tr>
<td><a href="repodata_from_packages.json.bz2" alt="repodata_from_packages.json.bz2">repodata_from_packages.json.bz2</a></td>
<td class="s">351 B</td>
<td>2021-02-12 09:01:48 +0000</td>
<td>9a0288ca48c6b8caa348d7cafefd0981c2d25dcb4a5837a5187ab200b8b9fb45</td>
<td>0c926155642f0e894d97dc8a5af7007b</td>
</tr> <tr>
<td><a href="test-package-0.1-0.tar.bz2" alt="test-package-0.1-0.tar.bz2">test-package-0.1-0.tar.bz2</a></td>
<td class="s">6 KB</td>
<td>2021-02-12 08:08:14 +0000</td>
<td>b908ffce2d26d94c58c968abf286568d4bcf87d1cfe6c994958351724a6f6988</td>
<td>2a8595f37faa2950e1b433acbe91d481</td>
</tr> </table>
<address>Updated: 2021-02-12 09:02:37 +0000 - Files: 1</address>
</body>
</html>

View File

@ -0,0 +1,25 @@
{
"info": {
"subdir": "noarch"
},
"packages": {
"test-package-0.1-0.tar.bz2": {
"build": "0",
"build_number": 0,
"depends": [],
"license": "BSD",
"license_family": "BSD",
"md5": "2a8595f37faa2950e1b433acbe91d481",
"name": "test-package",
"noarch": "generic",
"sha256": "b908ffce2d26d94c58c968abf286568d4bcf87d1cfe6c994958351724a6f6988",
"size": 5719,
"subdir": "noarch",
"timestamp": 1613117294885,
"version": "0.1"
}
},
"packages.conda": {},
"removed": [],
"repodata_version": 1
}

View File

@ -0,0 +1,25 @@
{
"info": {
"subdir": "noarch"
},
"packages": {
"test-package-0.1-0.tar.bz2": {
"build": "0",
"build_number": 0,
"depends": [],
"license": "BSD",
"license_family": "BSD",
"md5": "2a8595f37faa2950e1b433acbe91d481",
"name": "test-package",
"noarch": "generic",
"sha256": "b908ffce2d26d94c58c968abf286568d4bcf87d1cfe6c994958351724a6f6988",
"size": 5719,
"subdir": "noarch",
"timestamp": 1613117294885,
"version": "0.1"
}
},
"packages.conda": {},
"removed": [],
"repodata_version": 1
}

View File

@ -0,0 +1,14 @@
package:
name: test-package
version: 0.1
build:
number: 0
script: echo Hello world
noarch: generic
about:
home: https://github.com/mamba-org/mamba
license: BSD
license_family: BSD
summary: I am just a test package!

View File

@ -0,0 +1,192 @@
import argparse
import base64
import os
import re
import sys
import http.server
class ChannelHandler(http.server.SimpleHTTPRequestHandler):
url_pattern = re.compile(r"^/(?:t/[^/]+/)?([^/]+)")
def do_GET(self) -> None:
# First extract channel name
channel_name = None
if tuple(channels.keys()) != (None,):
match = self.url_pattern.match(self.path)
if match:
channel_name = match.group(1)
# Strip channel for file server
start, end = match.span(1)
self.path = self.path[:start] + self.path[end:]
# Then dispatch to appropriate auth method
if channel_name in channels:
channel = channels[channel_name]
self.directory = channel["directory"]
auth = channel["auth"]
if auth == "none":
return super().do_GET()
elif auth == "basic":
server_key = base64.b64encode(
bytes(f"{channel['user']}:{channel['password']}", "utf-8")
).decode("ascii")
return self.basic_do_GET(server_key=server_key)
elif auth == "bearer":
return self.bearer_do_GET(server_key=channel["bearer"])
elif auth == "token":
return self.token_do_GET(server_token=channel["token"])
self.send_response(404)
def basic_do_HEAD(self) -> None:
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
def basic_do_AUTHHEAD(self) -> None:
self.send_response(401)
self.send_header("WWW-Authenticate", 'Basic realm="Test"')
self.send_header("Content-type", "text/html")
self.end_headers()
def bearer_do_GET(self, server_key: str) -> None:
auth_header = self.headers.get("Authorization", "")
print(auth_header)
print(f"Bearer {server_key}")
if not auth_header or auth_header != f"Bearer {server_key}":
self.send_response(403)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(b"no valid api key received")
else:
super().do_GET()
def basic_do_GET(self, server_key: str) -> None:
"""Present frontpage with basic user authentication."""
auth_header = self.headers.get("Authorization", "")
if not auth_header:
self.basic_do_AUTHHEAD()
self.wfile.write(b"no auth header received")
elif auth_header == "Basic " + server_key:
super().do_GET()
else:
self.basic_do_AUTHHEAD()
self.wfile.write(auth_header.encode("ascii"))
self.wfile.write(b"not authenticated")
token_pattern = re.compile("^/t/([^/]+?)/")
def token_do_GET(self, server_token: str) -> None:
"""Present frontpage with user authentication."""
match = self.token_pattern.search(self.path)
if match:
prefix_length = len(match.group(0)) - 1
new_path = self.path[prefix_length:]
found_token = match.group(1)
if found_token == server_token:
self.path = new_path
return super().do_GET()
self.send_response(403)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(b"no valid api key received")
global_parser = argparse.ArgumentParser(description="Start a multi-channel conda package server.")
global_parser.add_argument("-p", "--port", type=int, default=8000, help="Port to use.")
channel_parser = argparse.ArgumentParser(description="Start a simple conda package server.")
channel_parser.add_argument(
"-d",
"--directory",
type=str,
default=os.getcwd(),
help="Root directory for serving.",
)
channel_parser.add_argument(
"-n",
"--name",
type=str,
default=None,
help="Unique name of the channel used in URL",
)
channel_parser.add_argument(
"-a",
"--auth",
default=None,
type=str,
help="auth method (none, basic, token, or bearer)",
)
channel_parser.add_argument(
"--token",
type=str,
default=None,
help="Use token as API Key",
)
channel_parser.add_argument(
"--bearer",
type=str,
default=None,
help="Use bearer token as API Key",
)
channel_parser.add_argument(
"--user",
type=str,
default=None,
help="Use token as API Key",
)
channel_parser.add_argument(
"--password",
type=str,
default=None,
help="Use token as API Key",
)
# Gobal args can be given anywhere with the first set of args for backward compatibility.
args, argv_remaining = global_parser.parse_known_args()
PORT = args.port
# Iteratively parse arguments in sets.
# Each argument set, separated by -- in the CLI is for a channel.
# Credits: @hpaulj on SO https://stackoverflow.com/a/26271421
channels = {}
while argv_remaining:
args, argv_remaining = channel_parser.parse_known_args(argv_remaining)
# Drop leading -- to move to next argument set
argv_remaining = argv_remaining[1:]
# Consolidation
if not args.auth:
if args.user and args.password:
args.auth = "basic"
elif args.token:
args.auth = "token"
elif args.bearer:
args.auth = "bearer"
else:
args.auth = "none"
# name = args.name if args.name else Path(args.directory).name
# args.name = name
channels[args.name] = vars(args)
print(channels)
# Unamed channel in multi-channel case would clash URLs but we want to allow
# a single unamed channel for backward compatibility.
if (len(channels) > 1) and (None in channels):
print("Cannot use empty channel name when using multiple channels", file=sys.stderr)
exit(1)
server = http.server.HTTPServer(("", PORT), ChannelHandler)
print("Server started at localhost:" + str(PORT))
try:
server.serve_forever()
except Exception:
# Catch all sorts of interrupts
print("Shutting server down")
server.shutdown()
print("Server shut down")

View File

@ -9,12 +9,15 @@ from xprocess import ProcessStarter
from .helpers import create as umamba_create
from .helpers import login, logout, random_string
here = Path(__file__).absolute()
pyserver = here.parent.parent / "test-server" / "reposerver.py"
base_channel_directory = here.parent.parent / "test-server"
channel_a_directory = base_channel_directory / "channel_a"
channel_b_directory = base_channel_directory / "channel_b"
channel_r_directory = base_channel_directory / "repo"
__this_dir__ = Path(__file__).resolve().parent
server_dir = __this_dir__ / "test-server"
pyserver = server_dir / "reposerver.py"
channel_a_directory = server_dir / "channel_a"
channel_b_directory = server_dir / "channel_b"
channel_r_directory = server_dir / "repo"
print(pyserver)
assert pyserver.exists()