withcache 0.13.1__tar.gz → 0.13.3__tar.gz

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.
Files changed (49) hide show
  1. {withcache-0.13.1 → withcache-0.13.3}/PKG-INFO +1 -1
  2. {withcache-0.13.1 → withcache-0.13.3}/shim/build.zig.zon +1 -1
  3. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/__init__.py +1 -1
  4. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_api.py +36 -5
  5. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/client.py +4 -1
  6. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/server.py +21 -8
  7. {withcache-0.13.1 → withcache-0.13.3}/tests/test_fastapi_catalog_api.py +73 -0
  8. {withcache-0.13.1 → withcache-0.13.3}/.gitignore +0 -0
  9. {withcache-0.13.1 → withcache-0.13.3}/LICENSE +0 -0
  10. {withcache-0.13.1 → withcache-0.13.3}/README.md +0 -0
  11. {withcache-0.13.1 → withcache-0.13.3}/deploy/Containerfile +0 -0
  12. {withcache-0.13.1 → withcache-0.13.3}/deploy/compose.local-build.yml +0 -0
  13. {withcache-0.13.1 → withcache-0.13.3}/deploy/compose.yml +0 -0
  14. {withcache-0.13.1 → withcache-0.13.3}/deploy/envvars.example +0 -0
  15. {withcache-0.13.1 → withcache-0.13.3}/hatch_build.py +0 -0
  16. {withcache-0.13.1 → withcache-0.13.3}/pyproject.toml +0 -0
  17. {withcache-0.13.1 → withcache-0.13.3}/shim/build.zig +0 -0
  18. {withcache-0.13.1 → withcache-0.13.3}/shim/shim.zig +0 -0
  19. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_app.py +0 -0
  20. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_events_log.py +0 -0
  21. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_settings_store.py +0 -0
  22. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_shim.py +0 -0
  23. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_table_state.py +0 -0
  24. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_templates/ui/_layout.html +0 -0
  25. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_templates/ui/_table_macros.html +0 -0
  26. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_templates/ui/catalog.html +0 -0
  27. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_templates/ui/dashboard.html +0 -0
  28. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_templates/ui/events.html +0 -0
  29. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_templates/ui/login.html +0 -0
  30. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_templates/ui/misses.html +0 -0
  31. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/_templates/ui/settings.html +0 -0
  32. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/curlwithcache.py +0 -0
  33. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/oras.py +0 -0
  34. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/static/bootstrap-icons.min.css +0 -0
  35. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/static/bootstrap.min.css +0 -0
  36. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/static/fonts/bootstrap-icons.woff +0 -0
  37. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/static/fonts/bootstrap-icons.woff2 +0 -0
  38. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/static/htmx.min.js +0 -0
  39. {withcache-0.13.1 → withcache-0.13.3}/src/withcache/wgetwithcache.py +0 -0
  40. {withcache-0.13.1 → withcache-0.13.3}/tests/test_differential.py +0 -0
  41. {withcache-0.13.1 → withcache-0.13.3}/tests/test_fastapi_admin_forms.py +0 -0
  42. {withcache-0.13.1 → withcache-0.13.3}/tests/test_fastapi_blob.py +0 -0
  43. {withcache-0.13.1 → withcache-0.13.3}/tests/test_fastapi_events.py +0 -0
  44. {withcache-0.13.1 → withcache-0.13.3}/tests/test_fastapi_scaffold.py +0 -0
  45. {withcache-0.13.1 → withcache-0.13.3}/tests/test_fastapi_settings_persistence.py +0 -0
  46. {withcache-0.13.1 → withcache-0.13.3}/tests/test_fastapi_ui_pages.py +0 -0
  47. {withcache-0.13.1 → withcache-0.13.3}/tests/test_fastapi_uvicorn_smoke.py +0 -0
  48. {withcache-0.13.1 → withcache-0.13.3}/tests/test_oras.py +0 -0
  49. {withcache-0.13.1 → withcache-0.13.3}/tests/test_withcache.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: withcache
