colibri-artifacts 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ """Command-line client for the Colibri Artifacts repository."""
@@ -0,0 +1,63 @@
1
+ import argparse
2
+ import json
3
+ import os
4
+ import re
5
+ from pathlib import Path
6
+
7
+ import httpx
8
+
9
+ from .client import ClientError, download, upload
10
+
11
+
12
+ def identifier(value: str) -> str:
13
+ if re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9._-]{0,127}", value) is None:
14
+ raise argparse.ArgumentTypeError(
15
+ "use 1-128 ASCII letters, digits, dots, underscores or hyphens; start with a letter or digit"
16
+ )
17
+ return value
18
+
19
+
20
+ def server_url(value: str) -> str:
21
+ try:
22
+ url = httpx.URL(value)
23
+ except httpx.InvalidURL as error:
24
+ raise argparse.ArgumentTypeError(str(error)) from error
25
+ if url.scheme not in {"http", "https"} or not url.host or url.query or url.fragment:
26
+ raise argparse.ArgumentTypeError("use an HTTP(S) server URL without query or fragment")
27
+ return str(url).rstrip("/") + "/"
28
+
29
+
30
+ def main(argv: list[str] | None = None) -> None:
31
+ parser = argparse.ArgumentParser(description="Upload and download Colibri Artifacts")
32
+ parser.add_argument(
33
+ "--server",
34
+ type=server_url,
35
+ default=os.environ.get("ARTIFACTS_URL", "http://127.0.0.1:8000"),
36
+ help="server URL (default: ARTIFACTS_URL or http://127.0.0.1:8000)",
37
+ )
38
+ commands = parser.add_subparsers(dest="command", required=True)
39
+ upload_parser = commands.add_parser("upload", help="upload a new, immutable version")
40
+ upload_parser.add_argument("project", type=identifier)
41
+ upload_parser.add_argument("version", type=identifier)
42
+ upload_parser.add_argument("file", type=Path)
43
+ download_parser = commands.add_parser("download", help="download a version or latest")
44
+ download_parser.add_argument("project", type=identifier)
45
+ download_parser.add_argument("version", type=identifier, nargs="?", default="latest")
46
+ download_parser.add_argument("-o", "--output", type=Path, help="destination file (must not exist)")
47
+ args = parser.parse_args(argv)
48
+ if args.command == "upload" and args.version == "latest":
49
+ parser.error("'latest' is reserved for downloads")
50
+ try:
51
+ with httpx.Client(base_url=args.server, timeout=60) as client:
52
+ if args.command == "upload":
53
+ print(json.dumps(upload(client, args.project, args.version, args.file)))
54
+ else:
55
+ print(download(client, args.project, args.version, args.output))
56
+ except httpx.HTTPStatusError as error:
57
+ parser.exit(1, f"Error: HTTP {error.response.status_code}: {error.response.text}\n")
58
+ except (httpx.RequestError, OSError, ClientError, json.JSONDecodeError) as error:
59
+ parser.exit(1, f"Error: {error or type(error).__name__}\n")
60
+
61
+
62
+ if __name__ == "__main__":
63
+ main()
@@ -0,0 +1,73 @@
1
+ import hashlib
2
+ import re
3
+ from email.message import Message
4
+ from email.utils import collapse_rfc2231_value
5
+ from pathlib import Path
6
+
7
+ import httpx
8
+
9
+
10
+ class ClientError(Exception):
11
+ pass
12
+
13
+
14
+ def _check_response(response: httpx.Response) -> None:
15
+ if not response.is_success:
16
+ response.read()
17
+ response.raise_for_status()
18
+
19
+
20
+ def upload(client: httpx.Client, project: str, version: str, source: Path) -> dict[str, object]:
21
+ with source.open("rb") as file:
22
+ response = client.post(
23
+ f"projects/{project}/versions/{version}",
24
+ files={"file": (source.name, file, "application/octet-stream")},
25
+ )
26
+ _check_response(response)
27
+ result = response.json()
28
+ if not isinstance(result, dict):
29
+ raise ClientError("Expected a JSON object in the upload response")
30
+ return result
31
+
32
+
33
+ def _filename(response: httpx.Response) -> str:
34
+ message = Message()
35
+ message["Content-Disposition"] = response.headers.get("content-disposition", "")
36
+ parameter = message.get_param("filename", header="content-disposition")
37
+ filename = collapse_rfc2231_value(parameter) if parameter is not None else None
38
+ if (
39
+ not filename
40
+ or filename in {".", ".."}
41
+ or Path(filename).drive
42
+ or any(character in filename for character in ("/", "\\"))
43
+ or any(ord(character) < 32 or ord(character) == 127 for character in filename)
44
+ ):
45
+ raise ClientError("The server returned a missing or unsafe filename; use --output")
46
+ return filename
47
+
48
+
49
+ def download(
50
+ client: httpx.Client, project: str, version: str, destination: Path | None
51
+ ) -> Path:
52
+ with client.stream("GET", f"projects/{project}/versions/{version}") as response:
53
+ _check_response(response)
54
+ expected = response.headers.get("x-checksum-sha256", "")
55
+ if re.fullmatch(r"[0-9a-fA-F]{64}", expected) is None:
56
+ raise ClientError("The server returned a missing or invalid SHA-256 checksum")
57
+ target = destination if destination is not None else Path(_filename(response))
58
+ digest = hashlib.sha256()
59
+ created = False
60
+ verified = False
61
+ try:
62
+ with target.open("xb") as output:
63
+ created = True
64
+ for chunk in response.iter_bytes(chunk_size=1024 * 1024):
65
+ output.write(chunk)
66
+ digest.update(chunk)
67
+ if digest.hexdigest() != expected.lower():
68
+ raise ClientError("SHA-256 mismatch; the incomplete download has been removed")
69
+ verified = True
70
+ return target
71
+ finally:
72
+ if created and not verified:
73
+ target.unlink()
@@ -0,0 +1,255 @@
1
+ Metadata-Version: 2.4
2
+ Name: colibri-artifacts
3
+ Version: 0.1.0
4
+ Summary: Command-line client for the Colibri Artifacts repository
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: httpx<1,>=0.27
8
+ Provides-Extra: publish
9
+ Requires-Dist: build<2,>=1.2; extra == "publish"
10
+ Requires-Dist: twine<7,>=6; extra == "publish"
11
+
12
+ # Colibri Artifacts
13
+
14
+ A command-line client and a separate HTTP server for arbitrary files,
15
+ not a package manager. **Only the client is intended for PyPI.** Installing the
16
+ client does not install or run the server.
17
+
18
+ An artifact is identified by **project + version**. Only one file can be uploaded
19
+ for each pair. The original filename is preserved and returned when downloading,
20
+ but is not used to look up the artifact.
21
+ `latest` means the project's most recently uploaded version, not the highest
22
+ SemVer version. Uploading an existing version is rejected; there are no API
23
+ methods to delete or modify artifacts.
24
+
25
+ ## Client installation
26
+
27
+ Requires Python 3.10+. To install the client from the repository root:
28
+
29
+ ```bash
30
+ python3 -m venv .venv
31
+ . .venv/bin/activate
32
+ pip install .
33
+ colibri-artifacts --help
34
+ ```
35
+
36
+ After the client has been published to PyPI, installation will be:
37
+
38
+ ```bash
39
+ pip install colibri-artifacts
40
+ ```
41
+
42
+ The package has **not been published yet**, and availability of the package
43
+ name has not been checked. Until then, install from source or a built wheel.
44
+ You can also run the client with `python -m colibri_artifacts`.
45
+
46
+ ### Configure the server
47
+
48
+ The client connects to `http://127.0.0.1:8000` by default. To use your server:
49
+
50
+ ```bash
51
+ export ARTIFACTS_URL=http://artifacts.internal:8000
52
+ ```
53
+
54
+ Alternatively, pass `--server` **before the subcommand**. It overrides
55
+ `ARTIFACTS_URL` for that invocation:
56
+
57
+ ```bash
58
+ colibri-artifacts --server http://artifacts.internal:8000 download my-service
59
+ ```
60
+
61
+ HTTP and HTTPS URLs are supported, including reverse proxy path prefixes such
62
+ as `https://artifacts.example.com/repository/`. TLS certificates are verified.
63
+ The client uses a 60-second timeout for network inactivity, not for the total
64
+ transfer duration.
65
+
66
+ ### Upload a file
67
+
68
+ ```bash
69
+ colibri-artifacts upload my-service 2026.11.26 ./build.tar.gz
70
+ ```
71
+
72
+ Arguments are `PROJECT VERSION FILE`. The client sends the file as multipart
73
+ form data, using its local basename as the original filename. It prints the
74
+ server's JSON metadata on success. A project does not need to be created first.
75
+ An existing project/version pair cannot be overwritten, even with identical
76
+ contents. `latest` is not a valid upload version.
77
+
78
+ ### Download a file
79
+
80
+ ```bash
81
+ # Download a specific version using the original filename in the current directory.
82
+ colibri-artifacts download my-service 2026.11.26
83
+
84
+ # Download the latest version; omitting VERSION also means latest.
85
+ colibri-artifacts download my-service latest
86
+ colibri-artifacts download my-service
87
+
88
+ # Choose a destination filename.
89
+ colibri-artifacts download my-service latest --output ./release.tar.gz
90
+ ```
91
+
92
+ Arguments are `PROJECT [VERSION]`; `-o` is an alias for `--output`.
93
+ The destination must not already exist, and its parent directory must exist.
94
+ Downloads are streamed to disk and verified against the server's SHA-256
95
+ checksum. A failed transfer or checksum mismatch removes the newly created
96
+ partial file. Existing local files are never overwritten.
97
+ Unsafe or missing server filenames are rejected unless an explicit output
98
+ path is supplied. On success, the client prints the destination path.
99
+
100
+ ### Errors and automation
101
+
102
+ Successful commands exit with code `0`. Network, HTTP, local filesystem,
103
+ response parsing, and checksum errors are written to stderr and exit with code
104
+ `1`. Invalid command-line arguments exit with code `2`.
105
+ Use an explicit version for reproducible CI jobs; `latest` changes when a new
106
+ version is successfully uploaded.
107
+
108
+ ## Server deployment
109
+
110
+ The server is separate from the client. It is installed from `server/` for
111
+ deployment or built into the Docker image; it is **not intended for PyPI**.
112
+ Requires Python 3.10+ and Linux with a local filesystem.
113
+ From the repository root, in a server-side virtual environment:
114
+
115
+ ```bash
116
+ pip install ./server
117
+ colibri-artifacts-server --storage /mnt/artifacts --host 127.0.0.1 --port 8000
118
+ ```
119
+
120
+ You can also run `python -m colibri_artifacts_server`.
121
+ The storage directory is created automatically; the process user must have
122
+ write permission. Instead of `--storage`, you can set the `ARTIFACTS_STORAGE`
123
+ environment variable (default: `./data`).
124
+ By default, the server listens only on `127.0.0.1:8000`.
125
+ Interactive API documentation: <http://127.0.0.1:8000/docs>.
126
+
127
+ **There is no authentication.** Anyone with access to the server can download
128
+ files and claim new versions, including by uploading arbitrary amounts of data.
129
+ Do not expose the port to the Internet; use a trusted network, firewall, or
130
+ reverse proxy with TLS, authentication, and request size limits.
131
+ To allow access from a trusted network, explicitly set `--host 0.0.0.0`.
132
+
133
+ ## HTTP API
134
+
135
+ The client wraps these endpoints; direct HTTP access is also supported.
136
+
137
+ Project and version identifiers must be 1–128 ASCII characters. The first
138
+ character must be a letter or digit; subsequent characters may also include
139
+ `.`, `_`, and `-`. Identifiers are case-sensitive.
140
+ `latest` is reserved and cannot be used for uploads.
141
+
142
+ ```bash
143
+ # Upload: multipart field named "file"; version can be any string in the format above.
144
+ curl --fail-with-body \
145
+ -F 'file=@./build.tar.gz' \
146
+ http://127.0.0.1:8000/projects/my-service/versions/2026.11.26
147
+
148
+ # Download a specific version, keeping the original filename.
149
+ curl --fail -OJ \
150
+ http://127.0.0.1:8000/projects/my-service/versions/2026.11.26
151
+
152
+ # Download the project's most recently uploaded version.
153
+ curl --fail -OJ \
154
+ http://127.0.0.1:8000/projects/my-service/versions/latest
155
+ ```
156
+
157
+ An upload returns `201` with `project`, `version`, `filename`, `size` in bytes,
158
+ and `sha256`. An existing version returns `409`, a missing artifact returns
159
+ `404`, an invalid request returns `422`, and delete or modification requests
160
+ return `405`. Path separators and control characters are not allowed in the
161
+ original filename.
162
+
163
+ Downloads include `Content-Disposition: attachment`, `X-Artifact-Version`,
164
+ `X-Checksum-SHA256`, and an `ETag` containing the SHA-256 checksum.
165
+ Responses for `latest` are not cached; specific immutable versions can be
166
+ cached. If uploads happen concurrently, `latest` is determined by the order in
167
+ which they are committed to the catalog.
168
+
169
+ ## Storage and durability
170
+
171
+ The `--storage` directory contains the SQLite catalog, `catalog.sqlite3`, and
172
+ the `objects` directory holding file contents. Stored objects have random
173
+ internal names; the original filename, including Unicode characters, is kept
174
+ in the catalog. Keep the entire storage directory on persistent storage or a
175
+ bind mount. Restarting the server does not change its contents.
176
+
177
+ An upload is first written to a temporary file and synced to disk. The object is
178
+ published without overwriting an existing file, and the catalog record is
179
+ committed in a transaction. Concurrent uploads of the same version result in
180
+ one success and conflicts for the others. A failed upload does not change
181
+ `latest`. Each operation uses its own SQLite connection; database locks
182
+ serialize upload commits.
183
+
184
+ This is **not WORM storage**: deletion is prevented through the HTTP API only.
185
+ An OS administrator or a process with write access to the disk can delete data.
186
+ Use separate storage protections and backups if stronger protection is needed.
187
+ After a crash, temporary or uncataloged objects may remain; they are not
188
+ accessible through the API. Objects are never deleted automatically.
189
+ For a consistent backup, stop the server and copy the **entire** storage
190
+ directory. Network filesystems (NFS/SMB) are not supported: this implementation
191
+ requires correct SQLite locking, hard links, and `fsync` on a local filesystem.
192
+ Multipart uploads may also use the system temporary directory, so ensure it
193
+ has enough free space or set `TMPDIR` before starting the process.
194
+
195
+ ## Docker Compose
196
+
197
+ The container runs as UID/GID `10001`. Prepare permissions for the bind mount:
198
+
199
+ ```bash
200
+ mkdir -p data
201
+ sudo chown 10001:10001 data
202
+ docker compose up -d --build
203
+ ```
204
+
205
+ Compose mounts `./data` at `/data` and publishes the port on localhost only.
206
+ To use a separate disk, replace `./data` with `/mnt/artifacts` in
207
+ `compose.yaml` and set permissions on that directory. For network access,
208
+ configure a reverse proxy or change the port binding while keeping appropriate
209
+ network restrictions.
210
+
211
+ ## Development and tests
212
+
213
+ Install both local packages to run the client tests, server tests, and their
214
+ integration test. This does not publish either package.
215
+
216
+ ```bash
217
+ pip install -e . -e ./server
218
+ python -m unittest discover -s tests -v
219
+ ```
220
+
221
+ To run only the client tests, the server package is not required:
222
+
223
+ ```bash
224
+ python -m unittest discover -s tests -p test_client.py -v
225
+ ```
226
+
227
+ ## Publishing the client to PyPI
228
+
229
+ Build and upload **only the root project**, not `server/`.
230
+ The root distribution contains the client and depends on HTTPX, not FastAPI,
231
+ Uvicorn, or the server package. The server distribution is marked
232
+ `Private :: Do Not Upload` to prevent accidental uploads to PyPI.
233
+
234
+ The client package is prepared for publishing but **has not been published**.
235
+ The name `colibri-artifacts` is provisional; its availability has not been
236
+ checked. Before publishing publicly, choose a license, add it to the project,
237
+ and make sure you are allowed to publish the repository's contents.
238
+ If the name is taken, change `project.name` in `pyproject.toml`.
239
+
240
+ ```bash
241
+ pip install '.[publish]'
242
+ python -m build --outdir dist/client
243
+ python -m twine check dist/client/*
244
+ python -m twine upload dist/client/*
245
+ ```
246
+
247
+ Use a clean `dist/client` directory for each release, and increment the version
248
+ in the root `pyproject.toml` before publishing a new release. PyPI does not allow
249
+ replacing already published distributions.
250
+ Publishing requires your PyPI account and a token or Trusted Publishing.
251
+ Do not store the token in the repository. After publishing under the chosen name:
252
+
253
+ ```bash
254
+ pip install colibri-artifacts
255
+ ```
@@ -0,0 +1,8 @@
1
+ colibri_artifacts/__init__.py,sha256=RJD8RWat3RN6nwZmful2T1bo-JAkylRiRYesAPRHvvA,64
2
+ colibri_artifacts/__main__.py,sha256=2L-kk5SRfXiDLmLgSSTWwwD_eiU5NstAqwT9VPiFTp8,2660
3
+ colibri_artifacts/client.py,sha256=4t9e0qY1AyraKVbyBpaRLO6ioRfbGWoDyqleB1uhk_0,2675
4
+ colibri_artifacts-0.1.0.dist-info/METADATA,sha256=YDq-D7aOO50SE4sVYLDjGUaHVZntSNbIY-TAy0GT55U,10141
5
+ colibri_artifacts-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ colibri_artifacts-0.1.0.dist-info/entry_points.txt,sha256=wWrzhxSUObaPTDMjcA4i6Tl5NOnCcHjx60JhqsnlGVk,70
7
+ colibri_artifacts-0.1.0.dist-info/top_level.txt,sha256=6-L8slO1BIJt0Mfxoagr8O8a0YJvVwqeFmfGPe1nBnU,18
8
+ colibri_artifacts-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ colibri-artifacts = colibri_artifacts.__main__:main
@@ -0,0 +1 @@
1
+ colibri_artifacts