3
- Version: 0.13.1
3
+ Version: 0.13.3
4
4
  Summary: Operator-curated, URL-keyed artifact cache for a small lab (CUDA/ROCm/DOCA/firmware)
5
5
  Project-URL: Homepage, https://github.com/safl/withcache
6
6
  Author-email: "Simon A. F. Lund" <safl@safl.dk>
@@ -2,7 +2,7 @@
2
2
  .name = .withcache_shim,
3
3
  // Zig requires a literal here; keep it in lockstep with the project's
4
4
  // single source (src/withcache/__init__.py) via `make bump` / `make version-check`.
5
- .version = "0.13.1",
5
+ .version = "0.13.3",
6
6
  .fingerprint = 0xd7d96c5ed212ccaa,
7
7
  .minimum_zig_version = "0.16.0",
8
8
  .paths = .{
@@ -22,6 +22,6 @@ inherit the framework floor.
22
22
  from . import oras
23
23
  from .client import blob_url, cache_base, is_cached, serve_url
24
24
 
25
- __version__ = "0.13.1"
25
+ __version__ = "0.13.3"
26
26
 
27
27
  __all__ = ["__version__", "blob_url", "cache_base", "is_cached", "oras", "serve_url"]
@@ -234,9 +234,29 @@ def register_api_routes(app: FastAPI) -> None:
234
234
  entries_out: list[dict[str, Any]] = []
235
235
  for e in cs.entries:
236
236
  fetch_url = e.get("resolved_src") or e.get("src") or ""
237
- if not fetch_url or store.get_blob(fetch_url) is None:
237
+ if not fetch_url:
238
238
  continue
239
- entries_out.append(dict(e))
239
+ blob = store.get_blob(fetch_url)
240
+ if blob is None:
241
+ continue
242
+ out = dict(e)
243
+ # Enrich with the downloaded blob's authoritative sha256 +
244
+ # size. The catalog TOML may or may not carry these (nosi's
245
+ # gen_catalog omits them at emit time because the blob
246
+ # digest isn't known until the artifact is packed); the
247
+ # blob store computed both during the actual download so
248
+ # the /catalog response is the right place to surface
249
+ # them. Bty consumes ``sha256`` to gate machine binds --
250
+ # without this enrichment a downloaded-but-unhashed entry
251
+ # can never satisfy bty's ``^[0-9a-f]{64}$`` ref check
252
+ # and the whole ramboot flow deadlocks.
253
+ blob_sha = blob["sha256"]
254
+ if isinstance(blob_sha, str) and blob_sha and not out.get("sha256"):
255
+ out["sha256"] = blob_sha
256
+ blob_size = blob["size"]
257
+ if isinstance(blob_size, int) and blob_size > 0 and not out.get("size_bytes"):
258
+ out["size_bytes"] = blob_size
259
+ entries_out.append(out)
240
260
  return JSONResponse(
241
261
  {
242
262
  "url": cs.url,
@@ -256,9 +276,19 @@ def register_api_routes(app: FastAPI) -> None:
256
276
  """Insert one catalog entry.
257
277
 
258
278
  Body: ``{"name": "...", "src": "...", "format?", "arch?",
259
- "sha256?", "size_bytes?", "resolved_src?", "description?"}``.
260
- Only ``src`` is required; every other field is optional and
261
- gets persisted through the ``catalog.toml`` round-trip.
279
+ "sha256?", "size_bytes?", "resolved_src?", "description?",
280
+ "netboot_ref?"}``. Only ``src`` is required; every other
281
+ field is optional and gets persisted through the
282
+ ``catalog.toml`` round-trip.
283
+
284
+ ``netboot_ref`` names another catalog entry (by ``name``)
285
+ whose bytes are a nosi netboot bundle (vmlinuz + initrd +
286
+ manifest) that nbdmux extracts at warm time so bty can
287
+ ramboot the image using its own kernel. Present iff the
288
+ entry is a disk image that has a matching netboot bundle;
289
+ the bundle entry itself never carries a ``netboot_ref``.
290
+ Withcache does not validate that the referenced entry
291
+ exists -- the sibling may be added in either order.
262
292
 
263
293
  409 when an entry with the same ``name`` already exists;
264
294
  rejecting on duplicate name (not src) because the display
@@ -278,6 +308,7 @@ def register_api_routes(app: FastAPI) -> None:
278
308
  "sha256",
279
309
  "size_bytes",
280
310
  "description",
311
+ "netboot_ref",
281
312
  }
282
313
  if not isinstance(body, dict):
283
314
  raise HTTPException(status_code=400, detail="body must be a JSON object")
@@ -221,7 +221,10 @@ def add_catalog_entry(
221
221
 
222
222
  ``entry`` must carry at least ``name`` + ``src``. Optional
223
223
  fields: ``format``, ``arch``, ``sha256``, ``size_bytes``,
224
- ``resolved_src``, ``description``.
224
+ ``resolved_src``, ``description``, ``netboot_ref`` (name of
225
+ a sibling entry carrying the matching nosi netboot bundle;
226
+ consumed by nbdmux to serve vmlinuz + initrd alongside the
227
+ disk-image export).
225
228
 
226
229
  Raises :class:`WithcacheError` on any HTTP failure (409 if the
227
230
  entry name already exists; 401 if auth is enabled and no valid
@@ -147,18 +147,31 @@ def _serialise_catalog(entries: list[dict[str, Any]]) -> bytes:
147
147
  row can't smuggle arbitrary TOML through.
148
148
 
149
149
  Scalar keys emitted: ``name``, ``src``, ``resolved_src``,
150
- ``format``, ``arch``, ``sha256``, ``description``. Integer:
151
- ``size_bytes``. ``resolved_src`` is the canonical fetch URL
152
- (for ``oras://`` refs; equal to ``src`` for plain HTTPS);
153
- bty needs it to render iPXE flash chains against the byte
154
- URL directly. ``description`` is operator-supplied prose so
155
- the /ui/images page has something better than the URL to
156
- display.
150
+ ``format``, ``arch``, ``sha256``, ``description``,
151
+ ``netboot_ref``. Integer: ``size_bytes``. ``resolved_src`` is
152
+ the canonical fetch URL (for ``oras://`` refs; equal to
153
+ ``src`` for plain HTTPS); bty needs it to render iPXE flash
154
+ chains against the byte URL directly. ``description`` is
155
+ operator-supplied prose so the /ui/images page has something
156
+ better than the URL to display. ``netboot_ref`` names a
157
+ sibling catalog entry carrying the matching nosi netboot
158
+ bundle (kernel + initrd) so nbdmux can pair the disk image
159
+ with its own kernel at warm time; see the ``add_catalog_entry``
160
+ docstring in ``_api.py`` for the pairing story.
157
161
  """
158
162
  out: list[str] = ["version = 1", ""]
159
163
  for e in entries:
160
164
  out.append("[[images]]")
161
- for key in ("name", "src", "resolved_src", "format", "arch", "sha256", "description"):
165
+ for key in (
166
+ "name",
167
+ "src",
168
+ "resolved_src",
169
+ "format",
170
+ "arch",
171
+ "sha256",
172
+ "description",
173
+ "netboot_ref",
174
+ ):
162
175
  val = e.get(key)
163
176
  if val is None or val == "":
164
177
  continue
@@ -122,6 +122,63 @@ class ListCatalogTests(_CatalogApiBase):
122
122
  self.assertEqual(entries[0]["sha256"], "a" * 64)
123
123
  self.assertEqual(entries[0]["description"], "downloaded")
124
124
 
125
+ def test_list_enriches_sha256_and_size_from_blob_store(self) -> None:
126
+ """A catalog TOML entry whose bytes are downloaded but that
127
+ omits ``sha256`` / ``size_bytes`` (nosi's gen_catalog does
128
+ exactly this: the OCI blob digest and content-length aren't
129
+ knowable at TOML-emit time) must still surface those two
130
+ fields in ``GET /catalog`` -- withcache computed them during
131
+ the download and stashed them in the blob row.
132
+
133
+ Bty's ``bty_image_ref`` regex is ``^[0-9a-f]{64}$``; without
134
+ this enrichment a downloaded-but-not-hashed entry can never
135
+ satisfy the check and the ramboot machine bind 422s. Pin the
136
+ wire so a future regression fails the test suite instead of
137
+ the deploy.
138
+ """
139
+ self.catalog.entries = [
140
+ {
141
+ "name": "no-sha-in-toml",
142
+ "src": "https://example/toml-quiet.img.gz",
143
+ "format": "img.gz",
144
+ "resolved_src": "https://example/toml-quiet.img.gz",
145
+ }
146
+ ]
147
+ self._seed_store_row("https://example/toml-quiet.img.gz", "b" * 64)
148
+
149
+ r = self.client.get("/catalog")
150
+ self.assertEqual(r.status_code, 200)
151
+ entries = r.json()["entries"]
152
+ self.assertEqual(len(entries), 1)
153
+ self.assertEqual(entries[0]["sha256"], "b" * 64)
154
+ # ``_seed_store_row`` writes 1024-byte blob rows.
155
+ self.assertEqual(entries[0]["size_bytes"], 1024)
156
+
157
+ def test_list_does_not_overwrite_toml_provided_sha256(self) -> None:
158
+ """When the catalog TOML already carries ``sha256`` (e.g. a
159
+ future gen_catalog that emits it), the enrichment path must
160
+ not clobber the operator-declared value with the blob's
161
+ computed one. The TOML value wins. Same for ``size_bytes``.
162
+ """
163
+ toml_sha = "c" * 64
164
+ blob_sha = "d" * 64
165
+ self.catalog.entries = [
166
+ {
167
+ "name": "declared-sha",
168
+ "src": "https://example/declared.img.gz",
169
+ "format": "img.gz",
170
+ "sha256": toml_sha,
171
+ "size_bytes": 42,
172
+ "resolved_src": "https://example/declared.img.gz",
173
+ }
174
+ ]
175
+ self._seed_store_row("https://example/declared.img.gz", blob_sha)
176
+
177
+ r = self.client.get("/catalog")
178
+ entries = r.json()["entries"]
179
+ self.assertEqual(entries[0]["sha256"], toml_sha)
180
+ self.assertEqual(entries[0]["size_bytes"], 42)
181
+
125
182
  def _seed_store_row(self, url: str, sha256: str) -> None:
126
183
  """Insert a blobs row for ``url`` so ``store.get_blob`` returns
127
184
  it; skips the actual file write because ``list_catalog`` only
@@ -167,12 +224,28 @@ class AddCatalogEntryTests(_CatalogApiBase):
167
224
  "sha256": "b" * 64,
168
225
  "size_bytes": 2048,
169
226
  "description": "Debian sysdev",
227
+ "netboot_ref": "debian-netboot",
170
228
  },
171
229
  )
172
230
  self.assertEqual(r.status_code, 201, r.text)
173
231
  stored = self.catalog.entries[0]
174
232
  self.assertEqual(stored["description"], "Debian sysdev")
175
233
  self.assertEqual(stored["resolved_src"], "https://example/debian.img.gz")
234
+ self.assertEqual(stored["netboot_ref"], "debian-netboot")
235
+
236
+ def test_netboot_ref_persists_through_toml_round_trip(self) -> None:
237
+ """netboot_ref must survive the catalog.toml write-then-reload."""
238
+ self.client.post(
239
+ "/catalog/entries",
240
+ json={
241
+ "name": "debian",
242
+ "src": "https://example/debian.img.gz",
243
+ "netboot_ref": "debian-netboot",
244
+ },
245
+ )
246
+ toml_path = os.path.join(self._tmpdir, "catalog.toml")
247
+ content = open(toml_path, encoding="utf-8").read()
248
+ self.assertIn('netboot_ref = "debian-netboot"', content)
176
249
 
177
250
  def test_add_persists_to_disk(self) -> None:
178
251
  self.client.post(
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes