From 742a414872ed225fba08ccd6906c8a45e10c1078 Mon Sep 17 00:00:00 2001 From: Ray Walker Date: Fri, 27 Nov 2026 19:46:46 +1100 Subject: [PATCH 1/3] feat(backends): native Google Cloud Storage backend Add GCSBackend, installed with the `gcs` extra and selected by `backend=` or CACHEKIT_GCS_BUCKET. Each entry is one object holding the bytes the file backend writes, under the file backend's name for the key, so the two backends read each other's entries. Authentication is Application Default Credentials. A read is one download, `exists` a ranged read of the 14-byte header, and a write one upload. An expired or corrupt entry is deleted by the read that finds it, conditionally on the generation it read, so a newer entry survives. No request is retried: errors map to BackendErrorType for the circuit breaker. The backend turns off the client library's background bucket-metadata fetch on its own client: it issues a bucket-level get on first use and after every 404, and a cache miss is a 404. The emulator integration tests run on push, started by .github/scripts/start-fake-gcs.sh with the image pinned by digest. --- .github/scripts/start-fake-gcs.sh | 44 ++ .github/workflows/ci.yml | 10 + README.md | 32 +- docs/README.md | 2 + docs/api-reference.md | 2 +- docs/backends/README.md | 17 +- docs/backends/gcs.md | 190 ++++++ docs/configuration.md | 35 +- docs/getting-started.md | 27 +- llms.txt | 25 +- pyproject.toml | 4 + src/cachekit/backends/__init__.py | 9 +- src/cachekit/backends/gcs/__init__.py | 26 + src/cachekit/backends/gcs/backend.py | 231 +++++++ src/cachekit/backends/gcs/config.py | 95 +++ src/cachekit/backends/gcs/error_handler.py | 80 +++ src/cachekit/backends/provider.py | 18 +- src/cachekit/decorators/wrapper.py | 4 +- .../test_backend_config_consistency.py | 9 +- tests/fixtures/zero_config.py | 8 +- tests/integration/test_gcs_integration.py | 278 ++++++++ tests/unit/backends/test_gcs_backend.py | 603 ++++++++++++++++++ tests/unit/backends/test_gcs_config.py | 62 ++ tests/unit/backends/test_provider.py | 40 ++ tests/unit/test_l1_only_mode.py | 8 +- uv.lock | 370 ++++++++++- 26 files changed, 2201 insertions(+), 28 deletions(-) create mode 100644 .github/scripts/start-fake-gcs.sh create mode 100644 docs/backends/gcs.md create mode 100644 src/cachekit/backends/gcs/__init__.py create mode 100644 src/cachekit/backends/gcs/backend.py create mode 100644 src/cachekit/backends/gcs/config.py create mode 100644 src/cachekit/backends/gcs/error_handler.py create mode 100644 tests/integration/test_gcs_integration.py create mode 100644 tests/unit/backends/test_gcs_backend.py create mode 100644 tests/unit/backends/test_gcs_config.py diff --git a/.github/scripts/start-fake-gcs.sh b/.github/scripts/start-fake-gcs.sh new file mode 100644 index 000000000..ebcb14a6d --- /dev/null +++ b/.github/scripts/start-fake-gcs.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# Start the CI Google Cloud Storage emulator (fake-gcs-server) on http://localhost:4443 as +# container `fake-gcs`, storing objects in memory. Point a client at it with +# STORAGE_EMULATOR_HOST=http://localhost:4443. +# The image is pinned by digest, so the registry only carries the bytes: the +# daemon verifies them against the digest wherever they come from. Each +# registry's anonymous quota is per source IP and hosted runners share IPs, so +# the pull walks FAKE_GCS_REPOS in order, twice, and uses the first that serves it. +# +# CI: bash .github/scripts/start-fake-gcs.sh +# Local: bash .github/scripts/start-fake-gcs.sh (needs docker and a free port 4443) +# Test: put a stub `docker` first on PATH; FAKE_GCS_DIGEST / FAKE_GCS_REPOS override the pin. +set -u + +# fsouza/fake-gcs-server 1.56.1 multi-arch index, resolved 2026-11-27. +# Every registry listed serves this digest. Renovate does not bump it. +FAKE_GCS_DIGEST=${FAKE_GCS_DIGEST:-sha256:797ce226d62f947c009dc40246b30cfb456b8473d8241407f9d6f2c04e4d69ef} +FAKE_GCS_REPOS=${FAKE_GCS_REPOS:-mirror.gcr.io/fsouza/fake-gcs-server docker.io/fsouza/fake-gcs-server} + +image= +for round in 1 2; do + for repo in $FAKE_GCS_REPOS; do + if timeout 120 docker pull "$repo@$FAKE_GCS_DIGEST"; then image=$repo@$FAKE_GCS_DIGEST; break 2; fi + done + [ "$round" = 1 ] && sleep 15 +done +[ -n "$image" ] || { echo "::error::no registry served fake-gcs-server@${FAKE_GCS_DIGEST} (tried: ${FAKE_GCS_REPOS})"; exit 1; } + +docker run -d --name fake-gcs -p 4443:4443 "$image" \ + -scheme http -port 4443 -backend memory -public-host localhost:4443 || exit 1 + +# Ready when the server lists buckets on the published port. The 30s deadline +# covers the probes too, so a server that never comes up, or accepts but never +# answers, fails this step instead of hanging the job. +deadline=$((SECONDS + 30)) +while [ "$SECONDS" -lt "$deadline" ]; do + if curl --silent --fail --max-time 2 --output /dev/null http://127.0.0.1:4443/storage/v1/b; then + exit 0 + fi + sleep 1 +done +echo "::error::fake-gcs-server did not answer on 127.0.0.1:4443 within 30s" +docker logs fake-gcs +exit 1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c2f2705f..a5afd9317 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -161,6 +161,12 @@ jobs: if: github.event_name == 'push' run: bash .github/scripts/start-memcached.sh + # Push runs only: tests/integration/test_gcs_integration.py skips its whole module when + # nothing answers on localhost:4443. + - name: Start the GCS emulator + if: github.event_name == 'push' + run: bash .github/scripts/start-fake-gcs.sh + - name: Run full test suite (main) if: github.event_name == 'push' env: @@ -186,6 +192,10 @@ jobs: if: github.event_name == 'push' run: python3 .github/scripts/assert-junit-ran.py junit.xml tests.integration.test_memcached_integration + - name: Check the GCS integration tests ran + if: github.event_name == 'push' + run: python3 .github/scripts/assert-junit-ran.py junit.xml tests.integration.test_gcs_integration + # Executable docs are tests: docstring examples, tests/docs/ and the docs/ # markdown blocks. None of them sit under tests/unit or tests/critical, so # the runs above never collect them. diff --git a/README.md b/README.md index d55864e2c..25ee0dea1 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ backend that fits your infrastructure — they're peers behind the same `@cache` | Redis | Self-hosted, full control | `REDIS_URL` / `CACHEKIT_REDIS_URL` | | CacheKit Cloud | Managed, zero-ops (closed beta) | `CACHEKIT_API_KEY` | | Memcached | High-throughput, existing infra | `CACHEKIT_MEMCACHED_SERVERS` | +| Google Cloud Storage | Durable results on Cloud Run and jobs, no server | `CACHEKIT_GCS_BUCKET` | | File / L1-only | Local dev, tests, no external deps | `CACHEKIT_FILE_CACHE_DIR` / nothing (or `backend=None`) | ```bash @@ -157,6 +158,28 @@ def expensive_api_call(user_id: int): +
+Google Cloud Storage — Optional + +```python notest +from cachekit import cache +from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + +# pip install cachekit[gcs] + +backend = GCSBackend(GCSBackendConfig(bucket="my-cache-bucket")) # Application Default Credentials + +@cache(backend=backend, ttl=3600) +def expensive_api_call(user_id: int): + return fetch_user_data(user_id) +``` + +One object per entry, in the file backend's format. See [Google Cloud Storage Backend](docs/backends/gcs.md) for IAM and the bucket lifecycle rule. + +*Requires: `pip install cachekit[gcs]` or `uv add cachekit[gcs]`* + +
+ --- > **CacheKit Cloud (Closed Beta)** @@ -294,7 +317,7 @@ Hosted runners come with other CPU models too: in a run of an earlier commit, an - Connection pooling with thread affinity - The CacheKit Cloud backend keeps idle connections pooled until the server closes them, with TCP keepalive probes, so a request after a pause skips a new TLS handshake - Distributed locking guards against cache stampedes across pods, best effort (async functions, on a backend that supports it) -- Pluggable backend abstraction (Redis, CacheKit Cloud, File, Memcached, custom) +- Pluggable backend abstraction (Redis, CacheKit Cloud, File, Memcached, Google Cloud Storage, custom) - Untrusted-decode bounds: nesting depth and header-declared allocation are capped on every cache read (a forged entry is a bounded cache miss), verified against the protocol's shared [`decode-bounds.json`](https://github.com/cachekit-io/protocol/blob/42ea601f3c1656df0a06904afa2406604f43f57d/test-vectors/decode-bounds.json) vectors > [!NOTE] @@ -520,7 +543,7 @@ info = expensive_func.cache_info() ```bash # Backend selection: set exactly ONE of CACHEKIT_REDIS_URL, CACHEKIT_API_KEY, -# CACHEKIT_MEMCACHED_SERVERS, CACHEKIT_FILE_CACHE_DIR. Two or more is a ConfigurationError at +# CACHEKIT_MEMCACHED_SERVERS, CACHEKIT_FILE_CACHE_DIR, CACHEKIT_GCS_BUCKET. Two or more is a ConfigurationError at # first call, and decorators relying on env auto-detection run uncached (docs/backends/README.md). # REDIS_URL is only a fallback and never conflicts. With none of them set, decorators cache # L1-only, in process (encrypted decorators still use localhost Redis; interop decorators refuse @@ -541,6 +564,11 @@ CACHEKIT_MEMCACHED_CONNECT_TIMEOUT=2.0 # Default: 2.0 seconds CACHEKIT_MEMCACHED_TIMEOUT=1.0 # Default: 1.0 seconds CACHEKIT_MEMCACHED_KEY_PREFIX="myapp:" # Default: "" (none) +# Google Cloud Storage Backend (optional: pip install cachekit[gcs]; Application Default Credentials) +# CACHEKIT_GCS_BUCKET="my-cache-bucket" # Required to select it +CACHEKIT_GCS_PREFIX="cachekit/" # Default: "" (bucket root) +CACHEKIT_GCS_TIMEOUT=10.0 # Default: 10.0 seconds + # Optional Configuration CACHEKIT_MAX_VALUE_SIZE=104857600 CACHEKIT_ARROW_COMPRESSION=zstd diff --git a/docs/README.md b/docs/README.md index 1e16dca65..91d7c9e50 100644 --- a/docs/README.md +++ b/docs/README.md @@ -29,6 +29,7 @@ Choose your storage backend: | [Redis](backends/redis.md) | Self-hosted, production-grade, connection pooling | | [File](backends/file.md) | Local filesystem, zero dependencies | | [Memcached](backends/memcached.md) | High-throughput, consistent hashing | +| [Google Cloud Storage](backends/gcs.md) | Durable, one object per entry, no server | | [CacheKit Cloud](backends/cachekitio.md) | Managed, zero infrastructure | | [L1-Only (None)](backends/none.md) | In-memory only, no external services | | [Custom](backends/custom.md) | Implement your own backend | @@ -88,6 +89,7 @@ docs/ │ ├── README.md # Backend overview (auto-rendered) │ ├── redis.md, file.md # Built-in backends │ ├── memcached.md, cachekitio.md # Optional backends +│ ├── gcs.md # Google Cloud Storage (optional) │ ├── none.md # L1-only mode │ └── custom.md # Custom backend guide │ diff --git a/docs/api-reference.md b/docs/api-reference.md index 63bcfc67a..15781278e 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -711,7 +711,7 @@ For error examples and handling patterns, see [Troubleshooting Guide](troublesho ## Backend Abstraction -cachekit uses a protocol-based backend abstraction (PEP 544) that allows pluggable storage backends for L2 cache. Built-in backends include Redis, CacheKit Cloud, File, and Memcached. You can also implement custom backends for any key-value store. +cachekit uses a protocol-based backend abstraction (PEP 544) that allows pluggable storage backends for L2 cache. Built-in backends include Redis, CacheKit Cloud, File, Memcached, and Google Cloud Storage. You can also implement custom backends for any key-value store. For comprehensive backend guide with examples and implementation patterns, see **[Backend Guide](backends/README.md)**. diff --git a/docs/backends/README.md b/docs/backends/README.md index bef458a55..d4eac6606 100644 --- a/docs/backends/README.md +++ b/docs/backends/README.md @@ -2,7 +2,7 @@ # Backend Guide -Pluggable L2 cache storage for cachekit. Four backends are included out of the box — Redis, File (local), Memcached, and CacheKit Cloud (managed). With no backend configured, a plaintext decorator runs in [L1-only mode](none.md), as `backend=None` does; encrypted and interop decorators still need a backend ([Nothing Configured](#4-nothing-configured-l1-only)). You can also implement custom backends for any key-value store. +Pluggable L2 cache storage for cachekit. Five backends are included out of the box — Redis, File (local), Memcached, Google Cloud Storage, and CacheKit Cloud (managed). With no backend configured, a plaintext decorator runs in [L1-only mode](none.md), as `backend=None` does; encrypted and interop decorators still need a backend ([Nothing Configured](#4-nothing-configured-l1-only)). You can also implement custom backends for any key-value store. ## Overview @@ -98,6 +98,7 @@ class BaseBackend(Protocol): | **[File](file.md)** | set = fsync + a scan of every entry, so slow on a large cache; get waits on a concurrent set ([cost model](file.md#performance-characteristics)) | Yes (disk) | Format shared; one writer process | Yes | File locks | | **[Redis](redis.md)** | One network round trip per operation ([not measured here](../performance.md#not-measured-here)) | Yes (RDB/AOF) | Yes | Yes | Yes | | **[Memcached](memcached.md)** | One network round trip per operation ([not measured here](../performance.md#not-measured-here)) | No | Yes | Yes (max 30d) | No | +| **[Google Cloud Storage](gcs.md)** | One HTTPS request to GCS per operation ([not measured here](../performance.md#not-measured-here)) | Yes | Yes | Yes (checked on read) | No | | **[CacheKit Cloud](cachekitio.md)** | 42–45ms p50 hit, measured from MEL ([varies by vantage](cachekitio.md#characteristics)) | Yes | Yes | Yes | Yes | | **[HTTP (custom)](custom.md)** | One HTTP request per operation ([not measured here](../performance.md#not-measured-here)) | Varies | Yes | Varies | Varies | | **[DynamoDB (custom)](custom.md)** | One DynamoDB API request per operation ([not measured here](../performance.md#not-measured-here)) | Yes | Yes | Yes | No | @@ -106,6 +107,8 @@ class BaseBackend(Protocol): `TTLInspectableBackend` protocol): supported by **File**, **Redis**, and **CacheKit Cloud**. **Memcached** supports `refresh_ttl` (via `touch`) directly but not `get_ttl`, so `refresh_ttl_on_get` does not apply to it (see [Memcached](memcached.md#ttl-inspection--refresh)). +**Google Cloud Storage** supports neither: an object cannot be edited in place +(see [Google Cloud Storage](gcs.md#limitations)). **Cross-process whole-function invalidation** (a server-side key registry, via the `KeyTrackableBackend` protocol): supported only by the tenant-scoped **Redis** backend that env @@ -134,6 +137,11 @@ calling process knows (see [Whole-Function Invalidation](../features/l1-invalida - Existing Memcached infrastructure you want to reuse - Read-heavy workloads where a network round trip on each L1 miss is acceptable ([not measured here](../performance.md#not-measured-here)) +**Use [GCSBackend](gcs.md) when**: +- The workload runs on Cloud Run, Cloud Functions or batch jobs, with no Redis and no disk that survives a run +- The cached call is expensive and its result is worth keeping for hours or days +- A round trip to GCS on each L1 miss is acceptable ([not measured here](../performance.md#not-measured-here)) + **Use [CacheKit Cloud](cachekitio.md) (`CachekitIOBackend`) when** *(closed beta: sign-up is by waitlist at [dash.cachekit.io](https://dash.cachekit.io))*: - You want managed, zero-ops distributed caching - Multi-region caching without operating Redis @@ -220,7 +228,7 @@ it builds its own `CachekitIOBackend` and never consults `set_default_backend()` If no explicit backend and no module-level default, `DefaultBackendProvider` picks a backend at the function's first call from the one environment selector that is -set. The four prefixed selectors are mutually exclusive, with no precedence between them: +set. The five prefixed selectors are mutually exclusive, with no precedence between them: set exactly one. | Environment variable | Backend | @@ -229,6 +237,7 @@ set exactly one. | `CACHEKIT_REDIS_URL` | Redis (tenant-scoped, keys prefixed `t:{tenant}:`) | | `CACHEKIT_MEMCACHED_SERVERS`| `MemcachedBackend` | | `CACHEKIT_FILE_CACHE_DIR` | `FileBackend` | +| `CACHEKIT_GCS_BUCKET` | `GCSBackend` | | none of the above: `REDIS_URL` | Redis, as above | | nothing set at all | plaintext, non-interop decorators: [L1-only](#4-nothing-configured-l1-only), no backend; secure and `encryption=True` decorators: Redis at `redis://localhost:6379`, tenant-scoped as above; `interop=` decorators: the same Redis, which interop refuses (see below) | @@ -237,7 +246,7 @@ set exactly one. `backend=RedisBackend()` instead ([Interop Mode](../features/interop-mode.md)). A `CachekitIOBackend` from `CACHEKIT_API_KEY` prefixes nothing and serves interop as resolved. -Setting more than one of the four `CACHEKIT_*` selectors is ambiguous and raises +Setting more than one of the five `CACHEKIT_*` selectors is ambiguous and raises `ConfigurationError` at first call. The decorator catches it, logs a WARNING on the `cachekit.decorators.orchestrator` logger, and runs the function uncached: @@ -415,6 +424,7 @@ first call (and runs uncached if nothing listens there): give it `backend=RedisB | **HTTP API** | One HTTP request per operation ([not measured here](../performance.md#not-measured-here)) | Custom cloud services | Network dependent | | **DynamoDB** | One DynamoDB API request per operation ([not measured here](../performance.md#not-measured-here)) | Serverless, low-traffic | High availability | | **Memcached** | One network round trip per operation ([not measured here](../performance.md#not-measured-here)) | Alternative to Redis | No persistence | +| **Google Cloud Storage** | One HTTPS request to GCS per operation ([not measured here](../performance.md#not-measured-here)) | Expensive results kept across runs, no server | No locking; expiry checked on read | --- @@ -423,6 +433,7 @@ first call (and runs uncached if nothing listens there): give it `backend=RedisB - [Redis Backend](redis.md) — Production-grade, shared cache - [File Backend](file.md) — Local disk, single-process, no infrastructure - [Memcached Backend](memcached.md) — High-throughput, volatile, multi-process +- [Google Cloud Storage Backend](gcs.md) — Durable, one object per entry, no server - [CacheKit Cloud Backend](cachekitio.md) — Managed, zero-ops, zero-knowledge - [Custom Backends](custom.md) — HTTP, DynamoDB, and your own implementations diff --git a/docs/backends/gcs.md b/docs/backends/gcs.md new file mode 100644 index 000000000..c5bc390fd --- /dev/null +++ b/docs/backends/gcs.md @@ -0,0 +1,190 @@ +**[Home](../README.md)** › **[Backends](README.md)** › **Google Cloud Storage Backend** + +# Google Cloud Storage Backend + +> Requires: `pip install cachekit[gcs]` + +Store each cache entry as one object in a Google Cloud Storage bucket. Durable, shared across processes and machines, and needs no server to run: a fit for jobs and services that keep no local disk between runs and have no Redis. + +## Basic Usage + +```python notest +from cachekit import cache +from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + +backend = GCSBackend(GCSBackendConfig(bucket="my-cache-bucket")) + +@cache(backend=backend, ttl=3600) +def cached_function(): + return expensive_computation() +``` + +Or select it from the environment, with no `backend=`: + +```bash +export CACHEKIT_GCS_BUCKET="my-cache-bucket" +``` + +`CACHEKIT_GCS_BUCKET` is a backend selector like `CACHEKIT_REDIS_URL` or `CACHEKIT_FILE_CACHE_DIR`: set exactly one of them ([Backend Resolution Priority](README.md#backend-resolution-priority)). + +## Configuration via Environment Variables + +```bash +export CACHEKIT_GCS_BUCKET="my-cache-bucket" # Required. A bucket name, not a gs:// URL +export CACHEKIT_GCS_PREFIX="cachekit/" # Default: "" (objects at the bucket root) +export CACHEKIT_GCS_PROJECT="my-project" # Default: none. Object reads and writes need no project +export CACHEKIT_GCS_TIMEOUT=10.0 # Default: 10.0 seconds (range: 0.1-600.0) +``` + +## Configuration via Python + +Config objects need neither credentials nor the `gcs` extra: + +```python +from cachekit.backends.gcs import GCSBackendConfig + +config = GCSBackendConfig( + bucket="my-cache-bucket", + prefix="cachekit/", + timeout=5.0, +) +``` + +`timeout` is how long to wait for a connection, and between bytes of a response. It is not a +deadline for the whole request. + +## Authentication + +The backend authenticates with [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials) and has no credential settings of its own: + +- **On Google Cloud** (Cloud Run, GKE, Compute Engine, Cloud Functions): the service account attached to the workload. Nothing to configure. +- **On your machine**: `gcloud auth application-default login`. + +A missing credential raises an AUTHENTICATION `BackendError` when the backend is built. Under `@cache` with env selection, that degrades like any other backend failure: the function runs uncached. + +## IAM + +Grant the identity `roles/storage.objectUser` on the bucket: + +```bash +gcloud storage buckets add-iam-policy-binding gs://my-cache-bucket \ + --member="serviceAccount:my-app@my-project.iam.gserviceaccount.com" \ + --role="roles/storage.objectUser" +``` + +That role is enough. The backend reads, writes, deletes and lists objects, and never reads the bucket's own metadata, so it needs no `storage.buckets.get`. The bucket must already exist: the backend does not create it. + +If you write a custom role instead, it needs `storage.objects.get`, `storage.objects.create`, `storage.objects.delete` and `storage.objects.list`. Without `storage.objects.list`, GCS answers a read of an absent object with 403 instead of 404, so every cache miss raises an AUTHENTICATION `BackendError`. An identity that can only read (`roles/storage.objectViewer`) serves hits and misses; it cannot store entries or delete expired ones. + +## Object Names and the Prefix + +An entry's object name is the prefix followed by 32 hex characters, the BLAKE2b-128 hash of the cache key: + +``` + +cachekit/0e2a03b49262c15a063c04d5a29c0158 +``` + +The prefix is used verbatim, so end it with `/` if you want a folder. It is a storage location only, like the file backend's `cache_dir`: it does not change the cache key, and two backends with different prefixes on one bucket never see each other's entries. + +The object holds the bytes the [File backend](file.md) writes for the same key, value and expiry: the [file-backend format](https://github.com/cachekit-io/protocol/blob/main/spec/file-backend-format.md) of the CacheKit protocol, a 14-byte header that carries the expiry, then the payload. A cache directory copied into the bucket with `gcloud storage cp`, or a bucket prefix copied to a directory, stays readable from the other backend. + +## Expiry and the Lifecycle Rule + +Expiry lives in each object's header and is checked when the entry is read. An expired entry is a miss, and the `get` that finds it deletes it. An entry nobody reads again is never deleted by cachekit, so give the bucket a lifecycle rule as a backstop, with an `age` above your longest TTL (here 8 days, for TTLs of up to 7): + +```json +{ + "rule": [ + { + "action": {"type": "Delete"}, + "condition": {"age": 8, "matchesPrefix": ["cachekit/"]} + } + ] +} +``` + +```bash +gcloud storage buckets update gs://my-cache-bucket --lifecycle-file=lifecycle.json +``` + +`age` is in days and counts from when the object was written. Drop `matchesPrefix` when the bucket holds nothing else. + +> [!WARNING] +> The rule deletes by age alone. An entry cached with no TTL, or with a TTL longer than `age`, is deleted when it reaches `age` and becomes a miss. + +## Requests per Operation + +| Operation | Requests | +|-----------|----------| +| `get` | One download. A hit, a miss and an absent object each cost one request; an expired or corrupt entry costs a second, to delete it. | +| `set` | One upload that replaces the object. An entry above 8 MiB is a resumable upload of two requests. | +| `exists` | One ranged read of the 14-byte header. | +| `delete` | One delete. | +| `health_check()` | One listing of at most one object under the prefix. | + +No request is retried. A failed request raises a `BackendError`: + +| Failure | `BackendErrorType` | +|---------|--------------------| +| HTTP 401, 403; credentials missing or refused | `AUTHENTICATION` | +| HTTP 429, 5xx; connection failed | `TRANSIENT` | +| Timeout; HTTP 408 | `TIMEOUT` | +| Any other HTTP error, such as a bucket that does not exist | `PERMANENT` | + +A 404 for an object is not an error: `get` returns `None` and `delete` returns `False`. Under `@cache`, a failed read is a miss and the function runs, and a failed write skips the backend only. + +## When to Use + +**Use GCSBackend when**: +- The workload runs on Cloud Run, Cloud Functions or batch jobs: no local disk that survives, no Redis +- The cached call is expensive (seconds, or money) and its result is worth keeping for hours or days +- Several machines should share results, and a round trip to GCS on each L1 miss is acceptable + +**When NOT to use**: +- Hot paths that need low-latency reads: every L1 miss is an HTTPS request to GCS (use [Redis](redis.md) or [Memcached](memcached.md)) +- You need distributed locking for stampede protection (use [Redis](redis.md) or [CacheKit Cloud](cachekitio.md)) +- You need sliding expiration via `refresh_ttl_on_get` (see [Limitations](#limitations)) +- Many small, short-lived entries: each write is a billed GCS operation + +## Characteristics + +- Latency: one HTTPS request to GCS per operation, which depends on your network and region ([not measured here](../performance.md#not-measured-here)) +- TTL support: Yes, checked on read; no upper bound below the file format's 10 years +- Cross-process: Yes (shared by every process that can reach the bucket) +- Persistence: Yes +- Thread-safe: Yes. Threads may share one backend +- Fork: build the backend after `fork()`, not before + +## Limitations + +1. **No TTL inspection or refresh.** A GCS object cannot be edited in place, so refreshing a TTL would rewrite the whole entry. The backend is not a `TTLInspectableBackend`: `refresh_ttl_on_get` does not apply to it (the decorator warns once and serves the hit). +2. **No locking.** No distributed lock, so no cross-process stampede protection. +3. **Last writer wins.** Two processes that store the same key at once each upload a whole object, and the later upload replaces the earlier one. A reader sees one or the other, never a mix. +4. **Whole-function invalidation is per process.** `invalidate_cache()` with no arguments deletes only the keys the calling process knows ([Whole-Function Invalidation](../features/l1-invalidation.md#whole-function-invalidation)). +5. **No eviction or size cap.** The bucket grows until entries are read after they expire or the lifecycle rule deletes them. +6. **Encrypted entries are not bound to their location.** `@cache.secure` binds each entry to its cache key. The bucket and the prefix are not part of that binding, as with the file backend's directory. + +## Testing Against an Emulator + +The client honours `STORAGE_EMULATOR_HOST`, so the backend runs unchanged against [fake-gcs-server](https://github.com/fsouza/fake-gcs-server), with no credentials: + +```bash +bash .github/scripts/start-fake-gcs.sh +STORAGE_EMULATOR_HOST=http://localhost:4443 uv run pytest tests/integration/test_gcs_integration.py +``` + +## See Also + +- [Backend Guide](README.md) — Backend comparison and resolution priority +- [File Backend](file.md) — The same entry format on local disk +- [Redis Backend](redis.md) — Low-latency shared caching with locking support +- [Configuration Guide](../configuration.md) — Full environment variable reference + +--- + +
+ +**[GitHub Issues](https://github.com/cachekit-io/cachekit-py/issues)** · **[Documentation](../README.md)** + +
diff --git a/docs/configuration.md b/docs/configuration.md index a66d41ab2..6a782e511 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -11,7 +11,7 @@ ## Backend Options -cachekit supports four backends. Pick the one that fits your infrastructure: +cachekit supports five backends. Pick the one that fits your infrastructure: | Backend | Best For | Required Config | |---------|----------|----------------| @@ -19,8 +19,9 @@ cachekit supports four backends. Pick the one that fits your infrastructure: | CacheKit Cloud | Managed, zero-ops | `CACHEKIT_API_KEY` | | File | Local dev, testing | None | | Memcached | High-throughput, existing infra | `CACHEKIT_MEMCACHED_SERVERS` | +| Google Cloud Storage | Durable results on Cloud Run and jobs, no server | `CACHEKIT_GCS_BUCKET` | -`@cache` picks its backend from env vars at a function's first call; with nothing configured it caches L1-only, in process, and connects to nothing ([details](backends/README.md#4-nothing-configured-l1-only)). CacheKit Cloud is a managed alternative (currently in closed beta). File backend is intended for local development and testing only. Memcached is an optional backend (`pip install cachekit[memcached]`). +`@cache` picks its backend from env vars at a function's first call; with nothing configured it caches L1-only, in process, and connects to nothing ([details](backends/README.md#4-nothing-configured-l1-only)). CacheKit Cloud is a managed alternative (currently in closed beta). File backend is intended for local development and testing only. Memcached is an optional backend (`pip install cachekit[memcached]`), and so is Google Cloud Storage (`pip install cachekit[gcs]`). ### Redis Backend @@ -59,6 +60,14 @@ High-throughput in-memory caching with consistent hashing across multiple server **Configuration:** See the [Memcached Backend](#memcached-backend-environment-variables) section below. +### Google Cloud Storage Backend + +> Requires: `pip install cachekit[gcs]` + +One object per cache entry in a GCS bucket, authenticated with Application Default Credentials. See [Google Cloud Storage Backend](backends/gcs.md) for IAM and the bucket lifecycle rule. + +**Configuration:** See the [Google Cloud Storage Backend](#google-cloud-storage-backend-environment-variables) section below. + --- ## Environment Variables @@ -248,6 +257,26 @@ CACHEKIT_MEMCACHED_RETRY_ATTEMPTS=2 # Default: 2 (range: 0-10) CACHEKIT_MEMCACHED_KEY_PREFIX="myapp:" # Default: "" (none) ``` +### Google Cloud Storage Backend Environment Variables + +> Requires: `pip install cachekit[gcs]` or `uv add cachekit[gcs]` + +```bash +# Bucket that holds the entries (required; a bucket name, not a gs:// URL). Setting it selects the backend +CACHEKIT_GCS_BUCKET=my-cache-bucket + +# Object-name prefix, used verbatim (default: "", the bucket root). A storage location only +CACHEKIT_GCS_PREFIX=cachekit/ + +# Google Cloud project passed to the storage client (default: none; object reads and writes need no project) +CACHEKIT_GCS_PROJECT=my-project + +# Seconds to wait for a connection, and between bytes of a response (default: 10.0, range: 0.1-600.0) +CACHEKIT_GCS_TIMEOUT=10.0 +``` + +There is no credential variable: the backend uses [Application Default Credentials](backends/gcs.md#authentication). + --- ## L1 Cache Configuration @@ -411,7 +440,7 @@ def secure_function(): > [!IMPORTANT] > When multiple environment variables could apply, cachekit follows this priority order. -> The four backend selectors are the exception: they have no order, so set exactly one +> The five backend selectors are the exception: they have no order, so set exactly one > ([details](backends/README.md#3-environment-variable-auto-detection)). ### Redis URL Priority diff --git a/docs/getting-started.md b/docs/getting-started.md index 2814cda9b..a07f2a67d 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -23,7 +23,7 @@ ## Quick Start CacheKit provides a unified caching API with pluggable backends. You write `@cache` -once; the backend (Redis, CacheKit Cloud, Memcached, or File / L1-only) is selected from +once; the backend (Redis, CacheKit Cloud, Memcached, Google Cloud Storage, or File / L1-only) is selected from your environment. See [Choose Your Backend](#choose-your-backend) for the full menu. With nothing configured, `@cache` caches in L1 only, in process, like `lru_cache`. It @@ -252,13 +252,14 @@ export CACHEKIT_CONNECTION_POOL_SIZE=50 ## Choose Your Backend -Four paths depending on your situation: +Five paths depending on your situation: | Backend | When to use | Setup effort | |:--------|:------------|:-------------| | **Redis** (recommended) | Production, existing infra, full control | Medium — run Redis yourself | | **CacheKit Cloud** (closed beta) | Skip Redis ops, managed edge caching | Low — API key only | | **Memcached** (optional) | High-throughput, existing Memcached infra | Low — `pip install cachekit[memcached]` | +| **Google Cloud Storage** (optional) | Cloud Run and jobs: durable results, no server | Low — `pip install cachekit[gcs]` and a bucket | | **File / L1-only** | Local dev, tests, no external deps | None | ### Redis (Recommended) @@ -322,6 +323,28 @@ def get_user(user_id: int): Everything else — TTL, namespaces, serializers — works the same as with Redis. See the [Backend Guide](backends/README.md) for multi-server configuration. +### Google Cloud Storage (Optional) + +One object per cache entry in a bucket you own. Durable and shared, with no server to run; each L1 miss is a request to GCS. + +```bash +pip install cachekit[gcs] +# Auth: Application Default Credentials (the workload's service account, or gcloud auth application-default login) +``` + +```python notest +from cachekit import cache +from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + +backend = GCSBackend(GCSBackendConfig(bucket="my-cache-bucket")) + +@cache(backend=backend, ttl=3600) +def get_user(user_id: int): + return fetch_from_db(user_id) +``` + +See [Google Cloud Storage Backend](backends/gcs.md) for IAM and the bucket lifecycle rule. + ### File / L1-Only (Dev and Testing) No external dependencies. Pure in-process memory cache. Not suitable for multi-pod or production. diff --git a/llms.txt b/llms.txt index a897cf658..b4e776b7e 100644 --- a/llms.txt +++ b/llms.txt @@ -1,8 +1,8 @@ # cachekit -> Caching for Python, TypeScript and Rust, with opt-in zero-knowledge encryption, circuit breakers and stampede protection. This is the Python SDK: intent-based decorators with distributed locking, Prometheus metrics and AES-256-GCM encryption on a Rust-powered core. Zero-config L1 in-memory; scales to Redis, Memcached, File, or CacheKit Cloud. +> Caching for Python, TypeScript and Rust, with opt-in zero-knowledge encryption, circuit breakers and stampede protection. This is the Python SDK: intent-based decorators with distributed locking, Prometheus metrics and AES-256-GCM encryption on a Rust-powered core. Zero-config L1 in-memory; scales to Redis, Memcached, File, Google Cloud Storage, or CacheKit Cloud. -cachekit provides decorator-based caching with circuit breaker, distributed locking, Prometheus metrics, L1+L2 dual-layer caching, and optional zero-knowledge encryption. Supports 4 built-in backends (Redis, Memcached, File, CacheKit Cloud) plus custom backends via the BaseBackend protocol. +cachekit provides decorator-based caching with circuit breaker, distributed locking, Prometheus metrics, L1+L2 dual-layer caching, and optional zero-knowledge encryption. Supports 5 built-in backends (Redis, Memcached, File, Google Cloud Storage, CacheKit Cloud) plus custom backends via the BaseBackend protocol. ## Quick Start @@ -30,13 +30,14 @@ def get_patient(id: int): ## Backends -4 built-in backends, all implementing the BaseBackend protocol (get/set/delete/exists/health_check): +5 built-in backends, all implementing the BaseBackend protocol (get/set/delete/exists/health_check): | Backend | Install | Use Case | |---------|---------|----------| | **Redis** | included | Production, distributed | | **Memcached** | `pip install cachekit[memcached]` | High-throughput, existing infra | | **File** | included | Single-machine, zero-dependency | +| **Google Cloud Storage** | `pip install cachekit[gcs]` | Durable shared cache with no server (Cloud Run, jobs) | | **CacheKit Cloud** (`CachekitIOBackend`) | included | Managed, zero infrastructure (closed beta) | ### Redis @@ -74,6 +75,19 @@ def cached_fn(): return data ``` +### Google Cloud Storage +```python +from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + +# Environment: CACHEKIT_GCS_BUCKET=my-cache-bucket (auth: Application Default Credentials) +config = GCSBackendConfig(bucket="my-cache-bucket", prefix="cachekit/") +backend = GCSBackend(config) + +@cache(backend=backend, ttl=3600) +def cached_fn(): + return data +``` + ### CacheKit Cloud (managed, closed beta) ```python # Environment: CACHEKIT_API_KEY=your-api-key @@ -139,6 +153,10 @@ CACHEKIT_MEMCACHED_KEY_PREFIX=myapp: CACHEKIT_FILE_CACHE_DIR=/tmp/cache CACHEKIT_FILE_MAX_SIZE_MB=500 +# Google Cloud Storage (auth: Application Default Credentials) +CACHEKIT_GCS_BUCKET=my-cache-bucket +CACHEKIT_GCS_PREFIX=cachekit/ + # CacheKit Cloud CACHEKIT_API_KEY=your-api-key CACHEKIT_API_URL=https://api.cachekit.io @@ -164,6 +182,7 @@ CACHEKIT_MASTER_KEY=hex-encoded-32-byte-key - [Redis](docs/backends/redis.md): Recommended production backend - [File](docs/backends/file.md): Local filesystem caching - [Memcached](docs/backends/memcached.md): High-throughput caching +- [Google Cloud Storage](docs/backends/gcs.md): One object per entry, file-backend format, IAM and lifecycle rule - [CacheKit Cloud](docs/backends/cachekitio.md): Managed backend (closed beta) - [Custom Backends](docs/backends/custom.md): Implement BaseBackend diff --git a/pyproject.toml b/pyproject.toml index fba271151..2efe25791 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,6 +94,9 @@ json = [ memcached = [ "pymemcache>=4.0.0", ] +gcs = [ + "google-cloud-storage>=3.0.0", +] [project.urls] Homepage = "https://github.com/cachekit-io/cachekit-py" @@ -264,6 +267,7 @@ dev = [ # ArrowSerializer return_format="polars" tests (zero-copy column aliasing). Not in `test`: # polars ships abi3 wheels only, which a free-threaded interpreter cannot install. "polars>=2.0.0", + "google-cloud-storage>=3.0.0", ] # Linux CI only - Atheris requires libFuzzer (not available on macOS without building LLVM) fuzz = [ diff --git a/src/cachekit/backends/__init__.py b/src/cachekit/backends/__init__.py index d960f2030..7e567ac1b 100644 --- a/src/cachekit/backends/__init__.py +++ b/src/cachekit/backends/__init__.py @@ -16,6 +16,7 @@ - CapabilityNotAvailableError: Exception for missing optional capabilities - RedisBackend: Redis implementation - MemcachedBackend: Memcached implementation (requires pymemcache) + - GCSBackend: Google Cloud Storage implementation (requires google-cloud-storage) Usage: >>> from cachekit.backends import BaseBackend, RedisBackend, BackendError @@ -47,6 +48,7 @@ ) if TYPE_CHECKING: + from cachekit.backends.gcs import GCSBackend from cachekit.backends.memcached import MemcachedBackend from cachekit.backends.redis import RedisBackend @@ -64,6 +66,7 @@ "CapabilityNotAvailableError", "RedisBackend", "MemcachedBackend", + "GCSBackend", ] @@ -109,7 +112,7 @@ def get_backend(self) -> BaseBackend: def __getattr__(name: str): - """Lazy imports: pymemcache may not be installed, and redis-py loads only for a program that uses Redis. + """Lazy imports: pymemcache or google-cloud-storage may not be installed, and redis-py loads only for a program that uses Redis. Loading redis-py loads hiredis, which re-enables the GIL on a free-threaded build, so ``import cachekit`` must not load it (see cachekit.hiredis_compat). @@ -122,4 +125,8 @@ def __getattr__(name: str): from cachekit.backends.memcached import MemcachedBackend return MemcachedBackend + if name == "GCSBackend": + from cachekit.backends.gcs import GCSBackend + + return GCSBackend raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/src/cachekit/backends/gcs/__init__.py b/src/cachekit/backends/gcs/__init__.py new file mode 100644 index 000000000..c89668b05 --- /dev/null +++ b/src/cachekit/backends/gcs/__init__.py @@ -0,0 +1,26 @@ +"""Google Cloud Storage backend for cachekit. + +Stores each cache entry as one GCS object, in the bytes and under the name the file backend +uses, and authenticates with Application Default Credentials. Requires the ``gcs`` extra: +``pip install 'cachekit[gcs]'``. + +Public API: + - GCSBackend: Main backend implementation + - GCSBackendConfig: Configuration class + +Example: + >>> from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + >>> config = GCSBackendConfig(bucket="my-cache-bucket", prefix="cachekit/") + >>> backend = GCSBackend(config) # doctest: +SKIP + >>> backend.set("key", b"value", ttl=60) # doctest: +SKIP +""" + +from __future__ import annotations + +from cachekit.backends.gcs.backend import GCSBackend +from cachekit.backends.gcs.config import GCSBackendConfig + +__all__ = [ + "GCSBackend", + "GCSBackendConfig", +] diff --git a/src/cachekit/backends/gcs/backend.py b/src/cachekit/backends/gcs/backend.py new file mode 100644 index 000000000..245c34a51 --- /dev/null +++ b/src/cachekit/backends/gcs/backend.py @@ -0,0 +1,231 @@ +"""Google Cloud Storage backend implementation for cachekit. + +One GCS object per cache entry, in the file backend's entry format: a 14-byte header that carries +the expiry, then the payload, named by the BLAKE2b-128 hex of the cache key. Implements +BaseBackend protocol. +""" + +from __future__ import annotations + +import hashlib +import logging +import struct +import time +from typing import Any + +# The entry format has one definition, the file backend's: an object this backend writes is the +# file that backend would write, so the header is built and judged by the same code. +from cachekit.backends.file.backend import FORMAT_VERSION, HEADER_SIZE, MAGIC, FileBackend, _has_unknown_transform +from cachekit.backends.gcs.config import GCSBackendConfig +from cachekit.backends.gcs.error_handler import classify_gcs_error +from cachekit.hash_utils import redact_error_for_log + +_logger = logging.getLogger(__name__) + +_CONTENT_TYPE = "application/octet-stream" + + +def _build_client(project: str | None) -> Any: + """A storage client on Application Default Credentials. + + With ``project=None`` the client has no project, and does not look for one: reading and + writing objects needs none, and credentials do not always carry one. + + Raises: + ImportError: If google-cloud-storage is not installed. + """ + try: + from google.cloud import storage + except ImportError as exc: + raise ImportError("GCSBackend requires google-cloud-storage. Install it with: pip install 'cachekit[gcs]'") from exc + return storage.Client(project=project) + + +class GCSBackend: + """Google Cloud Storage backend implementing BaseBackend protocol. + + Each entry is one object named ````, holding the bytes the + file backend would write for the same key, value and expiry. Expiry is checked on read: an + expired entry is a miss, and the read deletes it. An entry nobody reads again stays until a + bucket lifecycle rule removes it (see docs/backends/gcs.md). + + Authentication is Application Default Credentials only. No request is retried: a failed + request raises a ``BackendError`` and the next call tries again. + + Examples: + Create a backend (requires credentials and a bucket): + + >>> from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + >>> backend = GCSBackend(GCSBackendConfig(bucket="my-cache-bucket")) # doctest: +SKIP + >>> backend.set("key", b"value", ttl=60) # doctest: +SKIP + >>> backend.get("key") # doctest: +SKIP + b'value' + >>> backend.delete("key") # doctest: +SKIP + True + """ + + def __init__(self, config: GCSBackendConfig | None = None) -> None: + """Initialize GCSBackend. Builds the client and sends no request. + + Args: + config: Optional configuration. Defaults to loading from environment. + + Raises: + ImportError: If google-cloud-storage is not installed. + BackendError: If Application Default Credentials cannot be found. + """ + self._config = config or GCSBackendConfig.from_env() + try: + self._client = _build_client(self._config.project) + except ImportError: + raise + except Exception as exc: + raise classify_gcs_error(exc, operation="init") from exc + # google-cloud-storage fetches each bucket's metadata in a background thread, to label its + # trace spans, and re-checks the bucket after every 404. A cache miss is a 404, and both + # are bucket-level gets, which an identity that can only read and write objects is denied. + self._client._bucket_metadata_cache = None + self._bucket = self._client.bucket(self._config.bucket) # a handle: no bucket-level request + self._prefix = self._config.prefix + self._timeout = self._config.timeout + + def _blob(self, key: str) -> Any: + """Handle for the key's object: the prefix, then the file backend's name for the key.""" + return self._bucket.blob(self._prefix + hashlib.blake2b(key.encode("utf-8"), digest_size=16).hexdigest()) + + def _discard(self, blob: Any) -> None: + """Delete an expired or corrupt object that a read just saw. Best effort: the read is a miss either way. + + The delete is conditional on the generation the read saw, so an entry a writer stored in + between survives. A failure (a read-only identity, a lost race) is logged and dropped. + """ + try: + blob.delete(if_generation_match=blob.generation, timeout=self._timeout, retry=None) + except Exception as exc: + _logger.debug("GCS cleanup of a dead entry failed: %s", redact_error_for_log(exc)) + + def _read(self, operation: str, key: str, header_only: bool) -> bytes | None: + """Download the key's entry in one request, or its header alone; None for a miss. + + Raises: + BackendError: If the request fails for any reason but the object being absent. + """ + from google.api_core.exceptions import NotFound, RequestRangeNotSatisfiable + + blob = self._blob(key) + try: + data: bytes = blob.download_as_bytes( + end=HEADER_SIZE - 1 if header_only else None, + timeout=self._timeout, + retry=None, + ) + except NotFound: + return None + except RequestRangeNotSatisfiable: + data = b"" # an empty object has no byte range to serve: truncated, like any short header + except Exception as exc: + raise classify_gcs_error(exc, operation=operation, key=key) from exc + + header = data[:HEADER_SIZE] + if len(header) < HEADER_SIZE or header[0:2] != MAGIC or header[2] != FORMAT_VERSION: + self._discard(blob) # corrupt + return None + if _has_unknown_transform(header): + return None # a transform this reader does not implement: a miss, object left untouched + expiry_timestamp = struct.unpack(">Q", header[6:14])[0] + if expiry_timestamp > 0 and time.time() >= expiry_timestamp: + self._discard(blob) + return None + return data + + def get(self, key: str) -> bytes | None: + """Retrieve value from Google Cloud Storage, in one download request. + + Args: + key: Cache key to retrieve. + + Returns: + Bytes value if found and not expired, None otherwise. + + Raises: + BackendError: If the request fails. + """ + data = self._read("get", key, header_only=False) + return None if data is None else data[HEADER_SIZE:] + + def set(self, key: str, value: bytes, ttl: int | None = None) -> None: + """Store value in Google Cloud Storage, replacing the key's object in one upload. + + An entry of up to 8 MiB goes in a single request. A larger one is a resumable upload of + two requests; the object is replaced only when the second completes. + + Args: + key: Cache key to store. + value: Bytes value to store. + ttl: Time-to-live in seconds. None or 0 means no expiry. + + Raises: + BackendError: If the TTL is out of range or the upload fails. + """ + body = FileBackend._build_header(FileBackend._expiry_from_ttl(ttl)) + value + try: + self._blob(key).upload_from_string(body, content_type=_CONTENT_TYPE, timeout=self._timeout, retry=None) + except Exception as exc: + raise classify_gcs_error(exc, operation="set", key=key) from exc + + def delete(self, key: str) -> bool: + """Delete key from Google Cloud Storage. + + Args: + key: Cache key to delete. + + Returns: + True if the object existed and was deleted, False if it did not exist. + + Raises: + BackendError: If the request fails. + """ + from google.api_core.exceptions import NotFound + + try: + self._blob(key).delete(timeout=self._timeout, retry=None) + except NotFound: + return False + except Exception as exc: + raise classify_gcs_error(exc, operation="delete", key=key) from exc + return True + + def exists(self, key: str) -> bool: + """Check if key exists and is not expired, reading only the entry's 14-byte header. + + Args: + key: Cache key to check. + + Returns: + True if key exists and is not expired, False otherwise. + + Raises: + BackendError: If the request fails. + """ + return self._read("exists", key, header_only=True) is not None + + def health_check(self) -> tuple[bool, dict[str, Any]]: + """Check that the bucket answers, by listing at most one object under the prefix. + + A listing needs ``storage.objects.list`` only, never a bucket-level get, and it fails for a + bucket that does not exist, which an object read cannot tell from a miss. + + Returns: + Tuple of (is_healthy, details_dict) with latency_ms and backend_type. + """ + details: dict[str, Any] = {"backend_type": "gcs", "bucket": self._config.bucket} + start = time.perf_counter() + try: + listing = self._client.list_blobs( + self._bucket, prefix=self._prefix, max_results=1, timeout=self._timeout, retry=None + ) + next(iter(listing), None) + except Exception as exc: + details["error"] = str(classify_gcs_error(exc, operation="health_check")) + details["latency_ms"] = round((time.perf_counter() - start) * 1000, 2) + return "error" not in details, details diff --git a/src/cachekit/backends/gcs/config.py b/src/cachekit/backends/gcs/config.py new file mode 100644 index 000000000..3a8b5572a --- /dev/null +++ b/src/cachekit/backends/gcs/config.py @@ -0,0 +1,95 @@ +"""Google Cloud Storage backend configuration. + +Holds no credential fields: the backend authenticates with Application Default Credentials. +""" + +from __future__ import annotations + +from pydantic import Field, field_validator +from pydantic_settings import SettingsConfigDict + +from cachekit.backends.base_config import BaseBackendConfig, inherit_config + +# GCS caps an object name at 1024 bytes of UTF-8; an entry's name is the prefix plus 32 hex characters. +MAX_PREFIX_BYTES: int = 1024 - 32 + + +class GCSBackendConfig(BaseBackendConfig): + """Google Cloud Storage backend configuration. + + Attributes: + bucket: Name of the bucket that holds the entries. Required. + prefix: Object-name prefix, used verbatim (``"cache/"`` gives ``cache/``). A storage + location only: it does not change the cache key. + project: Google Cloud project passed to the storage client. Optional: the object requests + this backend sends need none. + timeout: Seconds to wait for the server to connect, and between bytes of a response. + + Examples: + Create with a bucket: + + >>> config = GCSBackendConfig(bucket="my-cache-bucket") + >>> config.prefix + '' + >>> config.timeout + 10.0 + + Keep entries under a prefix: + + >>> GCSBackendConfig(bucket="my-cache-bucket", prefix="cachekit/").prefix + 'cachekit/' + """ + + model_config = SettingsConfigDict( + **inherit_config(BaseBackendConfig), + env_prefix="CACHEKIT_GCS_", + ) + + bucket: str = Field( + ..., # Required field + min_length=1, + description="Bucket that holds the cache entries (a name, not a gs:// URL)", + ) + prefix: str = Field( + default="", + description="Object-name prefix, used verbatim; a storage location only", + ) + project: str | None = Field( + default=None, + description="Google Cloud project passed to the storage client; object requests need none", + ) + timeout: float = Field( + default=10.0, + ge=0.1, + le=600.0, + description="Seconds to wait for a connection, and between bytes of a response", + ) + + @field_validator("bucket", mode="after") + @classmethod + def validate_bucket(cls, v: str) -> str: + """Reject a URL or a path: the client would address a bucket of that literal name.""" + if "/" in v: + raise ValueError("bucket must be a bucket name, without gs:// or a path; put a path in prefix") + return v + + @field_validator("prefix", mode="after") + @classmethod + def validate_prefix(cls, v: str) -> str: + """Reject a prefix GCS would refuse in an object name.""" + if "\r" in v or "\n" in v: + raise ValueError("prefix must not contain a carriage return or line feed") + if len(v.encode("utf-8")) > MAX_PREFIX_BYTES: + raise ValueError(f"prefix must be at most {MAX_PREFIX_BYTES} bytes of UTF-8") + return v + + @classmethod + def from_env(cls) -> GCSBackendConfig: + """Create configuration from environment variables. + + Reads CACHEKIT_GCS_BUCKET, CACHEKIT_GCS_PREFIX, CACHEKIT_GCS_PROJECT and CACHEKIT_GCS_TIMEOUT. + + Returns: + GCSBackendConfig instance loaded from environment. + """ + return cls() # type: ignore[call-arg] diff --git a/src/cachekit/backends/gcs/error_handler.py b/src/cachekit/backends/gcs/error_handler.py new file mode 100644 index 000000000..28f5bfbb8 --- /dev/null +++ b/src/cachekit/backends/gcs/error_handler.py @@ -0,0 +1,80 @@ +"""Google Cloud Storage exception classification for backend abstraction. + +Maps google-cloud-storage, google-auth and transport exceptions to BackendErrorType for the +circuit breaker. +""" + +from __future__ import annotations + +from cachekit.backends.errors import BackendError, BackendErrorType + + +def _classify(exc: Exception) -> tuple[BackendErrorType, str]: + """The error type for exc, and the word that names it in the message.""" + import requests.exceptions + from google.api_core.exceptions import GoogleAPICallError + from google.auth.exceptions import DefaultCredentialsError, GoogleAuthError, RefreshError + + # Before the OSError branch: requests' exceptions are OSErrors, and its ConnectTimeout is also + # a ConnectionError. + if isinstance(exc, (requests.exceptions.Timeout, TimeoutError)): + return BackendErrorType.TIMEOUT, "timeout" + if isinstance(exc, GoogleAPICallError): + status = exc.code + if status in (401, 403): + return BackendErrorType.AUTHENTICATION, "authentication error" + if status == 408: + return BackendErrorType.TIMEOUT, "timeout" + if status == 429 or (status is not None and status >= 500): + return BackendErrorType.TRANSIENT, "transient error" + return BackendErrorType.PERMANENT, "permanent error" + if isinstance(exc, (DefaultCredentialsError, RefreshError)): + return BackendErrorType.AUTHENTICATION, "authentication error" + # Any other auth failure is the token endpoint or metadata server being unreachable. + if isinstance(exc, (GoogleAuthError, OSError)): + return BackendErrorType.TRANSIENT, "transient error" + return BackendErrorType.UNKNOWN, "unknown error" + + +def classify_gcs_error( + exc: Exception, + operation: str | None = None, + key: str | None = None, +) -> BackendError: + """Classify a Google Cloud Storage exception into BackendError with error_type. + + Args: + exc: Original exception from google-cloud-storage, google-auth or the HTTP transport. + operation: Operation that failed (get, set, delete, exists, health_check). + key: Cache key involved (optional, for debugging). + + Returns: + BackendError with appropriate error_type classification. + + Examples: + A 403 is an authentication error: + + >>> from google.api_core.exceptions import Forbidden, ServiceUnavailable + >>> classify_gcs_error(Forbidden("denied"), operation="get").error_type.value + 'authentication' + + A 503 is transient, and a transport timeout gets its own category: + + >>> classify_gcs_error(ServiceUnavailable("busy"), operation="set").error_type.value + 'transient' + >>> classify_gcs_error(TimeoutError(), operation="get").error_type.value + 'timeout' + """ + error_type, label = _classify(exc) + # Only the exception TYPE and the HTTP status go in the message: Google's error text carries the + # request URL, which names the bucket and object, and the message reaches log sinks via str(e) + # (CWE-532). Full details stay on original_exception. + status = getattr(exc, "code", None) + detail = f"{type(exc).__name__} (HTTP {status})" if isinstance(status, int) else type(exc).__name__ + return BackendError( + message=f"GCS {label} during {operation}: {detail}", + error_type=error_type, + original_exception=exc, + operation=operation, + key=key, + ) diff --git a/src/cachekit/backends/provider.py b/src/cachekit/backends/provider.py index cee5356dc..05a85db1a 100644 --- a/src/cachekit/backends/provider.py +++ b/src/cachekit/backends/provider.py @@ -168,7 +168,7 @@ async def get_async_client(self) -> redis_async.Redis: class _BackendEnv(BaseSettings): """The backend env vars as pydantic-settings reads them, for DefaultBackendProvider._is_configured(): - its four _SELECTORS plus REDIS_URL.""" + its five _SELECTORS plus REDIS_URL.""" model_config = SettingsConfigDict(case_sensitive=False, extra="ignore", hide_input_in_errors=True) @@ -177,6 +177,7 @@ class _BackendEnv(BaseSettings): cachekit_redis_url: Optional[SecretStr] = None cachekit_memcached_servers: Optional[SecretStr] = None cachekit_file_cache_dir: Optional[SecretStr] = None + cachekit_gcs_bucket: Optional[SecretStr] = None redis_url: Optional[SecretStr] = None @@ -189,6 +190,7 @@ class DefaultBackendProvider(BackendProviderInterface): - CACHEKIT_REDIS_URL → Redis (tenant-scoped PerRequestRedisBackend) - CACHEKIT_MEMCACHED_SERVERS → MemcachedBackend - CACHEKIT_FILE_CACHE_DIR → FileBackend + - CACHEKIT_GCS_BUCKET → GCSBackend With none of them set, ``REDIS_URL`` → Redis, as above (12-factor). With nothing set at all, ``_is_configured()`` is False and a plaintext decorator @@ -196,7 +198,7 @@ class DefaultBackendProvider(BackendProviderInterface): Only the decorators that cannot run L1-only (encryption, ``interop=``) still call it then, and get Redis at ``RedisBackendConfig``'s localhost default. - Setting more than one of the four prefixed selectors raises + Setting more than one of the five prefixed selectors raises ``ConfigurationError`` — auto-detection must be unambiguous; pass ``backend=`` explicitly to override. The non-prefixed ``REDIS_URL`` is only a fallback and never counts as a conflict (12-factor convention). @@ -216,6 +218,7 @@ class DefaultBackendProvider(BackendProviderInterface): ("CACHEKIT_REDIS_URL", "redis"), ("CACHEKIT_MEMCACHED_SERVERS", "memcached"), ("CACHEKIT_FILE_CACHE_DIR", "file"), + ("CACHEKIT_GCS_BUCKET", "gcs"), ) def __init__(self): @@ -223,6 +226,7 @@ def __init__(self): self._redis_backend = None self._memcached_backend = None self._file_backend = None + self._gcs_backend = None def _matched(self) -> list[tuple[str, str]]: """The prefixed selectors set to a non-empty value, matched by exact name.""" @@ -243,7 +247,8 @@ def _detect(self): raise ConfigurationError( f"Ambiguous backend auto-detection: multiple selectors set ({names}). " "Set exactly one of CACHEKIT_API_KEY / CACHEKIT_REDIS_URL / " - "CACHEKIT_MEMCACHED_SERVERS / CACHEKIT_FILE_CACHE_DIR, or pass backend= explicitly." + "CACHEKIT_MEMCACHED_SERVERS / CACHEKIT_FILE_CACHE_DIR / CACHEKIT_GCS_BUCKET, " + "or pass backend= explicitly." ) return matched[0][1] if matched else None @@ -289,6 +294,13 @@ def get_backend(self): self._file_backend = FileBackend(FileBackendConfig.from_env()) return self._file_backend + if choice == "gcs": + if self._gcs_backend is None: + from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + + self._gcs_backend = GCSBackend(GCSBackendConfig.from_env()) + return self._gcs_backend + # choice == "redis" (explicit CACHEKIT_REDIS_URL) or None: REDIS_URL, else RedisBackendConfig's default. # Shared backend: it resolves the tenant per operation, so caching it cannot pin a tenant. if self._redis_backend is None: diff --git a/src/cachekit/decorators/wrapper.py b/src/cachekit/decorators/wrapper.py index 26704f20f..d55dc8125 100644 --- a/src/cachekit/decorators/wrapper.py +++ b/src/cachekit/decorators/wrapper.py @@ -945,8 +945,8 @@ def create_cache_wrapper( "encryption requires a backend: backend=None is L1-only and stores raw Python " "objects, which cannot be ciphertext. Drop backend=None (the backend then " "resolves from set_default_backend(), else the one CACHEKIT_* selector set: " - "CACHEKIT_API_KEY, CACHEKIT_REDIS_URL, CACHEKIT_MEMCACHED_SERVERS or " - "CACHEKIT_FILE_CACHE_DIR, else REDIS_URL / localhost Redis; see " + "CACHEKIT_API_KEY, CACHEKIT_REDIS_URL, CACHEKIT_MEMCACHED_SERVERS, " + "CACHEKIT_FILE_CACHE_DIR or CACHEKIT_GCS_BUCKET, else REDIS_URL / localhost Redis; see " "docs/backends/README.md) or pass one explicitly to keep @cache.secure / " "encryption=True." ) diff --git a/tests/architecture/test_backend_config_consistency.py b/tests/architecture/test_backend_config_consistency.py index be07f84c7..ef43df485 100644 --- a/tests/architecture/test_backend_config_consistency.py +++ b/tests/architecture/test_backend_config_consistency.py @@ -18,6 +18,7 @@ from cachekit.backends.base_config import BaseBackendConfig from cachekit.backends.cachekitio.config import CachekitIOBackendConfig from cachekit.backends.file.config import FileBackendConfig +from cachekit.backends.gcs.config import GCSBackendConfig from cachekit.backends.memcached.config import MemcachedBackendConfig from cachekit.backends.redis.config import RedisBackendConfig @@ -27,8 +28,12 @@ FileBackendConfig, CachekitIOBackendConfig, MemcachedBackendConfig, + GCSBackendConfig, ] +# Constructor arguments for a config that has a required field and is still instantiated below. +REQUIRED_KWARGS: dict[type[BaseBackendConfig], dict[str, str]] = {GCSBackendConfig: {"bucket": "cache-bucket"}} + # Required model_config settings from BaseBackendConfig REQUIRED_MODEL_CONFIG_KEYS = { "env_nested_delimiter": "__", @@ -54,7 +59,7 @@ def test_isinstance_check_works(self, config_cls: type[BaseBackendConfig]) -> No if config_cls is CachekitIOBackendConfig: pytest.skip("CachekitIOBackendConfig requires api_key") - instance = config_cls() + instance = config_cls(**REQUIRED_KWARGS.get(config_cls, {})) assert isinstance(instance, BaseBackendConfig), f"{config_cls.__name__} instance should be instanceof BaseBackendConfig" @@ -95,7 +100,7 @@ def test_extra_forbid_catches_typos(self, config_cls: type[BaseBackendConfig]) - pytest.skip("CachekitIOBackendConfig requires api_key") with pytest.raises(ValidationError) as exc_info: - config_cls(totally_fake_field_that_doesnt_exist="value") # type: ignore[call-arg] + config_cls(totally_fake_field_that_doesnt_exist="value", **REQUIRED_KWARGS.get(config_cls, {})) # type: ignore[call-arg] # Verify it's an "extra fields" error errors = exc_info.value.errors() diff --git a/tests/fixtures/zero_config.py b/tests/fixtures/zero_config.py index 3a6f57d04..0965733dd 100644 --- a/tests/fixtures/zero_config.py +++ b/tests/fixtures/zero_config.py @@ -9,7 +9,13 @@ import pytest -SELECTORS = ("CACHEKIT_API_KEY", "CACHEKIT_REDIS_URL", "CACHEKIT_MEMCACHED_SERVERS", "CACHEKIT_FILE_CACHE_DIR") +SELECTORS = ( + "CACHEKIT_API_KEY", + "CACHEKIT_REDIS_URL", + "CACHEKIT_MEMCACHED_SERVERS", + "CACHEKIT_FILE_CACHE_DIR", + "CACHEKIT_GCS_BUCKET", +) BACKEND_ENV = (*SELECTORS, "REDIS_URL") diff --git a/tests/integration/test_gcs_integration.py b/tests/integration/test_gcs_integration.py new file mode 100644 index 000000000..bebbc4786 --- /dev/null +++ b/tests/integration/test_gcs_integration.py @@ -0,0 +1,278 @@ +"""Integration tests for GCSBackend against a Google Cloud Storage emulator. + +Requires a running fake-gcs-server. Start one with: + bash .github/scripts/start-fake-gcs.sh + +Set STORAGE_EMULATOR_HOST to override the default http://localhost:4443. The tests only ever talk +to that host, never to Google Cloud Storage. They are skipped when it is unreachable. CI push runs +start the emulator and fail the job if any test here skips. +""" + +from __future__ import annotations + +import os +import threading +import time +import urllib.error +import urllib.request +import uuid +from collections.abc import Iterator +from pathlib import Path +from typing import Any + +import pytest + +from cachekit.backends.errors import BackendError, BackendErrorType +from cachekit.backends.file import FileBackend, FileBackendConfig + +EMULATOR_HOST = os.environ.get("STORAGE_EMULATOR_HOST", "http://localhost:4443") + + +def _emulator_reachable() -> bool: + """Whether the emulator answers, and google-cloud-storage is installed.""" + try: + import google.cloud.storage # noqa: F401 + except ImportError: + return False + if not EMULATOR_HOST.startswith(("http://", "https://")): + return False + try: + # The scheme is checked above, and the host is this test run's own emulator. + with urllib.request.urlopen(f"{EMULATOR_HOST}/storage/v1/b", timeout=2) as response: # noqa: S310 + return response.status == 200 + except (urllib.error.URLError, OSError): + return False + + +pytestmark = [ + pytest.mark.integration, + pytest.mark.skipif(not _emulator_reachable(), reason="GCS emulator not reachable, or the gcs extra is not installed"), +] + + +# Override autouse Redis fixture — GCS tests don't need Redis +@pytest.fixture(autouse=True) +def setup_di_for_redis_isolation(): + """Override global Redis fixture — GCSBackend doesn't need Redis.""" + pass + + +@pytest.fixture(autouse=True) +def _emulator_env(monkeypatch: pytest.MonkeyPatch) -> None: + """Every client built in a test talks to the emulator, with anonymous credentials.""" + monkeypatch.setenv("STORAGE_EMULATOR_HOST", EMULATOR_HOST) + + +@pytest.fixture +def admin(_emulator_env: None) -> Any: + """A plain storage client, to look at the bucket independently of the backend.""" + from google.cloud import storage + + return storage.Client() + + +@pytest.fixture +def bucket(admin: Any) -> Iterator[Any]: + """A bucket no other test, xdist worker or concurrent run uses.""" + bucket = admin.create_bucket(f"cachekit-it-{uuid.uuid4().hex[:16]}") + yield bucket + bucket.delete(force=True) + + +@pytest.fixture +def backend(bucket: Any) -> Any: + from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + + return GCSBackend(GCSBackendConfig(bucket=bucket.name, timeout=5.0)) + + +def _names(bucket: Any) -> list[str]: + return sorted(blob.name for blob in bucket.list_blobs()) + + +class TestRoundTrip: + def test_set_get_exists_delete(self, backend: Any) -> None: + assert backend.get("k") is None + assert backend.exists("k") is False + + backend.set("k", b"value", ttl=60) + + assert backend.get("k") == b"value" + assert backend.exists("k") is True + assert backend.delete("k") is True + assert backend.delete("k") is False + assert backend.get("k") is None + + def test_set_replaces(self, backend: Any, bucket: Any) -> None: + backend.set("k", b"one", ttl=60) + backend.set("k", b"two") + + assert backend.get("k") == b"two" + assert len(_names(bucket)) == 1 + + @pytest.mark.parametrize("value", [b"", b"\x00\xff" * 512, os.urandom(9 * 1024 * 1024)], ids=["empty", "binary", "9MiB"]) + def test_values_survive(self, backend: Any, value: bytes) -> None: + """9 MiB is past the client library's single-request limit, so that one is a resumable upload.""" + backend.set("k", value, ttl=60) + assert backend.get("k") == value + + def test_concurrent_threads_share_a_backend(self, backend: Any) -> None: + errors: list[BaseException] = [] + + def work(i: int) -> None: + try: + for j in range(10): + key = f"thread-{i}-{j}" + backend.set(key, key.encode(), ttl=60) + assert backend.get(key) == key.encode() + except BaseException as exc: # noqa: BLE001 (reported below, on the main thread) + errors.append(exc) + + threads = [threading.Thread(target=work, args=(i,)) for i in range(8)] + for thread in threads: + thread.start() + for thread in threads: + thread.join(timeout=60) + + assert errors == [] + + +class TestObjectFormat: + @pytest.mark.parametrize("ttl", [None, 3600]) + def test_object_is_the_file_backends_file(self, backend: Any, bucket: Any, tmp_path: Path, ttl: int | None) -> None: + """Same key, value and expiry: the stored object and the file backend's file are the same bytes, same name.""" + import time_machine + + key = "ns:app:func:mod.fn:args:" + "ab" * 32 + ":1s" + with time_machine.travel(time.time(), tick=False): + FileBackend(FileBackendConfig(cache_dir=tmp_path)).set(key, b"payload", ttl=ttl) + backend.set(key, b"payload", ttl=ttl) + + (written,) = [p for p in tmp_path.iterdir() if p.is_file()] + assert _names(bucket) == [written.name] + assert bucket.blob(written.name).download_as_bytes() == written.read_bytes() + + def test_a_file_backend_entry_uploaded_as_is_is_readable(self, backend: Any, bucket: Any, tmp_path: Path) -> None: + FileBackend(FileBackendConfig(cache_dir=tmp_path)).set("k", b"from a file", ttl=60) + (written,) = [p for p in tmp_path.iterdir() if p.is_file()] + bucket.blob(written.name).upload_from_filename(str(written)) + + assert backend.get("k") == b"from a file" + + def test_prefix_is_part_of_the_object_name_only(self, bucket: Any) -> None: + from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + + plain = GCSBackend(GCSBackendConfig(bucket=bucket.name)) + prefixed = GCSBackend(GCSBackendConfig(bucket=bucket.name, prefix="cachekit/")) + plain.set("k", b"plain") + prefixed.set("k", b"prefixed") + + plain_name, prefixed_name = _names(bucket) + assert prefixed_name == f"cachekit/{plain_name}" + assert (plain.get("k"), prefixed.get("k")) == (b"plain", b"prefixed") + + +class TestExpiry: + def test_expired_entry_is_a_miss_and_get_deletes_it(self, backend: Any, bucket: Any) -> None: + backend.set("k", b"v", ttl=1) + assert backend.exists("k") is True + assert len(_names(bucket)) == 1 + + time.sleep(1.1) # the expiry is a whole second: the entry is dead once the clock reaches it + + assert backend.get("k") is None + assert _names(bucket) == [] + + def test_expired_entry_is_a_miss_on_exists(self, backend: Any) -> None: + backend.set("k", b"v", ttl=1) + time.sleep(1.1) + assert backend.exists("k") is False + + def test_cleanup_spares_an_entry_stored_since_the_read(self, backend: Any) -> None: + """A reader that saw a dead entry deletes that generation only, not a writer's newer one.""" + backend.set("k", b"dead") + seen = backend._blob("k") + seen.reload() # the generation a read of the dead entry would have seen + backend.set("k", b"fresh") + + backend._discard(seen) + + assert backend.get("k") == b"fresh" + + @pytest.mark.parametrize("body", [b"", b"CK", b"not a cachekit entry at all"], ids=["empty", "truncated", "bad-magic"]) + @pytest.mark.parametrize("read", ["get", "exists"]) + def test_corrupt_object_is_a_miss_and_is_deleted(self, backend: Any, bucket: Any, body: bytes, read: str) -> None: + backend.set("k", b"v") + (name,) = _names(bucket) + bucket.blob(name).upload_from_string(body) + + assert not getattr(backend, read)("k") + assert _names(bucket) == [] + + @pytest.mark.parametrize("read", ["get", "exists"]) + def test_unknown_flag_is_a_miss_left_untouched(self, backend: Any, bucket: Any, read: str) -> None: + backend.set("k", b"v") + (name,) = _names(bucket) + flagged = b"CK\x01\x00\x00\x01" + b"\x00" * 8 + b"transformed" + bucket.blob(name).upload_from_string(flagged) + + assert not getattr(backend, read)("k") + assert bucket.blob(name).download_as_bytes() == flagged + + +class TestHealthCheck: + def test_healthy(self, backend: Any) -> None: + healthy, details = backend.health_check() + + assert healthy is True + assert details["backend_type"] == "gcs" + assert details["latency_ms"] >= 0 + + def test_missing_bucket_is_unhealthy(self, _emulator_env: None) -> None: + from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + + healthy, details = GCSBackend(GCSBackendConfig(bucket=f"cachekit-absent-{uuid.uuid4().hex[:16]}")).health_check() + + assert healthy is False + assert "error" in details + + def test_set_to_a_missing_bucket_raises(self, _emulator_env: None) -> None: + from cachekit.backends.gcs import GCSBackend, GCSBackendConfig + + with pytest.raises(BackendError) as exc_info: + GCSBackend(GCSBackendConfig(bucket=f"cachekit-absent-{uuid.uuid4().hex[:16]}")).set("k", b"v") + assert exc_info.value.error_type is BackendErrorType.PERMANENT + + +class TestDecoratorIntegration: + def test_cache_with_explicit_backend(self, backend: Any, bucket: Any) -> None: + from cachekit import cache + + calls = 0 + + @cache(ttl=60, namespace="gcs_it", backend=backend, l1_enabled=False) + def add(a: int, b: int) -> int: + nonlocal calls + calls += 1 + return a + b + + assert (add(2, 3), add(2, 3), calls) == (5, 5, 1) + assert add(10, 20) == 30 + assert calls == 2 + assert len(_names(bucket)) == 2 + + def test_env_selection_builds_a_working_backend(self, bucket: Any, monkeypatch: pytest.MonkeyPatch) -> None: + from cachekit.backends.gcs import GCSBackend + from cachekit.backends.provider import DefaultBackendProvider + from tests.fixtures.zero_config import clear_cachekit_env + + clear_cachekit_env(monkeypatch) + monkeypatch.setenv("CACHEKIT_GCS_BUCKET", bucket.name) + monkeypatch.setenv("CACHEKIT_GCS_PREFIX", "env/") + + selected = DefaultBackendProvider().get_backend() + + assert isinstance(selected, GCSBackend) + selected.set("k", b"v", ttl=60) + assert selected.get("k") == b"v" + assert _names(bucket)[0].startswith("env/") diff --git a/tests/unit/backends/test_gcs_backend.py b/tests/unit/backends/test_gcs_backend.py new file mode 100644 index 000000000..cc4e5c27b --- /dev/null +++ b/tests/unit/backends/test_gcs_backend.py @@ -0,0 +1,603 @@ +"""Unit tests for GCSBackend. + +The backend runs on the real google-cloud-storage client over a scripted HTTP transport, so each +test sees the requests the backend sends: how many, which method, which headers. Nothing leaves +the process. tests/integration/test_gcs_integration.py covers a live server. +""" + +from __future__ import annotations + +import contextlib +import hashlib +import io +import json +import struct +import subprocess +import sys +from pathlib import Path +from typing import Any +from urllib.parse import parse_qs, unquote, urlsplit + +import pytest +import time_machine + +pytest.importorskip("google.cloud.storage", reason="needs the gcs extra") + +import requests +import requests.adapters +import urllib3 +from google.auth.credentials import AnonymousCredentials +from google.auth.exceptions import DefaultCredentialsError, RefreshError, TransportError +from google.auth.transport.requests import AuthorizedSession +from google.cloud import storage + +from cachekit.backends.base import BaseBackend, TTLInspectableBackend +from cachekit.backends.errors import BackendError, BackendErrorType +from cachekit.backends.file import FileBackend, FileBackendConfig +from cachekit.backends.gcs import GCSBackend, GCSBackendConfig +from cachekit.backends.gcs.error_handler import classify_gcs_error + +BUCKET = "cache-bucket" +FIXTURE_PATH = Path(__file__).parents[1] / "protocol" / "fixtures" / "file-backend.json" +VECTORS: list[dict[str, Any]] = json.loads(FIXTURE_PATH.read_text(encoding="utf-8"))["vectors"] + + +def _header(expiry: int = 0, reserved: int = 0, flags: int = 0) -> bytes: + return b"CK\x01" + bytes([reserved]) + struct.pack(">H", flags) + struct.pack(">Q", expiry) + + +def _name(key: str) -> str: + return hashlib.blake2b(key.encode("utf-8"), digest_size=16).hexdigest() + + +class _Reply: + """One scripted HTTP response, or the exception the transport raises instead.""" + + def __init__(self, status: int = 200, body: bytes = b"{}", generation: int | None = None, error: Exception | None = None): + self.status = status + self.body = body + self.generation = generation + self.error = error + + +class _Transport(requests.adapters.BaseAdapter): + """Answers each request with the next scripted reply, and records the request.""" + + def __init__(self) -> None: + super().__init__() + self.replies: list[_Reply] = [] + self.requests: list[requests.PreparedRequest] = [] + self._build = requests.adapters.HTTPAdapter() # for build_response only: it sends nothing + + def send(self, request: requests.PreparedRequest, **kwargs: Any) -> requests.Response: # type: ignore[override] + self.requests.append(request) + assert self.replies, f"unscripted request: {request.method} {request.url}" + reply = self.replies.pop(0) + if reply.error is not None: + raise reply.error + headers = {"Content-Length": str(len(reply.body))} + if reply.generation is not None: + headers["X-Goog-Generation"] = str(reply.generation) + raw = urllib3.HTTPResponse(body=io.BytesIO(reply.body), headers=headers, status=reply.status, preload_content=False) + return self._build.build_response(request, raw) + + def close(self) -> None: + pass + + def script(self, *replies: _Reply) -> None: + self.replies.extend(replies) + + def sent(self) -> list[tuple[str, str]]: + """(method, object name or bucket-relative path) of every request so far.""" + return [(r.method or "", unquote(urlsplit(r.url or "").path.split(f"/b/{BUCKET}", 1)[1])) for r in self.requests] + + +@pytest.fixture +def transport(monkeypatch: pytest.MonkeyPatch) -> _Transport: + """The transport every client built by GCSBackend talks to.""" + transport = _Transport() + + def build(project: str | None) -> storage.Client: + credentials = AnonymousCredentials() + session = AuthorizedSession(credentials) + session.mount("https://", transport) + return storage.Client(project=project or "test-project", credentials=credentials, _http=session) + + monkeypatch.setattr("cachekit.backends.gcs.backend._build_client", build) + return transport + + +@pytest.fixture +def backend(transport: _Transport) -> GCSBackend: + return GCSBackend(GCSBackendConfig(bucket=BUCKET)) + + +def _uploaded(request: requests.PreparedRequest) -> bytes: + """The object bytes of a multipart upload request.""" + content_type = request.headers["content-type"] + if isinstance(content_type, str): + content_type = content_type.encode() + boundary = content_type.split(b'boundary="', 1)[1].rstrip(b'"') + body = request.body + assert isinstance(body, bytes) + media = body.split(b"--" + boundary)[2] # preamble, metadata part, media part, epilogue + return media.split(b"\r\n\r\n", 1)[1].removesuffix(b"\r\n") + + +@pytest.mark.unit +class TestProtocolCompliance: + def test_is_a_base_backend(self, backend: GCSBackend) -> None: + assert isinstance(backend, BaseBackend) + + def test_is_not_ttl_inspectable(self, backend: GCSBackend) -> None: + """Objects are immutable: refreshing a TTL would rewrite the whole object.""" + assert not isinstance(backend, TTLInspectableBackend) + + def test_construction_sends_no_request(self, transport: _Transport) -> None: + GCSBackend(GCSBackendConfig(bucket=BUCKET)) + assert transport.requests == [] + + +@pytest.mark.unit +class TestGet: + def test_hit_is_one_unranged_download(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(body=_header() + b"value")) + + assert backend.get("k") == b"value" + + assert transport.sent() == [("GET", f"/o/{_name('k')}")] + assert "Range" not in transport.requests[0].headers + + def test_absent_object_is_a_miss_in_one_request(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(status=404)) + + assert backend.get("k") is None + assert len(transport.requests) == 1 + + def test_empty_payload_round_trips(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(body=_header())) + assert backend.get("k") == b"" + + @time_machine.travel(1_000_000, tick=False) + def test_entry_is_live_until_its_expiry_second(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(body=_header(expiry=1_000_001) + b"v")) + assert backend.get("k") == b"v" + + @time_machine.travel(1_000_000, tick=False) + def test_expired_entry_is_a_miss_and_is_deleted(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(body=_header(expiry=1_000_000) + b"v", generation=7), _Reply(status=204, body=b"")) + + assert backend.get("k") is None + + assert transport.sent() == [("GET", f"/o/{_name('k')}"), ("DELETE", f"/o/{_name('k')}")] + # Only the generation that was read: an entry stored in between survives. + assert parse_qs(urlsplit(transport.requests[1].url or "").query)["ifGenerationMatch"] == ["7"] + + @pytest.mark.parametrize( + "body", + [b"", b"CK\x01", _header()[:13], b"XX" + _header()[2:] + b"v", b"CK\x02" + _header()[3:] + b"v"], + ids=["empty", "short", "one-byte-short", "bad-magic", "bad-version"], + ) + def test_corrupt_entry_is_a_miss_and_is_deleted(self, backend: GCSBackend, transport: _Transport, body: bytes) -> None: + transport.script(_Reply(body=body, generation=3), _Reply(status=204, body=b"")) + + assert backend.get("k") is None + assert [method for method, _ in transport.sent()] == ["GET", "DELETE"] + + @pytest.mark.parametrize("reserved,flags", [(1, 0), (0, 1), (0, 0x8000)]) + @time_machine.travel(1_000_000, tick=False) + def test_unknown_transform_is_a_miss_left_untouched( + self, backend: GCSBackend, transport: _Transport, reserved: int, flags: int + ) -> None: + """Even when expired: the flags are judged before the expiry.""" + transport.script(_Reply(body=_header(expiry=1, reserved=reserved, flags=flags) + b"v", generation=3)) + + assert backend.get("k") is None + assert [method for method, _ in transport.sent()] == ["GET"] + + @pytest.mark.parametrize("cleanup", [_Reply(status=403), _Reply(status=412), _Reply(error=requests.ConnectionError())]) + @time_machine.travel(1_000_000, tick=False) + def test_failed_cleanup_is_still_a_miss(self, backend: GCSBackend, transport: _Transport, cleanup: _Reply) -> None: + """A read-only identity, or an entry replaced since the read, cannot fail the read.""" + transport.script(_Reply(body=_header(expiry=5) + b"v", generation=3), cleanup) + assert backend.get("k") is None + + +@pytest.mark.unit +class TestExists: + def test_reads_only_the_header(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(status=206, body=_header())) + + assert backend.exists("k") is True + + assert transport.sent() == [("GET", f"/o/{_name('k')}")] + assert transport.requests[0].headers["Range"] == "bytes=0-13" + + def test_absent_object(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(status=404)) + assert backend.exists("k") is False + + @time_machine.travel(1_000_000, tick=False) + def test_expired_entry_is_a_miss(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(status=206, body=_header(expiry=999_999), generation=4), _Reply(status=204, body=b"")) + assert backend.exists("k") is False + + def test_empty_object_is_a_miss_and_is_deleted(self, backend: GCSBackend, transport: _Transport) -> None: + """An empty object has no first byte, so the ranged read is refused with a 416.""" + transport.script(_Reply(status=416), _Reply(status=204, body=b"")) + + assert backend.exists("k") is False + assert [method for method, _ in transport.sent()] == ["GET", "DELETE"] + + def test_unknown_transform_is_a_miss_left_untouched(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(status=206, body=_header(flags=1))) + + assert backend.exists("k") is False + assert len(transport.requests) == 1 + + +@pytest.mark.unit +class TestSet: + @time_machine.travel(1_000_000, tick=False) + def test_is_one_upload_of_header_and_value(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply()) + + backend.set("k", b"value", ttl=60) + + assert [r.method for r in transport.requests] == ["POST"] + request = transport.requests[0] + assert parse_qs(urlsplit(request.url or "").query)["uploadType"] == ["multipart"] + assert _uploaded(request) == _header(expiry=1_000_060) + b"value" + body = request.body + assert isinstance(body, bytes) + assert json.loads(body.split(b"\r\n\r\n", 2)[1].split(b"\r\n", 1)[0])["name"] == _name("k") + + @pytest.mark.parametrize("ttl", [None, 0]) + def test_no_ttl_writes_no_expiry(self, backend: GCSBackend, transport: _Transport, ttl: int | None) -> None: + transport.script(_Reply()) + backend.set("k", b"v", ttl=ttl) + assert _uploaded(transport.requests[0]) == _header(expiry=0) + b"v" + + @pytest.mark.parametrize("ttl", [-1, 10 * 365 * 24 * 60 * 60 + 1]) + def test_out_of_range_ttl_is_refused_before_any_request(self, backend: GCSBackend, transport: _Transport, ttl: int) -> None: + with pytest.raises(BackendError) as exc_info: + backend.set("k", b"v", ttl=ttl) + + assert exc_info.value.error_type is BackendErrorType.PERMANENT + assert transport.requests == [] + + @pytest.mark.parametrize("ttl", [None, 0, 1, 3600]) + @pytest.mark.parametrize("value", [b"", b"value", bytes(range(256)) * 4]) + @time_machine.travel(1_700_000_000, tick=False) + def test_object_is_byte_identical_to_the_file_backend( + self, backend: GCSBackend, transport: _Transport, tmp_path: Path, value: bytes, ttl: int | None + ) -> None: + key = "ns:app:func:mod.fn:args:" + "ab" * 32 + ":1s" + file_backend = FileBackend(FileBackendConfig(cache_dir=tmp_path)) + file_backend.set(key, value, ttl=ttl) + (written,) = [p for p in tmp_path.iterdir() if p.is_file()] + transport.script(_Reply()) + + backend.set(key, value, ttl=ttl) + + assert _uploaded(transport.requests[0]) == written.read_bytes() + assert _name(key) == written.name + + +@pytest.mark.unit +class TestDelete: + def test_deleted(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(status=204, body=b"")) + + assert backend.delete("k") is True + assert transport.sent() == [("DELETE", f"/o/{_name('k')}")] + + def test_absent_object(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(status=404)) + assert backend.delete("k") is False + + +@pytest.mark.unit +class TestPrefix: + def test_prefix_precedes_the_name_verbatim(self, transport: _Transport) -> None: + backend = GCSBackend(GCSBackendConfig(bucket=BUCKET, prefix="cachekit/v1-")) + transport.script(_Reply(status=404), _Reply(status=404), _Reply(status=404)) + + backend.get("k") + backend.exists("k") + backend.delete("k") + + assert {path for _, path in transport.sent()} == {f"/o/cachekit/v1-{_name('k')}"} + + def test_prefix_is_not_a_key_prefix(self, transport: _Transport) -> None: + """A storage location only: nothing reads it as part of the cache key or the AAD.""" + assert not hasattr(GCSBackend(GCSBackendConfig(bucket=BUCKET, prefix="p/")), "key_prefix") + + +_STATUS_CASES = [ + (401, BackendErrorType.AUTHENTICATION), + (403, BackendErrorType.AUTHENTICATION), + (429, BackendErrorType.TRANSIENT), + (500, BackendErrorType.TRANSIENT), + (502, BackendErrorType.TRANSIENT), + (503, BackendErrorType.TRANSIENT), + (504, BackendErrorType.TRANSIENT), + (408, BackendErrorType.TIMEOUT), + (400, BackendErrorType.PERMANENT), + (412, BackendErrorType.PERMANENT), +] +_TRANSPORT_CASES = [ + (requests.ReadTimeout(), BackendErrorType.TIMEOUT), + (requests.ConnectTimeout(), BackendErrorType.TIMEOUT), + (TimeoutError(), BackendErrorType.TIMEOUT), + (requests.ConnectionError(), BackendErrorType.TRANSIENT), + (ConnectionResetError(), BackendErrorType.TRANSIENT), + (RefreshError("token"), BackendErrorType.AUTHENTICATION), + (DefaultCredentialsError("none"), BackendErrorType.AUTHENTICATION), + (TransportError("metadata server"), BackendErrorType.TRANSIENT), + (ValueError("?"), BackendErrorType.UNKNOWN), +] +_OPERATIONS = { + "get": lambda b: b.get("k"), + "set": lambda b: b.set("k", b"v", ttl=60), + "delete": lambda b: b.delete("k"), + "exists": lambda b: b.exists("k"), +} + + +@pytest.mark.unit +class TestErrors: + @pytest.mark.parametrize("operation", _OPERATIONS) + @pytest.mark.parametrize("status,error_type", _STATUS_CASES) + def test_http_status_mapping( + self, backend: GCSBackend, transport: _Transport, operation: str, status: int, error_type: BackendErrorType + ) -> None: + transport.script(_Reply(status=status, body=b'{"error": {"message": "nope"}}')) + + with pytest.raises(BackendError) as exc_info: + _OPERATIONS[operation](backend) + + assert exc_info.value.error_type is error_type + assert exc_info.value.operation == operation + assert len(transport.requests) == 1 # no retry + + @pytest.mark.parametrize("operation", _OPERATIONS) + @pytest.mark.parametrize("error,error_type", _TRANSPORT_CASES, ids=lambda v: type(v).__name__) + def test_transport_error_mapping( + self, backend: GCSBackend, transport: _Transport, operation: str, error: Exception, error_type: BackendErrorType + ) -> None: + transport.script(_Reply(error=error)) + + with pytest.raises(BackendError) as exc_info: + _OPERATIONS[operation](backend) + + assert exc_info.value.error_type is error_type + assert exc_info.value.original_exception is error + assert len(transport.requests) == 1 # no retry + + def test_set_to_a_missing_bucket_is_permanent(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(status=404)) + + with pytest.raises(BackendError) as exc_info: + backend.set("k", b"v") + assert exc_info.value.error_type is BackendErrorType.PERMANENT + + def test_message_carries_no_bucket_object_or_key(self, backend: GCSBackend, transport: _Transport) -> None: + """Google's error text quotes the request URL; only the type and status reach str(e).""" + transport.script(_Reply(status=403, body=b'{"error": {"message": "caller lacks access to cache-bucket"}}')) + + with pytest.raises(BackendError) as exc_info: + backend.get("tenant-42:secret-key") + + text = str(exc_info.value) + assert "Forbidden (HTTP 403)" in text + for leak in (BUCKET, _name("tenant-42:secret-key"), "tenant-42", "caller lacks"): + assert leak not in text + + def test_classifier_defaults(self) -> None: + error = classify_gcs_error(KeyError("x")) + assert error.error_type is BackendErrorType.UNKNOWN + assert error.operation is None + + +@pytest.mark.unit +class TestHealthCheck: + def test_healthy_is_one_object_listing(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(body=b'{"kind": "storage#objects"}')) + + healthy, details = backend.health_check() + + assert healthy is True + assert details["backend_type"] == "gcs" + assert details["bucket"] == BUCKET + assert isinstance(details["latency_ms"], float) + assert "error" not in details + assert transport.sent() == [("GET", "/o")] + assert parse_qs(urlsplit(transport.requests[0].url or "").query)["maxResults"] == ["1"] + + def test_listing_is_scoped_to_the_prefix(self, transport: _Transport) -> None: + transport.script(_Reply(body=b"{}")) + GCSBackend(GCSBackendConfig(bucket=BUCKET, prefix="p/")).health_check() + assert parse_qs(urlsplit(transport.requests[0].url or "").query)["prefix"] == ["p/"] + + @pytest.mark.parametrize("reply", [_Reply(status=403), _Reply(status=404), _Reply(error=requests.ReadTimeout())]) + def test_unhealthy_reports_the_error_and_does_not_raise( + self, backend: GCSBackend, transport: _Transport, reply: _Reply + ) -> None: + transport.script(reply) + + healthy, details = backend.health_check() + + assert healthy is False + assert details["backend_type"] == "gcs" + assert "latency_ms" in details + assert "operation=health_check" in details["error"] + + +@pytest.mark.unit +class TestNoBucketLevelRequest: + def test_no_operation_reads_bucket_metadata(self, backend: GCSBackend, transport: _Transport) -> None: + """Every request is to an object or the object listing, so object-level IAM is enough. + + The client library would otherwise fetch the bucket itself in a background thread, on the + first request and again after every 404. + """ + transport.script( + _Reply(status=404), # get: miss + _Reply(), # set + _Reply(body=_header() + b"v"), # get: hit + _Reply(status=206, body=_header()), # exists + _Reply(status=204, body=b""), # delete + _Reply(status=404), # delete: absent + _Reply(body=b"{}"), # health_check + ) + + backend.get("k") + backend.set("k", b"v") + backend.get("k") + backend.exists("k") + backend.delete("k") + backend.delete("k") + backend.health_check() + + assert backend._client._bucket_metadata_cache is None + assert transport.replies == [] + assert all(path == "/o" or path.startswith("/o/") for _, path in transport.sent()) + + +@pytest.mark.unit +class TestConstruction: + def test_config_defaults_to_the_environment(self, transport: _Transport, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("CACHEKIT_GCS_BUCKET", BUCKET) + monkeypatch.setenv("CACHEKIT_GCS_PREFIX", "env/") + transport.script(_Reply(status=404)) + + GCSBackend().get("k") + + assert transport.sent() == [("GET", f"/o/env/{_name('k')}")] + + def test_missing_library_names_the_extra(self) -> None: + """In an interpreter where no ``google`` package can load: the imports work, the constructor explains.""" + script = ( + "import sys\n" + "sys.modules['google'] = None\n" + "import cachekit, cachekit.backends, cachekit.backends.gcs\n" + "from cachekit.backends.gcs import GCSBackend, GCSBackendConfig\n" + "try:\n" + " GCSBackend(GCSBackendConfig(bucket='cache-bucket'))\n" + "except ImportError as exc:\n" + " print(exc)\n" + ) + result = subprocess.run([sys.executable, "-c", script], capture_output=True, text=True, timeout=60) # noqa: S603 + + assert result.returncode == 0, result.stderr + assert "pip install 'cachekit[gcs]'" in result.stdout + + def test_missing_credentials_is_an_authentication_error(self, monkeypatch: pytest.MonkeyPatch) -> None: + def no_credentials(project: str | None) -> Any: + raise DefaultCredentialsError("Your default credentials were not found.") + + monkeypatch.setattr("cachekit.backends.gcs.backend._build_client", no_credentials) + + with pytest.raises(BackendError) as exc_info: + GCSBackend(GCSBackendConfig(bucket=BUCKET)) + assert exc_info.value.error_type is BackendErrorType.AUTHENTICATION + + @pytest.mark.parametrize("project", [None, "my-project"]) + def test_client_gets_the_configured_project_and_looks_for_no_other( + self, monkeypatch: pytest.MonkeyPatch, project: str | None + ) -> None: + """No project configured means a client without one: object requests need none.""" + from cachekit.backends.gcs.backend import _build_client + + monkeypatch.setenv("STORAGE_EMULATOR_HOST", "http://localhost:1") # anonymous credentials, nothing sent + monkeypatch.setenv("GOOGLE_CLOUD_PROJECT", "ambient-project") + + assert _build_client(project).project == project + + def test_timeout_reaches_the_transport(self, transport: _Transport) -> None: + seen: list[Any] = [] + send = transport.send + + def recording_send(request: requests.PreparedRequest, **kwargs: Any) -> requests.Response: + seen.append(kwargs.get("timeout")) + return send(request, **kwargs) + + transport.send = recording_send # type: ignore[method-assign] + backend = GCSBackend(GCSBackendConfig(bucket=BUCKET, timeout=2.5)) + transport.script(_Reply(status=404), _Reply(), _Reply(status=404), _Reply(status=404), _Reply(body=b"{}")) + + backend.get("k") + backend.set("k", b"v") + backend.exists("k") + backend.delete("k") + backend.health_check() + + assert seen == [2.5] * 5 + + +def _serve(transport: _Transport, vector: dict[str, Any], ranged: bool) -> None: + body = bytes.fromhex(vector["file_hex"]) + transport.script(_Reply(status=206 if ranged else 200, body=body[:14] if ranged else body, generation=1)) + + +def _reader_clock(vector: dict[str, Any]) -> contextlib.AbstractContextManager[Any]: + if "reader_now_unix_seconds" not in vector: + return contextlib.nullcontext() + return time_machine.travel(vector["reader_now_unix_seconds"], tick=False) + + +@pytest.mark.unit +@pytest.mark.parametrize("vector", VECTORS, ids=lambda v: v["name"]) +class TestProtocolVectors: + """The protocol's file-backend vectors, served as objects (tests/unit/protocol/fixtures/file-backend.json).""" + + def test_object_name(self, backend: GCSBackend, transport: _Transport, vector: dict[str, Any]) -> None: + transport.script(_Reply(status=404)) + backend.get(vector["key_utf8"]) + assert transport.sent() == [("GET", f"/o/{vector['filename']}")] + + def test_get(self, backend: GCSBackend, transport: _Transport, vector: dict[str, Any]) -> None: + _serve(transport, vector, ranged=False) + transport.script(_Reply(status=204, body=b"")) # for the delete, when the action is one + + with _reader_clock(vector): + result = backend.get(vector["key_utf8"]) + + self._check(transport, vector, result, miss=None, hit=bytes.fromhex(vector["payload_hex"])) + + def test_exists(self, backend: GCSBackend, transport: _Transport, vector: dict[str, Any]) -> None: + _serve(transport, vector, ranged=True) + transport.script(_Reply(status=204, body=b"")) + + with _reader_clock(vector): + result = backend.exists(vector["key_utf8"]) + + self._check(transport, vector, result, miss=False, hit=True) + + def test_set_writes_the_vector_bytes(self, backend: GCSBackend, transport: _Transport, vector: dict[str, Any]) -> None: + """A writer never sets the reserved byte or a flag, so only unflagged vectors can be written.""" + if vector["reader_action"] == "miss_preserve": + pytest.skip("this writer emits no reserved byte or flag") + expiry = vector["expiry_unix_seconds"] + transport.script(_Reply()) + + with time_machine.travel(expiry - 60 if expiry else 0, tick=False): + backend.set(vector["key_utf8"], bytes.fromhex(vector["payload_hex"]), ttl=60 if expiry else None) + + assert _uploaded(transport.requests[0]).hex() == vector["file_hex"] + + @staticmethod + def _check(transport: _Transport, vector: dict[str, Any], result: Any, miss: Any, hit: Any) -> None: + methods = [method for method, _ in transport.sent()] + action = vector["reader_action"] + if action == "return_payload": + assert result == hit + assert methods == ["GET"] + elif action == "miss_preserve": + assert result is miss + assert methods == ["GET"] # not deleted, not rewritten + else: + assert action == "miss_expired" + assert result is miss + assert methods == ["GET", "DELETE"] diff --git a/tests/unit/backends/test_gcs_config.py b/tests/unit/backends/test_gcs_config.py new file mode 100644 index 000000000..28047815a --- /dev/null +++ b/tests/unit/backends/test_gcs_config.py @@ -0,0 +1,62 @@ +"""Unit tests for GCSBackendConfig. They need no google-cloud-storage: the config imports none of it.""" + +from __future__ import annotations + +import pytest +from pydantic import ValidationError + +from cachekit.backends.gcs.config import MAX_PREFIX_BYTES, GCSBackendConfig + + +@pytest.fixture(autouse=True) +def _no_gcs_env(monkeypatch: pytest.MonkeyPatch) -> None: + for name in ("CACHEKIT_GCS_BUCKET", "CACHEKIT_GCS_PREFIX", "CACHEKIT_GCS_PROJECT", "CACHEKIT_GCS_TIMEOUT"): + monkeypatch.delenv(name, raising=False) + + +@pytest.mark.unit +class TestGCSBackendConfig: + def test_defaults(self) -> None: + config = GCSBackendConfig(bucket="cache-bucket") + + assert (config.bucket, config.prefix, config.project, config.timeout) == ("cache-bucket", "", None, 10.0) + + def test_fields_are_exactly_these(self) -> None: + """No credential field: authentication is Application Default Credentials only.""" + assert set(GCSBackendConfig.model_fields) == {"bucket", "prefix", "project", "timeout"} + + def test_bucket_is_required(self) -> None: + with pytest.raises(ValidationError): + GCSBackendConfig.from_env() + + @pytest.mark.parametrize("bucket", ["", "gs://cache-bucket", "cache-bucket/prefix"]) + def test_bucket_must_be_a_bare_name(self, bucket: str) -> None: + with pytest.raises(ValidationError): + GCSBackendConfig(bucket=bucket) + + @pytest.mark.parametrize("prefix", ["a\nb", "a\rb", "x" * (MAX_PREFIX_BYTES + 1), "é" * (MAX_PREFIX_BYTES // 2 + 1)]) + def test_prefix_gcs_would_refuse_is_rejected(self, prefix: str) -> None: + with pytest.raises(ValidationError): + GCSBackendConfig(bucket="cache-bucket", prefix=prefix) + + def test_longest_prefix_is_accepted(self) -> None: + assert len(GCSBackendConfig(bucket="cache-bucket", prefix="x" * MAX_PREFIX_BYTES).prefix) == MAX_PREFIX_BYTES + + @pytest.mark.parametrize("timeout", [0, 0.05, 601]) + def test_timeout_bounds(self, timeout: float) -> None: + with pytest.raises(ValidationError): + GCSBackendConfig(bucket="cache-bucket", timeout=timeout) + + def test_from_env(self, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("CACHEKIT_GCS_BUCKET", "env-bucket") + monkeypatch.setenv("CACHEKIT_GCS_PREFIX", "cachekit/") + monkeypatch.setenv("CACHEKIT_GCS_PROJECT", "env-project") + monkeypatch.setenv("CACHEKIT_GCS_TIMEOUT", "2.5") + + config = GCSBackendConfig.from_env() + + assert (config.bucket, config.prefix, config.project, config.timeout) == ("env-bucket", "cachekit/", "env-project", 2.5) + + def test_constructor_beats_env(self, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("CACHEKIT_GCS_BUCKET", "env-bucket") + assert GCSBackendConfig(bucket="explicit").bucket == "explicit" diff --git a/tests/unit/backends/test_provider.py b/tests/unit/backends/test_provider.py index 52f1723b4..c86ab572f 100644 --- a/tests/unit/backends/test_provider.py +++ b/tests/unit/backends/test_provider.py @@ -386,6 +386,46 @@ def test_get_backend_returns_file_when_cache_dir_set(self, tmp_path: Path) -> No assert backend is mock_instance mock_file.assert_called_once() + def test_get_backend_returns_gcs_when_bucket_set(self) -> None: + """CACHEKIT_GCS_BUCKET alone → GCSBackend, built once from the environment.""" + from cachekit.backends.gcs import GCSBackendConfig + + provider = DefaultBackendProvider() + assert provider._gcs_backend is None + + with mock.patch.dict("os.environ", {"CACHEKIT_GCS_BUCKET": "cache-bucket"}, clear=True): + with mock.patch("cachekit.backends.gcs.GCSBackend") as mock_gcs: + backend = provider.get_backend() + + assert backend is mock_gcs.return_value + assert provider.get_backend() is backend + mock_gcs.assert_called_once() + (config,) = mock_gcs.call_args.args + assert isinstance(config, GCSBackendConfig) + assert config.bucket == "cache-bucket" + + def test_gcs_bucket_with_file_cache_dir_is_ambiguous(self, tmp_path: Path) -> None: + """CACHEKIT_GCS_BUCKET is a selector like the others: a second one raises, and the message lists it.""" + from cachekit.config.validation import ConfigurationError + + provider = DefaultBackendProvider() + + with mock.patch.dict( + "os.environ", {"CACHEKIT_GCS_BUCKET": "cache-bucket", "CACHEKIT_FILE_CACHE_DIR": str(tmp_path)}, clear=True + ): + with pytest.raises(ConfigurationError, match="Ambiguous backend") as exc_info: + provider.get_backend() + + message = str(exc_info.value) + assert "(CACHEKIT_FILE_CACHE_DIR, CACHEKIT_GCS_BUCKET)" in message + assert "CACHEKIT_FILE_CACHE_DIR / CACHEKIT_GCS_BUCKET, or pass backend=" in message + + def test_gcs_bucket_counts_as_configured(self) -> None: + """With only CACHEKIT_GCS_BUCKET set, in any casing, a decorator must not fall back to L1 only.""" + for name in ("CACHEKIT_GCS_BUCKET", "cachekit_gcs_bucket"): + with mock.patch.dict("os.environ", {name: "cache-bucket"}, clear=True): + assert DefaultBackendProvider()._is_configured() is True + def test_get_backend_explicit_redis_url(self) -> None: """CACHEKIT_REDIS_URL is an explicit selector → RedisBackend.""" provider = DefaultBackendProvider() diff --git a/tests/unit/test_l1_only_mode.py b/tests/unit/test_l1_only_mode.py index c62ca5ddd..74e177eab 100644 --- a/tests/unit/test_l1_only_mode.py +++ b/tests/unit/test_l1_only_mode.py @@ -617,7 +617,13 @@ def leaks() -> str: assert msg.startswith("encryption requires a backend") tiers = ["set_default_backend()", "CACHEKIT_*", "REDIS_URL"] assert [msg.index(t) for t in tiers] == sorted(msg.index(t) for t in tiers) - for selector in ("CACHEKIT_API_KEY", "CACHEKIT_REDIS_URL", "CACHEKIT_MEMCACHED_SERVERS", "CACHEKIT_FILE_CACHE_DIR"): + for selector in ( + "CACHEKIT_API_KEY", + "CACHEKIT_REDIS_URL", + "CACHEKIT_MEMCACHED_SERVERS", + "CACHEKIT_FILE_CACHE_DIR", + "CACHEKIT_GCS_BUCKET", + ): assert selector in msg def test_secure_with_backend_still_decorates(self): diff --git a/uv.lock b/uv.lock index 896135ec4..af625323a 100644 --- a/uv.lock +++ b/uv.lock @@ -5,7 +5,8 @@ resolution-markers = [ "python_full_version >= '3.15' and sys_platform == 'win32'", "python_full_version >= '3.15' and sys_platform == 'emscripten'", "python_full_version >= '3.15' and sys_platform != 'emscripten' and sys_platform != 'win32'", - "python_full_version >= '3.12' and python_full_version < '3.15'", + "python_full_version == '3.14.*'", + "python_full_version >= '3.12' and python_full_version < '3.14'", "python_full_version < '3.12'", ] @@ -243,6 +244,9 @@ data = [ { name = "pandas", version = "3.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.15'" }, { name = "pyarrow" }, ] +gcs = [ + { name = "google-cloud-storage" }, +] json = [ { name = "orjson" }, ] @@ -258,6 +262,7 @@ dev = [ { name = "cachetools" }, { name = "faker" }, { name = "fakeredis" }, + { name = "google-cloud-storage" }, { name = "h11" }, { name = "hypothesis" }, { name = "numpy", version = "2.4.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, @@ -309,6 +314,7 @@ test = [ [package.metadata] requires-dist = [ { name = "blake3", specifier = ">=1.0.5" }, + { name = "google-cloud-storage", marker = "extra == 'gcs'", specifier = ">=3.0.0" }, { name = "msgpack", specifier = ">=1.2.1" }, { name = "numpy", marker = "extra == 'data'", specifier = ">=2.0.2" }, { name = "orjson", marker = "extra == 'json'", specifier = ">=3.9.0" }, @@ -322,7 +328,7 @@ requires-dist = [ { name = "urllib3", specifier = ">=2.8.0" }, { name = "xxhash", specifier = ">=3.5.0" }, ] -provides-extras = ["data", "json", "memcached"] +provides-extras = ["data", "json", "memcached", "gcs"] [package.metadata.requires-dev] dev = [ @@ -332,6 +338,7 @@ dev = [ { name = "cachetools", specifier = ">=5.3.0" }, { name = "faker", specifier = ">=20.0.0" }, { name = "fakeredis", specifier = ">=2.21.0" }, + { name = "google-cloud-storage", specifier = ">=3.0.0" }, { name = "h11", specifier = ">=0.16.0" }, { name = "hypothesis", specifier = ">=6.0.0" }, { name = "numpy", specifier = ">=2.0.2" }, @@ -395,6 +402,104 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/c4/51/29046e48f693c54e5b7412216d447a1d8362c9653148d98c02cdf65fa733/certifi-2026.10.19-py3-none-any.whl", hash = "sha256:42d35340cc5b9ba78e818ddbff0c5b1c2b779de448a340fd1b989f5fa8670e1b", size = 136464, upload-time = "2026-10-20T02:24:15.072Z" }, ] +[[package]] +name = "cffi" +version = "2.1.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pycparser", marker = "implementation_name != 'PyPy'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9e/ef/008a1939e372c06329a3fce4279c02f328488f3526744906eeec3da7ad5f/cffi-2.1.1.tar.gz", hash = "sha256:dd31f52ea1086513bb9df30f8fcee9b8918323ae067a3d5b78bc826a000712be", size = 530807, upload-time = "2026-08-03T21:21:18.939Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/70/d2/16d99a0c4948febc0ebd133a13b2f688ff7f8cb04da971e1128872ce0c03/cffi-2.1.1-cp311-cp311-macosx_10_15_x86_64.whl", hash = "sha256:c8d2c9fd1f2d16f780d15127abb050d13d1a76c03a4bd87d7e4980e45e511e12", size = 183838, upload-time = "2026-08-03T21:19:29.637Z" }, + { url = "https://files.pythonhosted.org/packages/cd/95/31b535a9f0220ae9f357de4a08d57ce89cb417653c2fd9f075f50822a388/cffi-2.1.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:398aff33cee2767e3e781d2554c54bd0dff386bb437581e0d8011fde1a942ec1", size = 184168, upload-time = "2026-08-03T21:19:30.764Z" }, + { url = "https://files.pythonhosted.org/packages/ad/5a/4707a0dc1f203f5dde5a907b0d4e3c25d71120241048bd5bc6f1bb9d4e71/cffi-2.1.1-cp311-cp311-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:154852545011f779917b11c78db2358d095da62a9a172b78ad0a583ee5adc0d0", size = 211805, upload-time = "2026-08-03T21:19:31.867Z" }, + { url = "https://files.pythonhosted.org/packages/ad/66/c19feabb28485b6e0bbaaafa90837a1ef5d302e90f2178bd33f17a49879b/cffi-2.1.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:3311ed60d36f83378794e1009ac6258bafbf81f7888b4caa7b35a521e3f95813", size = 218716, upload-time = "2026-08-03T21:19:32.896Z" }, + { url = "https://files.pythonhosted.org/packages/a7/92/500760486c8baab49a7a8a58ba7fc3355ec3974b454b8a09e528efde9e1d/cffi-2.1.1-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:6e192623c49c94421616a5778fba35cf0d5a8d000650c1967ef4448ee5cdd990", size = 205569, upload-time = "2026-08-03T21:19:34.142Z" }, + { url = "https://files.pythonhosted.org/packages/a5/a7/a67c733254d6e7373f7822f8082d8d6beade791e0cf12a7611f376fa61c7/cffi-2.1.1-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a6e721d4b0e45d5b65e87534470e67b18dcd092c83f68fba09f152b9cbc061af", size = 204907, upload-time = "2026-08-03T21:19:35.174Z" }, + { url = "https://files.pythonhosted.org/packages/f7/a4/4399daaf8f7dfee9d7c3327fdb0426ee041cc63edc358b93911ceb2bfc7a/cffi-2.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:34e261f78cb6ceaaa36f42f2613f4380d94d9c759a9c73c769ee6e0247364632", size = 217807, upload-time = "2026-08-03T21:19:36.286Z" }, + { url = "https://files.pythonhosted.org/packages/28/f7/dabe6da2466ecbd82dc62e7342dc6b1065dad990c06f00f0ede9ebf2a0ed/cffi-2.1.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:7225e4514edb64eb6740324353e0da0711954fd8d7da4576755b1c6e09b697cd", size = 221252, upload-time = "2026-08-03T21:19:37.416Z" }, + { url = "https://files.pythonhosted.org/packages/ce/87/616202d8e51342c07d2534c510111c4cc37201775ce8f60802c9335d1edd/cffi-2.1.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:df913725b79db7bcf03448f36b7bf8815363417d5b58deecf9305e3e30f0f21a", size = 214214, upload-time = "2026-08-03T21:19:38.507Z" }, + { url = "https://files.pythonhosted.org/packages/b4/c6/ab025d75d2c26c19b087c0124e75ee31cb65032f4fe345d356d8c507ab97/cffi-2.1.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:f5cfbc5fe74540d335175b656c725d74d90e3730c626d92575eea35029d9afaa", size = 219408, upload-time = "2026-08-03T21:19:39.809Z" }, + { url = "https://files.pythonhosted.org/packages/db/e2/7e8109f65445bdc673a7b54f02c677de462db75674220fd1335efc8eb598/cffi-2.1.1-cp311-cp311-win32.whl", hash = "sha256:f8ec5e643a9a937f64e1999eb9f75d072263751912dc5cd06d3c85f8f44be7c3", size = 174470, upload-time = "2026-08-03T21:19:41.246Z" }, + { url = "https://files.pythonhosted.org/packages/73/c0/77ba02423c2f7d7091143c45cd49e0e6575c4c1967394bb542bd923a9b74/cffi-2.1.1-cp311-cp311-win_amd64.whl", hash = "sha256:42f6930c31dc7f50732c9ae793c2786c7b6b044195967bbdde40bb9be81c4cc0", size = 185096, upload-time = "2026-08-03T21:19:42.615Z" }, + { url = "https://files.pythonhosted.org/packages/7c/47/9f1f85f9672ceda4984dc6c4f8824e8558992a2972c3d3c81fb8eb28d4ba/cffi-2.1.1-cp311-cp311-win_arm64.whl", hash = "sha256:c7659f22557c5a0bc4855cd635f55edec690cc008a40768527762cb9fb263455", size = 179941, upload-time = "2026-08-03T21:19:43.747Z" }, + { url = "https://files.pythonhosted.org/packages/10/69/43965eccfdead3b9220015fd1320e117be8c6ed01a62ffab76eeb752f5d5/cffi-2.1.1-cp312-cp312-macosx_10_15_x86_64.whl", hash = "sha256:c8c69575568085ba0b1b10c0249d779a214aea6f6522e949a0fc9fb0fcb449d0", size = 184821, upload-time = "2026-08-03T21:19:44.887Z" }, + { url = "https://files.pythonhosted.org/packages/54/7d/16e5a096677b5e313ca80cd5e5170efa3ea44624a82bb111925522da64b1/cffi-2.1.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:f81b3b8f3d4e343550fa4baa0e479bba9f2d29ce9c2e9b51d1ce1718d7442fcf", size = 184719, upload-time = "2026-08-03T21:19:46.129Z" }, + { url = "https://files.pythonhosted.org/packages/56/e6/8941622732edec876dd17d0453dce07317ae96db34f2ec1436c9d3785986/cffi-2.1.1-cp312-cp312-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:811bd1e21d32de12efca32393a0ab3f5133b54fce9bd44b8bd77ab07da14bf6a", size = 214799, upload-time = "2026-08-03T21:19:47.218Z" }, + { url = "https://files.pythonhosted.org/packages/44/de/f98430906df1545ffde0d543dd124a7a439bc2cd32b36b9c53f805df7333/cffi-2.1.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:68e62fe11f30d5ca8289242866f0a5291402d8529ca2178ab8afc5c9694ae890", size = 222389, upload-time = "2026-08-03T21:19:48.331Z" }, + { url = "https://files.pythonhosted.org/packages/6a/5b/717f1526b9957b34456313c31645c5b82b8fb5c3fe9e4752999be7128bfc/cffi-2.1.1-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:4a7c934f7360e8cd64fe9efadcbd10c7c6364f531e432b9a4bf5ccbc9e0e8b50", size = 210249, upload-time = "2026-08-03T21:19:49.543Z" }, + { url = "https://files.pythonhosted.org/packages/64/b3/f8aa4f3e34986c7e4ec45072d1b1b9dd295b6b18007b45518d79726dd725/cffi-2.1.1-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:3143d81e29e1e20a9ce10901ec369012947876596f75a222235965f2b7ae832e", size = 208775, upload-time = "2026-08-03T21:19:50.918Z" }, + { url = "https://files.pythonhosted.org/packages/b1/db/dceb9dd5b231e1da801793f8acc9f3c52a7e1afe40bb1aae37e02b0faad5/cffi-2.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c1453022f490d2459a11819d83ad1d586e9ff65a12ac3e705ffebd46d3685dcf", size = 221822, upload-time = "2026-08-03T21:19:52.054Z" }, + { url = "https://files.pythonhosted.org/packages/a0/d2/6cd24ae3be000a634109c247d1475d62e5616d0dc78c82770942ec384248/cffi-2.1.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:208f941bb9d18e768138677f0a6d2ce01f590df56043dda1df1535ac57c88517", size = 225232, upload-time = "2026-08-03T21:19:53.109Z" }, + { url = "https://files.pythonhosted.org/packages/cb/52/3fa190537004dd7f0ab860a6dc7c0175b8667f68d1e618a46f5498d30250/cffi-2.1.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:210019b6c7cf07f081b4c54635c8cf744377001350e29cc0f81c4377b4797735", size = 223597, upload-time = "2026-08-03T21:19:54.515Z" }, + { url = "https://files.pythonhosted.org/packages/80/fb/0bb75b7039588c074b37ae99f40d9bfddf990ecb2fbc346ebccd2e56b9be/cffi-2.1.1-cp312-cp312-win32.whl", hash = "sha256:046bfc24911b37851ee1b51aab8bffe713d89c68c6a057b09484ce9fd5f69b4e", size = 175292, upload-time = "2026-08-03T21:19:55.566Z" }, + { url = "https://files.pythonhosted.org/packages/d9/79/615cc094e2fb508cade7de88d3b4f6c4ec2bab695c97bce9153dc65aadf5/cffi-2.1.1-cp312-cp312-win_amd64.whl", hash = "sha256:f53e442b08449d42821fa4a4fba000095af9f62742a500f978a9f557ec44339a", size = 185919, upload-time = "2026-08-03T21:19:56.89Z" }, + { url = "https://files.pythonhosted.org/packages/70/c6/d0ea84713fe46b243a436a18fcd47d639732747e21635c8a27191b06dc30/cffi-2.1.1-cp312-cp312-win_arm64.whl", hash = "sha256:7bde5e4cc5c10140859842b9d383af292b22639a4dffb725314baf45968cef80", size = 180093, upload-time = "2026-08-03T21:19:58.155Z" }, + { url = "https://files.pythonhosted.org/packages/9d/f4/035513d4117049066b4779dc3b7c0c0fdad175fa13731c9f4003f1cd1478/cffi-2.1.1-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:b5bdfd1c873d4e093aabc0ca84c4ca6dbc4f752afb5c86f146d9742580c9da2e", size = 194248, upload-time = "2026-08-03T21:19:59.399Z" }, + { url = "https://files.pythonhosted.org/packages/76/af/2aeb4dbb5fc41a04161ae9ff1518de7cec08e164f44a8ce6a4cf7fd2cd1d/cffi-2.1.1-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:31348097ff5bbe827ccc41795d4dd099d9f0625e7def00ee653c137a490c2a6c", size = 196908, upload-time = "2026-08-03T21:20:00.746Z" }, + { url = "https://files.pythonhosted.org/packages/a7/46/2e5fdde8555706dd98139a910ca11be02809f3f605ce956f655d0214e100/cffi-2.1.1-cp313-cp313-macosx_10_15_x86_64.whl", hash = "sha256:9d2055050ea716bd38b7f7f1579c275386646b4894c155a3e2f3cd62ed41b7c6", size = 184805, upload-time = "2026-08-03T21:20:02.02Z" }, + { url = "https://files.pythonhosted.org/packages/55/41/4c7042f317b9217502988f0873af87e16ad606dc20f84e546e3e6ce9764c/cffi-2.1.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:19ee6127ee34de7d83ce3d371ebc5ed91addbdcc39f9ab15ce4eb35a4e534971", size = 184764, upload-time = "2026-08-03T21:20:03.141Z" }, + { url = "https://files.pythonhosted.org/packages/43/1f/1c3d90d91811c8f86ced9ed637956c54bfe5b79ca98fe976d7f8c8979f6b/cffi-2.1.1-cp313-cp313-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:6a8dddef476fab96d066d578fc88526767b836ab5ab21754e1d5bf3879c31c7c", size = 214722, upload-time = "2026-08-03T21:20:04.377Z" }, + { url = "https://files.pythonhosted.org/packages/37/6f/3b5ce4c3b2192d250f04908f2bfd91ef34552ec8f7716a5d4abdb8d67bb2/cffi-2.1.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:f16c709686a78c727bbbf059f92b0bf41c6fc60deec706d2dc19f529175a6125", size = 222369, upload-time = "2026-08-03T21:20:05.544Z" }, + { url = "https://files.pythonhosted.org/packages/02/10/4b3c75dde3d9663c9e02ba05c2668b954f671d4bbe346413ca8c696b295a/cffi-2.1.1-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:fcd22650c908d7b7da162bbfaab594a1227a15d1643a98c68b122ac642fa2264", size = 210175, upload-time = "2026-08-03T21:20:06.75Z" }, + { url = "https://files.pythonhosted.org/packages/df/62/14f74b9543e605d17701dc797b815958b8bb70b7624ce1b832ddad48ed6c/cffi-2.1.1-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:aa9511c62d14da7aacc9b4bf51f3f697a621e83b2d6919008243c3aad168eea3", size = 208670, upload-time = "2026-08-03T21:20:08.04Z" }, + { url = "https://files.pythonhosted.org/packages/95/95/86342356ff5953b3fb06f7ef7c5bee212d45e770abc7218d451b9148313c/cffi-2.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:a931079504ecc49efed7744c476a5c343a92fabf66dec2db95edb1b2fdc770e2", size = 221824, upload-time = "2026-08-03T21:20:09.274Z" }, + { url = "https://files.pythonhosted.org/packages/eb/ff/7b3429ff53aafe931ed8a5fc69f481bbef7ba6de87ddcbb63d08f483f613/cffi-2.1.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a2d7755bef5a12ed488f4ef1f1b69ee9191d7396083b755a5d2295f6edb4768b", size = 225148, upload-time = "2026-08-03T21:20:10.7Z" }, + { url = "https://files.pythonhosted.org/packages/34/34/a95870b9221e09cf4f2ce3178b1a210abdfe63a1bd357da940418d7b8d15/cffi-2.1.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:e0bcb7e0f677f543555d2adff3bf19c05f66cdb4796e5ff602442ab2fe3c4ef7", size = 223564, upload-time = "2026-08-03T21:20:12.165Z" }, + { url = "https://files.pythonhosted.org/packages/70/ea/839b50531021a647fb5e929f72cf97bc1ff702b5472166164b5b6e76b851/cffi-2.1.1-cp313-cp313-win32.whl", hash = "sha256:334644fbac4eff73d985a17a91226df55d0f394160c4cfb880e084c8f7161cac", size = 175263, upload-time = "2026-08-03T21:20:13.559Z" }, + { url = "https://files.pythonhosted.org/packages/60/a6/8b149b2c3f2e11aaa1618ef64500b45f50f22c57a977a4dff1aff1f91042/cffi-2.1.1-cp313-cp313-win_amd64.whl", hash = "sha256:1aa5645c30469b09530c4ebca77ebf8f17618293c58f8549cb1a543a50236e7d", size = 185688, upload-time = "2026-08-03T21:20:14.69Z" }, + { url = "https://files.pythonhosted.org/packages/01/9a/11f687cb39d6a3504060d5242f04f48c735afb4d3d533958a20594890cb2/cffi-2.1.1-cp313-cp313-win_arm64.whl", hash = "sha256:63bbfd5ded17c4840ac07cd8f1c21ba9d9708141f840b324f422f41b207e3973", size = 180078, upload-time = "2026-08-03T21:20:15.917Z" }, + { url = "https://files.pythonhosted.org/packages/d3/7b/d6bbf82b8b96e7391438898c42f5bd96dd02030fd5b64937d248220003e2/cffi-2.1.1-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:7dbb61fe3a7699468030f71bbe5f8a0e326a151daa91beb11a6fc1f980c55e1c", size = 194064, upload-time = "2026-08-03T21:20:17.148Z" }, + { url = "https://files.pythonhosted.org/packages/94/e6/bcc91b283be94735e268487a054004f0aa19947b6348fa367db53230abc8/cffi-2.1.1-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:f24fb43132a4c6b4cb4eb029492919b2db645be6808d738f244fd146c03c32cb", size = 196720, upload-time = "2026-08-03T21:20:18.268Z" }, + { url = "https://files.pythonhosted.org/packages/d9/99/c4b0c17cacdc9c3b8f280026286a9826d6a208c0f047591a3c3ce99b91fd/cffi-2.1.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:d28630f5854ab07ab1fd4aba756de52326c82e6be15d414b12793f1975048b54", size = 184964, upload-time = "2026-08-03T21:20:19.708Z" }, + { url = "https://files.pythonhosted.org/packages/b3/a9/9db617d05d7367c1ad0ab00b3aa6e6f9281edd689b4ee9ea0e5a84e89c97/cffi-2.1.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:661c298b4821edebead0c91edd2b00374d67ad7c5a1f7a91d4442633b79d6a72", size = 184962, upload-time = "2026-08-03T21:20:20.833Z" }, + { url = "https://files.pythonhosted.org/packages/67/b8/b42132ca113dc567d37684437b46ca1dafc885902b02a110a02d5b511857/cffi-2.1.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:58acb8ab8e295e6c5ea12f888cbb13cf21511ef2a3303a23f4325c29d17fe5c1", size = 222328, upload-time = "2026-08-03T21:20:22.118Z" }, + { url = "https://files.pythonhosted.org/packages/80/10/c5c0cbf0a657aecf59ef511409734230bf556f05a0d6c9eed7aa5c0a0166/cffi-2.1.1-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:456a61fa52d579ebf9df2e9552ead5129855dbaff6c1e5a9b1bc408809bdc062", size = 209985, upload-time = "2026-08-03T21:20:23.401Z" }, + { url = "https://files.pythonhosted.org/packages/d5/6c/bfa0b87b03b9238148beca990292843c9396ba069b54496596594173de7b/cffi-2.1.1-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a4f00aa42f75d6e4595e8866e748cc1705adc0cddfeb2ca86d0d03993d63ba03", size = 208530, upload-time = "2026-08-03T21:20:24.628Z" }, + { url = "https://files.pythonhosted.org/packages/e9/02/4e7d553a7ac4b4238b38b3c1b80d486e9d4436f8d2acbf87a0997fe3f402/cffi-2.1.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:b0431303acaea1089ad4b3e9ce4e6518193def1118d4073ca848635ee4ea2e96", size = 221525, upload-time = "2026-08-03T21:20:25.758Z" }, + { url = "https://files.pythonhosted.org/packages/82/1d/a4aaf9babd75acb4d5f223bff71533bee748dd770a382619a798960ee9ba/cffi-2.1.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:64faea20f4e2613363a1a9b9c7dd73058f3ecd00133a511e72ad7c511658f527", size = 225053, upload-time = "2026-08-03T21:20:26.985Z" }, + { url = "https://files.pythonhosted.org/packages/81/10/5dc0e7bdd18e22107054288283380fc97a06ae3f1656a106908d666a3c88/cffi-2.1.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:5c58fe613dc5e5336357eff555824a314d8e43282600435c8d1cb6a7a2fedd13", size = 223213, upload-time = "2026-08-03T21:20:28.277Z" }, + { url = "https://files.pythonhosted.org/packages/0b/e9/d0061c364cde06ee43168a0d076ac1da512cbc380d44767b844ba34fe2b6/cffi-2.1.1-cp314-cp314-win32.whl", hash = "sha256:1a18a57b58cfb21fc28d72e876acf10eaed67a1ed96226f92af4df681d571c4c", size = 177682, upload-time = "2026-08-03T21:20:44.288Z" }, + { url = "https://files.pythonhosted.org/packages/a7/06/1c3e01e3ba14c39f6d10bfbac52753b7e22259e38088e5cfe1d704918690/cffi-2.1.1-cp314-cp314-win_amd64.whl", hash = "sha256:3222ba5d678f80a030e6afbcc33dc1ae5cb45facabb61cee2c7016b8432fde48", size = 187949, upload-time = "2026-08-03T21:20:45.623Z" }, + { url = "https://files.pythonhosted.org/packages/87/5b/da4e39efe18eeb89cf580ea9cfc66b6a7c3eadb808fc0cc1d3a295cb5a5d/cffi-2.1.1-cp314-cp314-win_arm64.whl", hash = "sha256:ab36d55f9ed2d067327667c2fea18dda018eb628dd6347aa01dda6cf1f5d3836", size = 182947, upload-time = "2026-08-03T21:20:46.955Z" }, + { url = "https://files.pythonhosted.org/packages/23/59/40338bf421c5accea1d45158170c87006ef1cd371b05c077e76476949728/cffi-2.1.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:7750c6449dff7864bb9bb27ddfb0267756189201a3afc911d82b3caacd70dfc3", size = 188504, upload-time = "2026-08-03T21:20:29.495Z" }, + { url = "https://files.pythonhosted.org/packages/7d/47/5ecf1023850036e674c77ec4de86182d309ae344e39e7cba984b7df5d647/cffi-2.1.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:0beceaabe56af686895136a2de78db54ecd8e4046b236b8fd6d6cb61389e9bf2", size = 188259, upload-time = "2026-08-03T21:20:31.291Z" }, + { url = "https://files.pythonhosted.org/packages/2a/9c/92934c3bea9f785b23eba304538c0b4d37a2a96d2431eb3a1bc87a11aa19/cffi-2.1.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:49cbc70e6542d4ccccb936558d1064a8012541e78f821f955cff24e357776c94", size = 223864, upload-time = "2026-08-03T21:20:32.571Z" }, + { url = "https://files.pythonhosted.org/packages/4d/45/ba4c93527bc38616a8bd36488acb69a2212d60486794f0c1f318949bbb76/cffi-2.1.1-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:e2d65b31f36619cda3999b78b2aa9632e76b78448e7a56fc4240824200e7c4fc", size = 211538, upload-time = "2026-08-03T21:20:33.808Z" }, + { url = "https://files.pythonhosted.org/packages/80/e9/b6ef565e452acb932fb0cb5443f44a78efbd1233e566f02b5a83855e9115/cffi-2.1.1-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:28907ab9bfb6aa13184cfc17c6b8e1023c5ab6fd7076d8c20a35e59fe04f8f29", size = 210688, upload-time = "2026-08-03T21:20:34.974Z" }, + { url = "https://files.pythonhosted.org/packages/9a/95/eff5f0cee78d2eabc7eebffec40d3fc1876b5f3c95582e018bb4b99601f2/cffi-2.1.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:51b31d1c98274844cfd7838ce00bfc27c7423a4dc00fc0772fc3331c2cc90676", size = 223803, upload-time = "2026-08-03T21:20:36.564Z" }, + { url = "https://files.pythonhosted.org/packages/fa/01/579d39fb8bef00a335a23d83757b44feb24cd6345a2c451b64cb67b9c362/cffi-2.1.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:5e7cecbaadb83884793e05828cee59b210b24583b9c7425d0ba6a754fe22eb4e", size = 226763, upload-time = "2026-08-03T21:20:37.816Z" }, + { url = "https://files.pythonhosted.org/packages/8d/b0/0b44f47c60b01b57b6e2bbd92343f13a85a1d93bc46ccf6e47e244acd99c/cffi-2.1.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:25792eac27877609e7bb06d42ff88278a6624fff2ba9bbb523c09616b117e80f", size = 225688, upload-time = "2026-08-03T21:20:38.959Z" }, + { url = "https://files.pythonhosted.org/packages/eb/d2/3b7176cb570a1d3e27faf67b72f591af508036e0d8b2be2ef9af9e8c84bb/cffi-2.1.1-cp314-cp314t-win32.whl", hash = "sha256:8ef53b2de9bcb9197d31854256575d59dbac0cba72ac627bb291ef5eceb74be4", size = 182868, upload-time = "2026-08-03T21:20:40.388Z" }, + { url = "https://files.pythonhosted.org/packages/56/78/31f00c1bcd97c9bbf55f1bfdf5bc809a5de8887473e90bb9960dca825e80/cffi-2.1.1-cp314-cp314t-win_amd64.whl", hash = "sha256:616f097f2fe415bc92a247f02e11f634e1f9e9a83d327e3c915c15089c87869e", size = 194104, upload-time = "2026-08-03T21:20:41.725Z" }, + { url = "https://files.pythonhosted.org/packages/7b/1b/58496f2ed0a35de575250c02a43ab3cc2c04d494a88fed31c1cabc0fd176/cffi-2.1.1-cp314-cp314t-win_arm64.whl", hash = "sha256:ad2c86c495b899d862ea0f4b42891b8713a3bd45dd4105c7fd51c2a72f39f3a5", size = 186402, upload-time = "2026-08-03T21:20:43.042Z" }, + { url = "https://files.pythonhosted.org/packages/c1/8f/9ebe220eab48a093d1a5a5e339ab0dc7316eef3bb04d63c42f0251b61f50/cffi-2.1.1-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:dddad92b554513a31f272570678ba307fb9f618f05e3d4a5eacafff9eae03e1d", size = 194043, upload-time = "2026-08-03T21:20:48.179Z" }, + { url = "https://files.pythonhosted.org/packages/ff/69/844bad3ece306c4782c2ecb93597035b6690d48704b803914c199da1e8b3/cffi-2.1.1-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:da0e573f9f97159390c89d9f1a9e41908b66d408cc5b58d08cf3847d844c531b", size = 196737, upload-time = "2026-08-03T21:20:49.457Z" }, + { url = "https://files.pythonhosted.org/packages/1b/8a/af668013284634733f02d683458a0728739c7d6ddb5e14cb0c20832266fe/cffi-2.1.1-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:fb92203a88b3d3053034db775110081c49d28be6551923805e039924093761e4", size = 184933, upload-time = "2026-08-03T21:20:50.639Z" }, + { url = "https://files.pythonhosted.org/packages/0c/75/2f5207ff6d1a613133b23a5203cc0c2a628313b5eb3974d7956ae3c57950/cffi-2.1.1-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:2ae64be792b8966f2c69538199728b290e34726562896df1e5dc8ffd8d8188e8", size = 185002, upload-time = "2026-08-03T21:20:52.173Z" }, + { url = "https://files.pythonhosted.org/packages/e2/31/9e1313b0a6e30e91b3b3d3fff51ae99c857c07738e3afcce1f7334e1b7ab/cffi-2.1.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:507a24c282e0f42f8ed737cf048572cbf580468da5555764a8331735e9c736b6", size = 222271, upload-time = "2026-08-03T21:20:53.462Z" }, + { url = "https://files.pythonhosted.org/packages/50/e3/f6234a833e6e08c7007003074723c406559eecf9b48dfc97471e5a8eb7a0/cffi-2.1.1-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:246fa40ce8645a614ff682e0b70f37134e460eaf93a775e0cbe3cca585a67a80", size = 209919, upload-time = "2026-08-03T21:20:54.783Z" }, + { url = "https://files.pythonhosted.org/packages/0d/fc/5f74e293fced6edb51af3a46c4ccf6c23c9943774ecb375ddbd522c76add/cffi-2.1.1-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:471cee653ae88de62096552e6d24ccb4a5adb8c8c9f10b5054d0122c15bf2779", size = 208529, upload-time = "2026-08-03T21:20:56.066Z" }, + { url = "https://files.pythonhosted.org/packages/44/16/29e6d01b388bef055ecd6ca8244b3f4d336bd09e92d5d892187b9601084e/cffi-2.1.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:aeae0e330c9f6acd681f647d46cefd30c29f93e3392882e792e82080c9691399", size = 221630, upload-time = "2026-08-03T21:20:57.336Z" }, + { url = "https://files.pythonhosted.org/packages/a4/18/fa7f1f6857d5eb88a4ca99ffcbfb7c387a287ccc154c64a73e86314745d7/cffi-2.1.1-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:42a494cee34437f05546455144f2b5d9ac09b1face62bcfce597d2e521066688", size = 225134, upload-time = "2026-08-03T21:20:58.675Z" }, + { url = "https://files.pythonhosted.org/packages/e0/9f/e8e3dfa04a1b4c241f8c91faacad872b4d4efd051d49764ad4e2fd4b9fea/cffi-2.1.1-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:cc572dace3f60ef98d7b12ff411d20f5362feb31a0439eab0085bbfd349982d7", size = 223197, upload-time = "2026-08-03T21:20:59.968Z" }, + { url = "https://files.pythonhosted.org/packages/f8/7e/8debeb04f1ab9fe2a6963964cd6f1aaf7192627b83926586a6a4e089c9fa/cffi-2.1.1-cp315-cp315-win32.whl", hash = "sha256:4f42141fc14250de6dde5ee7ea4432be017252d91f19c5ad043c084cea629cac", size = 177683, upload-time = "2026-08-03T21:21:14.901Z" }, + { url = "https://files.pythonhosted.org/packages/e0/31/5158704cc474ab65c1647932e88be78dc0873f47130e253be38bcaf13d01/cffi-2.1.1-cp315-cp315-win_amd64.whl", hash = "sha256:e6e8cff14d6fb0be70a09c0bdc58096f501952d04624ebf867e0e56da2df8960", size = 187897, upload-time = "2026-08-03T21:21:16.108Z" }, + { url = "https://files.pythonhosted.org/packages/cc/4b/b3a2da8570c704ffc0f9762cdc3ec0f02c8573798e0b5cf7f11c82bbb70f/cffi-2.1.1-cp315-cp315-win_arm64.whl", hash = "sha256:27350daa11d4f10c540e6e89dada4c54feb7256ad03e9a4dc075ebad7ba360d1", size = 182935, upload-time = "2026-08-03T21:21:17.271Z" }, + { url = "https://files.pythonhosted.org/packages/d0/ef/5443574510a1207e6f6bc38ba6e1f1de36cb48fef07b2728bb896a21f430/cffi-2.1.1-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:c26608d2222fb1e94487e4a387d85f13eb55d5ed725cb25a0c589ac4ee60e7bc", size = 188464, upload-time = "2026-08-03T21:21:01.163Z" }, + { url = "https://files.pythonhosted.org/packages/7e/ae/a56fa8c4686ad50e148fcbc8d3ae0d03915ff5c30d795058988c24118cef/cffi-2.1.1-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:4be96343e422f2dfcd12ab5c9f5aebe03f82f737c6bffeca6830b3875cb44aab", size = 188262, upload-time = "2026-08-03T21:21:02.382Z" }, + { url = "https://files.pythonhosted.org/packages/53/b2/6187f46f2912276a3ae284076109cc5c8680482f11f766ccf26db4a86427/cffi-2.1.1-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:937c0052c05a31ca1daf18de3158eed4dbfcb9cc107adbea227728d647be701e", size = 223779, upload-time = "2026-08-03T21:21:03.553Z" }, + { url = "https://files.pythonhosted.org/packages/8a/f6/c3ad28bd19f77047a03084424fbd4cbe997303267c14423737324be0385d/cffi-2.1.1-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:df423d40ee8654634421812bc3b196da3f9bd7d32929da813f8394c4348a5358", size = 211520, upload-time = "2026-08-03T21:21:04.863Z" }, + { url = "https://files.pythonhosted.org/packages/a0/cd/ccac9013a5bd9fd764de118674ab9c805b5ca10c19270d90ee273f8b2240/cffi-2.1.1-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a730a083190634c65cca36ba5f489531576ebd79bcd5c8e172130f6453127231", size = 210673, upload-time = "2026-08-03T21:21:06.223Z" }, + { url = "https://files.pythonhosted.org/packages/52/86/2976131c639aead931c5bee5aba67e4b09fbeb8018b6f282f70803f923a7/cffi-2.1.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:363e05fa78e15116c3c32c210ee36884fd6b9afa6d440e47112c3bd511d64cb6", size = 223835, upload-time = "2026-08-03T21:21:07.539Z" }, + { url = "https://files.pythonhosted.org/packages/ac/0c/33a7aeab2f9c76918c52e084beb39c570db3588133412929e8ec06fab90b/cffi-2.1.1-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:770de9db11e84213beec501cfcaa013b019820ca881e03344dea5844f7876d94", size = 226705, upload-time = "2026-08-03T21:21:08.774Z" }, + { url = "https://files.pythonhosted.org/packages/e3/26/2cde30fdde421130bfc18f70395731a6e6b2053c6a1978a5258ff04e72fa/cffi-2.1.1-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:7da0c5eff80f0197f3b3d1232ec5a682a9325f4ae9016a78f5f5ca35f9ced1f5", size = 225539, upload-time = "2026-08-03T21:21:09.911Z" }, + { url = "https://files.pythonhosted.org/packages/6d/cd/a361394c94b2129d604bb846f624a8e88255a3ee33129c434a00d715e64f/cffi-2.1.1-cp315-cp315t-win32.whl", hash = "sha256:06c72bb76605a4b0cd0aad6930b69d4baf7dd5d806cfc409b824191099700e66", size = 182707, upload-time = "2026-08-03T21:21:11.226Z" }, + { url = "https://files.pythonhosted.org/packages/9b/b5/ba2b299993c26577d529b6ae29841f9e15b9fcf004d65f423f4fcf94ade9/cffi-2.1.1-cp315-cp315t-win_amd64.whl", hash = "sha256:d9c275eaacd24aa73f94ffd6de08fc3f932424d8b6c376f4bed7cde376fe7bc3", size = 193772, upload-time = "2026-08-03T21:21:12.39Z" }, + { url = "https://files.pythonhosted.org/packages/aa/29/35e016098c814cd93de9cd320c66b5bfba14dc6ecedd3cb518fa7c408c69/cffi-2.1.1-cp315-cp315t-win_arm64.whl", hash = "sha256:d18e5ac0f2f03f4f518d3e23db0f0cad7faa1da8620e9c09461d443bbf6e6692", size = 186360, upload-time = "2026-08-03T21:21:13.636Z" }, +] + [[package]] name = "charset-normalizer" version = "3.4.4" @@ -569,6 +674,75 @@ toml = [ { name = "tomli", marker = "python_full_version <= '3.11'" }, ] +[[package]] +name = "cryptography" +version = "50.0.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cffi", marker = "platform_python_implementation != 'PyPy'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9d/af/182eb91b0df3fe75c4d9f26fe70684569566745f6ba7e5c9c73a862c5252/cryptography-50.0.2.tar.gz", hash = "sha256:7b46165bb56eb4704e2eaaf86f3c940d19154535d9b0ca7d6d590b04060e00d5", size = 880623, upload-time = "2026-09-30T15:30:04.884Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e5/56/d194340cc4a57535e82e1bee9e89667ac4b7c13b5d3f59686deae3094dd5/cryptography-50.0.2-cp311-abi3-macosx_11_0_arm64.whl", hash = "sha256:fa8f5efb344d6908a1ce62f4a24e2e5780f825d6f53f5f50ec5ffacac72936cb", size = 3914904, upload-time = "2026-09-30T14:43:44.339Z" }, + { url = "https://files.pythonhosted.org/packages/d9/69/c9bd862c3bf43d6399c433caf002df16e2dffd4be49bdf515cda38038711/cryptography-50.0.2-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:79def8d059362e7831389ed3be0ecdf58a89386e1271e35dd9f5af84e81bffd0", size = 4731146, upload-time = "2026-09-30T14:43:47.113Z" }, + { url = "https://files.pythonhosted.org/packages/21/69/64cef1f702bf6657e0cc186ed1a2891d50d29fb41586b254e1c07adea261/cryptography-50.0.2-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:630ebfea3bf689d075f82316324ff7433dc447fe6bc1bfc76524b74b4a9567d2", size = 4719841, upload-time = "2026-09-30T14:43:49.01Z" }, + { url = "https://files.pythonhosted.org/packages/38/6b/61a3f8d8c5e1e49a6cddccafc4015cc1c0021360ab0acb4080e7a423644a/cryptography-50.0.2-cp311-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:f9f6143a8c75945eb960d9eb98905a441394abfa24afaae239d514ffb2586480", size = 4738340, upload-time = "2026-09-30T14:43:50.932Z" }, + { url = "https://files.pythonhosted.org/packages/7b/2e/7212ca32fd43dc91f2f41db20160b268098874b4c9a0e7be94d6835f5b2e/cryptography-50.0.2-cp311-abi3-manylinux_2_28_ppc64le.whl", hash = "sha256:a582ab2ae1d34f67112cadc86702774c9ea4374df6bca6afe672817203c99134", size = 5367029, upload-time = "2026-09-30T14:43:52.911Z" }, + { url = "https://files.pythonhosted.org/packages/1a/f1/b474e930c4d910328780e3940da76f5aa5cbc48ce1fc14e44d239d9ea9db/cryptography-50.0.2-cp311-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:4061c0079120205fb760c58acab6443e217307dcf05e3702cf970e0689972856", size = 4753050, upload-time = "2026-09-30T14:43:55.272Z" }, + { url = "https://files.pythonhosted.org/packages/7c/52/9af10e80ac16b0fcc2123f9cbd5e7afbd0fd5075bb7a607c592258a39cda/cryptography-50.0.2-cp311-abi3-manylinux_2_31_armv7l.whl", hash = "sha256:ac9ed99d81760c62fe89d5f0815cdfa1ba9a35141cf30f1c2d044f04b4803d2e", size = 4376724, upload-time = "2026-09-30T14:43:57.24Z" }, + { url = "https://files.pythonhosted.org/packages/71/37/6202e488cc1eb625ea110c292c6bda92823176e023f427d8d5660ce8d632/cryptography-50.0.2-cp311-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:87e9ce85beb6b328ba370cc6e6aea483c92617b4c95b1d33a49297eb662bfb04", size = 4737859, upload-time = "2026-09-30T14:43:59.541Z" }, + { url = "https://files.pythonhosted.org/packages/8f/30/e86d7d518489b0ae2497091a35287abcb1a2ce4037837a34afbe9b1d6964/cryptography-50.0.2-cp311-abi3-manylinux_2_34_ppc64le.whl", hash = "sha256:f265528741e048bce55c3463ed721fb0aa45a5888d8add8cfeccb3035451bbdc", size = 5324103, upload-time = "2026-09-30T14:44:01.901Z" }, + { url = "https://files.pythonhosted.org/packages/d3/69/2c833a049475e0a3444e94c7d0aca0aa51d166374a449b09e92ac98138de/cryptography-50.0.2-cp311-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:9dab55f57c74c3cad24c323bacbbd04be4705ba6eb0d92e920b1fc4837ed5079", size = 4752576, upload-time = "2026-09-30T14:44:04.545Z" }, + { url = "https://files.pythonhosted.org/packages/6c/5d/906970b83bbfc1f5bbfb677a143c181f2801f23b6a7204a3b47c42c97e65/cryptography-50.0.2-cp311-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:25784ce8b9621c90c643efb9e1e2162ab3b0224cae446ad5e70e7fcb1ce18b51", size = 4870819, upload-time = "2026-09-30T14:44:06.884Z" }, + { url = "https://files.pythonhosted.org/packages/68/e3/f2298d3bb55e0c4a91841ec4d01b3f020ba8c5fbf15ccdcc6dcf03f97025/cryptography-50.0.2-cp311-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:85d0d9a31b9098e98534226d5686b47264b95e62ce459dc2e62fdfc809f9fe93", size = 5030152, upload-time = "2026-09-30T14:44:09.443Z" }, + { url = "https://files.pythonhosted.org/packages/9a/4f/adfc442765721292fff86d314ce385d3249d22db42295c0dd057727b60f3/cryptography-50.0.2-cp311-abi3-win_amd64.whl", hash = "sha256:7afa5a6602a9f29af1f3a2965f831bae7c9d5d597b7cbb716d41ab3b7d89879c", size = 3824692, upload-time = "2026-09-30T14:44:11.671Z" }, + { url = "https://files.pythonhosted.org/packages/ce/cb/52eb3770c0d0be2702a98c6e96065ddc0a2877cf0845aa9c23397c142cd4/cryptography-50.0.2-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:f785f6161f202ab04d8ca194158968798e480ca058943907972da5f12e2881e8", size = 3892731, upload-time = "2026-09-30T14:44:13.485Z" }, + { url = "https://files.pythonhosted.org/packages/19/8e/aa1fc533d4546b127b45de8aa024eb5933d23eff9debfe25931e56861095/cryptography-50.0.2-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:0ecbc5652bdb6fc9eaf89a7d196e20941adfe812f43bc4ca05d9150496821047", size = 4710431, upload-time = "2026-09-30T14:44:15.427Z" }, + { url = "https://files.pythonhosted.org/packages/6a/64/72bc3f75176e7e406b748a3e3830432b8c51297b38368713df04dc04898a/cryptography-50.0.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:ab50ee449bf968271e820086f10a33d101dd060370abc10bcd22279be2656539", size = 4694824, upload-time = "2026-09-30T14:44:17.69Z" }, + { url = "https://files.pythonhosted.org/packages/4e/c6/62c77550edfa5ca3f14bf44a1e6739b9fa09d6e998a11d97ed8213bccc98/cryptography-50.0.2-cp314-cp314t-manylinux_2_28_aarch64.whl", hash = "sha256:a9f7355e6fab51f6c369b86fb7571cffa05edee2c2121e0380a37fb9ac1cd5c1", size = 4716967, upload-time = "2026-09-30T14:44:19.661Z" }, + { url = "https://files.pythonhosted.org/packages/f4/37/cce70f150c432914460157a6ecc161752e053aa5ec0ef3b3f7dc6e31039a/cryptography-50.0.2-cp314-cp314t-manylinux_2_28_ppc64le.whl", hash = "sha256:94e5e9f108ee10471288214d3d233fbfbb492840a8457eb85178d643ddeb32c7", size = 5328676, upload-time = "2026-09-30T14:44:21.744Z" }, + { url = "https://files.pythonhosted.org/packages/aa/9a/6f2f0304d634ceafdeaf23e84537336664ac419b5d07611675c2ad3f6b7a/cryptography-50.0.2-cp314-cp314t-manylinux_2_28_x86_64.whl", hash = "sha256:241449bf940a5d27309bd317e6f9a2af6932113818bb2b8f5c59ddc7ef16da18", size = 4727698, upload-time = "2026-09-30T14:44:24.178Z" }, + { url = "https://files.pythonhosted.org/packages/1d/de/66bcf9244d118663b2e1aaded8990f4640e3d7b7411870a5765f252074d2/cryptography-50.0.2-cp314-cp314t-manylinux_2_31_armv7l.whl", hash = "sha256:d8947001be83df1394050758ce0e745dd74fb134eef0a4b5124208dfc3a68c37", size = 4354821, upload-time = "2026-09-30T14:44:26.263Z" }, + { url = "https://files.pythonhosted.org/packages/bd/e6/db28a28c7b6c676addce89136de3d8db49ea825a8c863472e36e42ead4ad/cryptography-50.0.2-cp314-cp314t-manylinux_2_34_aarch64.whl", hash = "sha256:4a20ce1e5cb4284a86692fdcba7cb8754185c6b2e5c56fcef3751cf451d3cdc2", size = 4716748, upload-time = "2026-09-30T14:44:28.447Z" }, + { url = "https://files.pythonhosted.org/packages/30/96/01546c7f69ea0e2ab790a2e4f0934a4052fb9b388147fbf83c2fd72f1e57/cryptography-50.0.2-cp314-cp314t-manylinux_2_34_ppc64le.whl", hash = "sha256:84f964e537f916e2cc85199e5a88742e964939b575ac8598b3f9d6cc416cdaf1", size = 5285085, upload-time = "2026-09-30T14:44:30.704Z" }, + { url = "https://files.pythonhosted.org/packages/6c/01/03263395f74d50b071e9e66daace3f8bef80493e5d410726f2ba8554736b/cryptography-50.0.2-cp314-cp314t-manylinux_2_34_x86_64.whl", hash = "sha256:828d49b0ff5a0e3975865571c5d91dbbdd0d38d8289b249a163e9425413a5e05", size = 4727268, upload-time = "2026-09-30T14:44:32.92Z" }, + { url = "https://files.pythonhosted.org/packages/eb/94/2bfe8f29ec0cc9c0d99359c4161adf32858e4934b72c6d100d2ac0bbe962/cryptography-50.0.2-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:deb9fde5c60e437ee4821bc9bc39ff31b42135c27e1dc61ef0a629389c1de62e", size = 4849503, upload-time = "2026-09-30T14:44:34.969Z" }, + { url = "https://files.pythonhosted.org/packages/54/44/e80651ecbf0e42b62e2bb5f5768916e07eea72e1297338956a61df361f88/cryptography-50.0.2-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:8c71ba2cd31fc93748c38e1b613200ff1c2665cbfd5341fe3a61cfde35a1430e", size = 5004057, upload-time = "2026-09-30T14:44:37.064Z" }, + { url = "https://files.pythonhosted.org/packages/f8/cc/1d33befb3cd7ea7e77d2d73f43f2066471da1b21f24a6156efcaabf6d2e8/cryptography-50.0.2-cp314-cp314t-win_amd64.whl", hash = "sha256:78198641e5be9521beea5aa782bb551a58068d10e6eb04c9c680c1b69f2e7d45", size = 3795868, upload-time = "2026-09-30T14:44:39.71Z" }, + { url = "https://files.pythonhosted.org/packages/2d/49/93f6a6e7a87c9aa68d44d3e1cdb5fe8f60c90d5d2f46acae9a56892816b8/cryptography-50.0.2-cp315-abi3.abi3t-macosx_11_0_arm64.whl", hash = "sha256:edc3342adf8f697fc5f59c887a304356f147b397809440ed64e2fa6af2f50f37", size = 4133708, upload-time = "2026-09-30T14:44:41.807Z" }, + { url = "https://files.pythonhosted.org/packages/8c/75/32ac2a56243d778805c16ca6a32b8f74fb757df7e28d7ecb560afafb59cf/cryptography-50.0.2-cp315-abi3.abi3t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:d370b8d1dfcdf7130178137f6fbee6140774a1acc6cacefc4b42643ec11d0a3a", size = 4956267, upload-time = "2026-09-30T14:44:43.693Z" }, + { url = "https://files.pythonhosted.org/packages/aa/a4/2c8d734e43d97f0842ee9f1b7b4bfb3d0cf5e19edebf43c2afe6675c2320/cryptography-50.0.2-cp315-abi3.abi3t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:f2f9bd7f90c64fe89253f0a2c05e3c4856072660429ce8831b4235bf29403a67", size = 4966465, upload-time = "2026-09-30T14:44:45.769Z" }, + { url = "https://files.pythonhosted.org/packages/c2/58/ee288c829a6f41f6235ae9dd33d82fd19b45442b65b4c8a3da36963d9f7a/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl", hash = "sha256:e275096ea1e60cc595cda2836fd4a6c725d1125108b868be17f53684d164e2cc", size = 4959356, upload-time = "2026-09-30T14:44:48.211Z" }, + { url = "https://files.pythonhosted.org/packages/92/20/9ded6d51ddd9897f6b6e81fb9ebea7951d7cc5d6c890b0ed8abf77a51a80/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_28_ppc64le.whl", hash = "sha256:b13478603dcd0a2479ff8e87e2c19a7d525734686fe3c49542472293a204212d", size = 5548822, upload-time = "2026-09-30T14:44:50.86Z" }, + { url = "https://files.pythonhosted.org/packages/02/a8/8df951850d6b31d2a00218f19e2b3f999523437ed7a819df7fa427942fca/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl", hash = "sha256:58a0c478eeca76fe5e07993c5a0703def34a6dc6a0cda4f5564639b33112ffe7", size = 5001199, upload-time = "2026-09-30T14:44:53.379Z" }, + { url = "https://files.pythonhosted.org/packages/8b/f9/36b3022218ce75b7cdf068fb95f809f9bd0d820e4955ef43b90c255cc7ac/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_31_armv7l.whl", hash = "sha256:d38cdff612d06fa6a32840d5e1b1f7a27cee4a349aa9085d94a67789d6bfd408", size = 4629333, upload-time = "2026-09-30T14:44:55.635Z" }, + { url = "https://files.pythonhosted.org/packages/8c/72/20f99a219f6af47cdd1cbd978c243b92d71496e168a746138af44ded4f29/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_34_aarch64.whl", hash = "sha256:fdd28f912fccfec1846a94e2e1e8f9b0012f557f0c46fe4f3eb0d7a87afcf90b", size = 4958822, upload-time = "2026-09-30T14:44:59.639Z" }, + { url = "https://files.pythonhosted.org/packages/f2/20/196f112617fb08eb4d608a2a6c422373d46f9cc2857f38fc0667033c0899/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_34_ppc64le.whl", hash = "sha256:cbc8738fd8526d80f35cb3a40d41f41a2e7030bb3b18b09a6778ef63d291c2fd", size = 5506351, upload-time = "2026-09-30T14:45:02.267Z" }, + { url = "https://files.pythonhosted.org/packages/24/95/83378121ef3eaaaf71d4b781577ff794acb39b9e1b87a3f156898c8497ed/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_34_x86_64.whl", hash = "sha256:e105ab60406787da31fccc883fc0f733af1efd78f0136a4599692c4083a73d0c", size = 5000859, upload-time = "2026-09-30T14:45:05.009Z" }, + { url = "https://files.pythonhosted.org/packages/22/f7/70fd7ae4d1dbfa7ba29b02e1b9068771519a86027756510b700ce81086a8/cryptography-50.0.2-cp315-abi3.abi3t-musllinux_1_2_aarch64.whl", hash = "sha256:6f8700550aa1474a91e5dc07049c46f98b423b5b1ddd0483e0b51362eeeaf5be", size = 5092151, upload-time = "2026-09-30T15:29:15.932Z" }, + { url = "https://files.pythonhosted.org/packages/d4/be/688367b74de86984bd58d8efacfc7c9e68b89a6a22ced0fb4f38db50254a/cryptography-50.0.2-cp315-abi3.abi3t-musllinux_1_2_x86_64.whl", hash = "sha256:c71be1cbfa5cd9a41ee452acf1eccd82b2c05950358b106ec8ceb83411d1a020", size = 5286120, upload-time = "2026-09-30T15:29:18.309Z" }, + { url = "https://files.pythonhosted.org/packages/39/d1/55f8a3f2ef5d1529e16835ef10cf0fe3d559ce237b46dddc440c0bba3649/cryptography-50.0.2-cp315-abi3.abi3t-win_amd64.whl", hash = "sha256:c423ab384a46c4dff7217b2ea5ba2e11cffdeab6441acd04cf65a369caf0366c", size = 4111557, upload-time = "2026-09-30T15:29:20.155Z" }, + { url = "https://files.pythonhosted.org/packages/23/ad/ac987755d00e1e64273760228d2635ae38dae2be83e3c6e0d3289d91dec3/cryptography-50.0.2-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:0ec5f09541743261e66e291b4a0cbf0fb2997aeaab6d9e9c740b9dba1b58d1c2", size = 3943588, upload-time = "2026-09-30T15:29:22.265Z" }, + { url = "https://files.pythonhosted.org/packages/d5/8d/6d585339bedf85d45044c85d8412dac53f2bb6f918e8b7777efba1787844/cryptography-50.0.2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:c5e67125c7dca78d199ec4e116aa93dbb83494808ecbb8211a2cb09b1bf41dbd", size = 4756166, upload-time = "2026-09-30T15:29:24.58Z" }, + { url = "https://files.pythonhosted.org/packages/bf/f1/1c1f6874e8550cfddd4b688ceb38cefb6ed15ceed224d56f133f3d88c214/cryptography-50.0.2-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:ee247f5c245c9a2fe7c8e2214e295918838e44e00a45a6718451e4004219e767", size = 4749145, upload-time = "2026-09-30T15:29:26.807Z" }, + { url = "https://files.pythonhosted.org/packages/c1/63/61b15dc1a8de03fe0adbe3fd7608b3ad5c73bf50993bbcb1faaa930afe33/cryptography-50.0.2-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:dfe9763530994147d9af1def057a5b9658b00e8f8fe8743d144d1e0911c2e454", size = 4763638, upload-time = "2026-09-30T15:29:28.588Z" }, + { url = "https://files.pythonhosted.org/packages/fc/35/b345bdfa40c9126df1a9d33236aa98418367931b8725f84fc3ae2b98dc59/cryptography-50.0.2-cp39-abi3-manylinux_2_28_ppc64le.whl", hash = "sha256:58ddb5a8e3179d12f19e4ea34d2d32e9d63a4baa142c875c1eb59f41b7243acd", size = 5382217, upload-time = "2026-09-30T15:29:30.589Z" }, + { url = "https://files.pythonhosted.org/packages/4f/87/ef344a9e616871f2519c22d6afcda79ddd5d35e9592d95eb6e677608d055/cryptography-50.0.2-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f21e8a22c8605750c7af886bab299a363721264061b4ac0a30efb73cfd58efc5", size = 4781387, upload-time = "2026-09-30T15:29:32.605Z" }, + { url = "https://files.pythonhosted.org/packages/90/5b/f2fdb13cd0b96f6f932c8627bb292a45f11c64d21620a8e120aee9a3b848/cryptography-50.0.2-cp39-abi3-manylinux_2_31_armv7l.whl", hash = "sha256:9c8402a82ea0dc4ceeab793db05f0fafa8ca139ca34fcde5df0f596103c74107", size = 4403790, upload-time = "2026-09-30T15:29:34.374Z" }, + { url = "https://files.pythonhosted.org/packages/bc/ce/7e4f662b1e3c393513569e402cfc85ac7da0bd3d5435e122a3140219eb2d/cryptography-50.0.2-cp39-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:0ddc924c04591c2811ca024d62ecad4f7f6f08af8939c211438f48a16bd23602", size = 4764319, upload-time = "2026-09-30T15:29:36.149Z" }, + { url = "https://files.pythonhosted.org/packages/3c/3f/86ff33ce34cc0de6847fb96e035a1a760d81652e38643f617c02ad32ef7a/cryptography-50.0.2-cp39-abi3-manylinux_2_34_ppc64le.whl", hash = "sha256:a6557e5f38e065ca9fbdaf7cfc7435ecb1d113aa81a022d1b51921ee7432e227", size = 5338560, upload-time = "2026-09-30T15:29:39.053Z" }, + { url = "https://files.pythonhosted.org/packages/40/cf/6b5c8e2fd9202d98988ab7cb5cc5c991704c4ad55f492ff408e4969f83f1/cryptography-50.0.2-cp39-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:1981f1db4630889b9ef7803fadef12b056f428cb6b85c27ba57b774793b6093c", size = 4780973, upload-time = "2026-09-30T15:29:41.251Z" }, + { url = "https://files.pythonhosted.org/packages/10/bf/8d6ebc7dded797bd0f0160d52188021211f011a2b164ef0ae1dac4587465/cryptography-50.0.2-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:7a8701d6b584d76e909e3d305b7d126b41439876a5aaf76cddc67fc230eafa2e", size = 4897738, upload-time = "2026-09-30T15:29:43.106Z" }, + { url = "https://files.pythonhosted.org/packages/d4/aa/f3f6e0de7e6253b8baa8b2d8fb9d50924fa75cee3d4624bd4bc1208ee923/cryptography-50.0.2-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:ce47f66801c20ec6c6632453bb5960fe38939e9306970b48b3a5a26de7745d94", size = 5058280, upload-time = "2026-09-30T15:29:44.827Z" }, + { url = "https://files.pythonhosted.org/packages/f6/b6/a1faf3a27ae9405fb34b1713cc73b2d8a26b04d5c561578fa2e6ef3e5bb9/cryptography-50.0.2-cp39-abi3-win_amd64.whl", hash = "sha256:4e81d95e5bafc2d6e34e4bed780e53e4d5b9a2f928573428aa4d35fbec1eb0de", size = 3854095, upload-time = "2026-09-30T15:29:46.782Z" }, + { url = "https://files.pythonhosted.org/packages/1d/7a/f08d34ce09d60f89ebd391e2ebc6ba2b995e6dd7552f41820f8085f94e53/cryptography-50.0.2-pp311-pypy311_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:92e665960f25fcdc73725b9cec7a3824f279ba97a98653afe9ffac2e43668f67", size = 4716035, upload-time = "2026-09-30T15:29:48.681Z" }, + { url = "https://files.pythonhosted.org/packages/45/67/e18fb65592451a2acb76e9f2fbe14e0f47a8318b4c5430f1633851d03daa/cryptography-50.0.2-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:eef4c2f3423810b3070ab391f85436d2f8bbfcb286ac15cbc73190b3563b1f1a", size = 4726917, upload-time = "2026-09-30T15:29:50.608Z" }, + { url = "https://files.pythonhosted.org/packages/83/28/38fdce17e60f6b825e69fc3b7f75e70a6612759980704697e1de4cbfaf6e/cryptography-50.0.2-pp311-pypy311_pp73-manylinux_2_34_aarch64.whl", hash = "sha256:7c6d0330c472d96f6a6afe24d80dfdf15176c33096f0a4397ae4c60f3dd3be48", size = 4715341, upload-time = "2026-09-30T15:29:52.522Z" }, + { url = "https://files.pythonhosted.org/packages/b6/b1/d9121a717e0f893c64bd6ca7702614778d7df2a5c309128a002421788516/cryptography-50.0.2-pp311-pypy311_pp73-manylinux_2_34_x86_64.whl", hash = "sha256:1ba34f04897fcdaa73f74145c25f3ec146fbd56593853e88adc2e811303c5f42", size = 4726322, upload-time = "2026-09-30T15:29:54.263Z" }, + { url = "https://files.pythonhosted.org/packages/36/8b/e6d153808bf353e152abd2fd4d8f09670d956ac78379ac46e60d7efbf04c/cryptography-50.0.2-pp311-pypy311_pp80-macosx_11_0_arm64.whl", hash = "sha256:3dc4fd8058cea1644971207d530e1a03a184a805ffc8ebdddf0599d78a331b81", size = 3873097, upload-time = "2026-09-30T15:29:56.097Z" }, + { url = "https://files.pythonhosted.org/packages/ca/1d/1271f287ff7170ddafc2aad36260c4eec20ccd2fea70f38455e9d56d427b/cryptography-50.0.2-pp311-pypy311_pp80-win_amd64.whl", hash = "sha256:7b75de3c8b3be1cdb1052747c929440c3eea46c1bc2cb8a6e3a48388e9b7b452", size = 3805376, upload-time = "2026-09-30T15:29:58.729Z" }, +] + [[package]] name = "cyclonedx-python-lib" version = "9.1.0" @@ -636,6 +810,123 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/e0/1b/5e74289a1878e666bb4b65fe5805a04cafcac2aa5f519ef1ead67ef91c56/filelock-4.2.4-py3-none-any.whl", hash = "sha256:301241438c57936ef93f4243a94f2559022268bfcf9b375a9a72eb0f8db8358e", size = 162475, upload-time = "2026-10-19T01:57:49.419Z" }, ] +[[package]] +name = "google-api-core" +version = "2.44.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "google-auth" }, + { name = "googleapis-common-protos" }, + { name = "opentelemetry-api" }, + { name = "proto-plus" }, + { name = "protobuf" }, + { name = "requests" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/72/ef/63d89cb580f3a42c51db53b3d151352aa61b9c87ea8cfdd8d24ee6caa09d/google_api_core-2.44.0.tar.gz", hash = "sha256:5ab9a396965c1227d7dea4581e562b7018aa2bca96d2de0be5eb70dc9c8ab3a1", size = 288859, upload-time = "2026-11-05T18:39:43.265Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c9/73/4068d4b123d206f42e44d476b6ed4de773d81efc4e88101ff82e318b9a7a/google_api_core-2.44.0-py3-none-any.whl", hash = "sha256:8cb9ad8af28de9bc75121686d69b697ce0937e21fad2ad80c9a7e89f22b26e1f", size = 225627, upload-time = "2026-11-05T18:39:01.342Z" }, +] + +[[package]] +name = "google-auth" +version = "2.63.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cryptography" }, + { name = "pyasn1-modules" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/35/0e/e8125c650f126f8703feabca892277f258af7c761fd93f7d51a404e56d75/google_auth-2.63.1.tar.gz", hash = "sha256:f69f387dba9abe536fec87483a749485f2ef0c81bfa79f609d9873e57054a1a5", size = 409098, upload-time = "2026-11-21T20:36:15.511Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/10/21/868ddea6de119b3e47ee0ae8de70bffabb6c0fe8a6f395ea62bdfb2ec062/google_auth-2.63.1-py3-none-any.whl", hash = "sha256:3c977ca57114a302c2589f3a24be7ca1b6862d30da7619f4230a78809f58a0e9", size = 271264, upload-time = "2026-11-21T20:36:13.886Z" }, +] + +[[package]] +name = "google-cloud-core" +version = "2.8.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "google-api-core" }, + { name = "google-auth" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/55/71/d6081acadf55d4233271c39860f0d140ef61fbdb4bceb2075e9c2905d947/google_cloud_core-2.8.0.tar.gz", hash = "sha256:365f8e4518ae81c8101b8dea5fc1c32a960badedb8b511f19db2843cbbd285d2", size = 36605, upload-time = "2026-09-29T19:25:59.275Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/12/ed/1b09640a565e5d34d4e517463f65a67a11f9dcdeb6b6e8220f2d06aaf489/google_cloud_core-2.8.0-py3-none-any.whl", hash = "sha256:e235b0952f7ffe7b9c71a4cf96b506d9cfb557e22557c412f0df9b7068b5d007", size = 31048, upload-time = "2026-09-29T19:25:35.361Z" }, +] + +[[package]] +name = "google-cloud-storage" +version = "3.17.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "google-api-core" }, + { name = "google-auth" }, + { name = "google-cloud-core" }, + { name = "google-crc32c" }, + { name = "google-resumable-media" }, + { name = "requests" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/32/88/b90f3c94896ee5a8ae3eda9af98a6847c395eb15e9917fb43ffeb48a584e/google_cloud_storage-3.17.2.tar.gz", hash = "sha256:ef92d6520abd37c757a962f8702c72786ff833f8d5aa6ebeb528a0688189f64c", size = 17359031, upload-time = "2026-11-23T18:19:56.097Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/94/00/0fe4cb53eb14046ad9ea5462f683491a43128646b6d3656cb3f58e337a77/google_cloud_storage-3.17.2-py3-none-any.whl", hash = "sha256:5d5a1d0c9d6a4f96180a35a958bbfe81bf57ad2fab87e4ee9f78117b8d5f5f68", size = 346718, upload-time = "2026-11-23T18:19:54.215Z" }, +] + +[[package]] +name = "google-crc32c" +version = "1.9.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/fa/25/9cb0c1c31c45b893eb8f11ae70b3f4309432d59b5acaebca5dbe791729a4/google_crc32c-1.9.0.tar.gz", hash = "sha256:7b8c84c3d159ab6817fe3f74e6e6cef099c3f95dcec3abc0d8afb1404642efbe", size = 14857, upload-time = "2026-09-24T21:39:32.067Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0e/55/a2f07f15e624f0de79359b1a6c1deb59ec5061bd3b38744b3b2849400662/google_crc32c-1.9.0-cp311-cp311-macosx_12_0_arm64.whl", hash = "sha256:457d0d9a4718fd52b1494eac5c200ad25beeadbdc91843d550a003910838589f", size = 31958, upload-time = "2026-09-24T21:19:00.994Z" }, + { url = "https://files.pythonhosted.org/packages/f8/b3/923743597b774bbcf12a7c3e00e48d745e15fd616ad7489a40a63fff8f2f/google_crc32c-1.9.0-cp311-cp311-macosx_12_0_x86_64.whl", hash = "sha256:ccfe40021fd6afe23361175cf7551e3cef5fd34dc1ebe319f14993a83579e0eb", size = 31805, upload-time = "2026-09-24T21:22:25.019Z" }, + { url = "https://files.pythonhosted.org/packages/df/a6/4d0352fe889663e0d81cea7fc664ec9158727384de4a44ab10e9967a7682/google_crc32c-1.9.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:fbef61a3794e011c65fb4396a196cf123a7f474fe5a443db8e5dd7d751b9e6d4", size = 38119, upload-time = "2026-09-24T21:38:06.634Z" }, + { url = "https://files.pythonhosted.org/packages/aa/e3/26685384e4b66ff0928d9566ef6110a7df76029175a1842329d7e3515f10/google_crc32c-1.9.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:86764b99e7a607830d93cb5b75e0ec3ff6cb06d3c274624418473cee701900d4", size = 36677, upload-time = "2026-09-24T21:38:08.082Z" }, + { url = "https://files.pythonhosted.org/packages/cb/ce/4e90102e84880e97d3cf935f2672ecd29191bdeacf57f01740f92debda00/google_crc32c-1.9.0-cp311-cp311-win_amd64.whl", hash = "sha256:43a2dc26f9be213fbe0b4fc4a1088c5d45cbfcb3247420ccc820f0fc3edeea86", size = 35096, upload-time = "2026-09-24T21:39:28.201Z" }, + { url = "https://files.pythonhosted.org/packages/e4/5d/0730e1b3a14d054d1466f2fec88dadf978509c749a3d96d8b069cc56d38a/google_crc32c-1.9.0-cp312-cp312-macosx_12_0_arm64.whl", hash = "sha256:53fdafef58e230d0c946ab5f8446d123d9f548230a73b29c8b41c9546f268bc1", size = 31961, upload-time = "2026-09-24T21:19:01.724Z" }, + { url = "https://files.pythonhosted.org/packages/dd/32/d085abaf2fd907121975b92245bb3480fb8be40c37d03f9d6c41857f84c3/google_crc32c-1.9.0-cp312-cp312-macosx_12_0_x86_64.whl", hash = "sha256:8b91f41645b15a720357183fa5716682ada441873e3c462c15f9714be36f146b", size = 31804, upload-time = "2026-09-24T21:22:25.81Z" }, + { url = "https://files.pythonhosted.org/packages/94/78/dd1935432337e5da7af391a6fc9f161c1c8e9b9002a402b9190135fe1b59/google_crc32c-1.9.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:16865b477d7941712cb0e0aad8ad4815e984fb5fc16d3fdaef7d986e26e53c95", size = 37775, upload-time = "2026-09-24T21:38:09.249Z" }, + { url = "https://files.pythonhosted.org/packages/9e/43/9db03635bb10188d93dcbab9baa2a8670a0da4e868b4370cdbd98d65fed8/google_crc32c-1.9.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:3abb18297d9ef0ab120531838be0e6d68c9fa876570e11c229c48f2edac23ce7", size = 36347, upload-time = "2026-09-24T21:38:10.141Z" }, + { url = "https://files.pythonhosted.org/packages/cf/eb/94dee516c846bd9382c3f566d8f8e5fb9e90599e45afeb697f9fc2533528/google_crc32c-1.9.0-cp312-cp312-win_amd64.whl", hash = "sha256:fb63a8d7fa2e95dcff1ca16af2f4d88b526fa5ff72d1696285884ac2d49b6963", size = 35097, upload-time = "2026-09-24T21:39:28.934Z" }, + { url = "https://files.pythonhosted.org/packages/3f/34/cb484e8b6174f130f8c6dc79c733a9dd8869b410ad6511fb6104c46b973a/google_crc32c-1.9.0-cp313-cp313-macosx_12_0_arm64.whl", hash = "sha256:f1dc17d987ddcc5eba12a7ce48f0eb93141dea236b170c1101151396edf2f0cf", size = 31960, upload-time = "2026-09-24T21:19:02.454Z" }, + { url = "https://files.pythonhosted.org/packages/af/25/3e8e567bd48448e225ea27318ccf2b94e05124e7b8b97b13eaec9e127199/google_crc32c-1.9.0-cp313-cp313-macosx_12_0_x86_64.whl", hash = "sha256:f894a2877650b56201d26a012a257b76d54a68834dc3913a93830ca8a047b075", size = 31803, upload-time = "2026-09-24T21:22:27.008Z" }, + { url = "https://files.pythonhosted.org/packages/f0/18/bee0dd59ae622482dc6463636c79e4bde7c954d061c859c9256362c9931a/google_crc32c-1.9.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:4488f1553a9ab7e86cdedc833374a7e904031803b995dc0bd0be48c271fa6556", size = 37776, upload-time = "2026-09-24T21:38:11.056Z" }, + { url = "https://files.pythonhosted.org/packages/fd/b6/e76e80fed5f2558273c7839e622f98095c9b36c719c7147e38e3c055cb70/google_crc32c-1.9.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:0568b17ed90ac596f29400d99e243fd0cc6276766183def888d1bf8d1dc13827", size = 36350, upload-time = "2026-09-24T21:38:12.138Z" }, + { url = "https://files.pythonhosted.org/packages/87/34/165542bfa99dfef91a76471cc48cce74b8ff4e295722896087ab2b8e8611/google_crc32c-1.9.0-cp313-cp313-win_amd64.whl", hash = "sha256:8583ec21d56b565d68ab2963cc7e21b3b271247c29b04286068255ef65f221bd", size = 35090, upload-time = "2026-09-24T21:39:29.764Z" }, + { url = "https://files.pythonhosted.org/packages/8f/eb/43ea41f4061a1cad87b2b6559c98e960e45bf551fe66f83d833b98aaf0c9/google_crc32c-1.9.0-cp314-cp314-macosx_12_0_arm64.whl", hash = "sha256:6a3b2c8a343c570ed8100a7627c20badfd92c6caa2067093a86be45af27f5b1b", size = 31963, upload-time = "2026-09-24T21:19:03.208Z" }, + { url = "https://files.pythonhosted.org/packages/45/d2/a968c0c29ccd2b0c980ff4f9e3f7035cee28c23a1c57541825cc8221858c/google_crc32c-1.9.0-cp314-cp314-macosx_12_0_x86_64.whl", hash = "sha256:13179f7e3282617923e957b8e54b8f9c3968030f48640a9f47fd7c5c38c4a215", size = 31805, upload-time = "2026-09-24T21:22:27.917Z" }, + { url = "https://files.pythonhosted.org/packages/03/73/388e493d6c3e252e37165d22efe5a1361f872a24425391b999822861b23a/google_crc32c-1.9.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:265233aff33d835f5b909584fe36ab29647b598c271b661a300001099109e53e", size = 37925, upload-time = "2026-09-24T21:38:13.32Z" }, + { url = "https://files.pythonhosted.org/packages/98/36/190d32caa363ef25d685f422ed1bbf93ff1140fb22fd4d90f24cec209977/google_crc32c-1.9.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:dee799544cae42a42b17a88e38b59cf2c271051dc001da2117a8ff240ffa0548", size = 36495, upload-time = "2026-09-24T21:38:14.211Z" }, + { url = "https://files.pythonhosted.org/packages/d3/fd/81cefea6adae7bd92abb23d4567d199f6485a20ec0a305ca5fa04c52b9c5/google_crc32c-1.9.0-cp314-cp314-win_amd64.whl", hash = "sha256:af73200fa9791ccd380f3598235dba8d82b8af0905df045b3dc60b59836e8ddd", size = 35535, upload-time = "2026-09-24T21:39:30.52Z" }, + { url = "https://files.pythonhosted.org/packages/c5/18/19d4f17f3f33f8fdffcb3e1e69219d6f7ec2c359c160867b04dac1d0a64d/google_crc32c-1.9.0-cp315-cp315-macosx_12_0_arm64.whl", hash = "sha256:e6e8be8a94436079cb5340f6d495d9d7ba30124d8b952703994c739c7c06e236", size = 31977, upload-time = "2026-09-24T21:19:03.976Z" }, + { url = "https://files.pythonhosted.org/packages/81/b4/8010372c4b46f2ee2352dfdb630c397570cd85522a315df024ad2f9459aa/google_crc32c-1.9.0-cp315-cp315-macosx_12_0_x86_64.whl", hash = "sha256:f2b64641bca27497b986b9d87883014035aa904cb4fa333407c6752b3afee9ba", size = 31809, upload-time = "2026-09-24T21:22:29.1Z" }, + { url = "https://files.pythonhosted.org/packages/c5/f8/7e33845d6b90ce1cf37cfabf25cb859277c7d3533ef1b6b1e1ca58581549/google_crc32c-1.9.0-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:f97c3806dcea41c29c04965347b0e12481561b75e0045dc7a4f69d75dec5d9b1", size = 38359, upload-time = "2026-09-24T21:38:14.983Z" }, + { url = "https://files.pythonhosted.org/packages/36/ff/556b2423f449a7515af6b8222a4d7833cbe09ff3e8d2f0b80471f5f6d02e/google_crc32c-1.9.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:0abe7e202c25909869c35672ab0f2fe748a7acf276eb78577332a7c38999740f", size = 36858, upload-time = "2026-09-24T21:38:15.799Z" }, + { url = "https://files.pythonhosted.org/packages/40/71/4733f1b7c921d04a2bb9b9916cf66498bf7ad0860a06289413830da83192/google_crc32c-1.9.0-cp315-cp315-win_amd64.whl", hash = "sha256:5695c8b9327e040b2aba12c6659b0acb5995314ef0af0192da66e662e011103b", size = 35534, upload-time = "2026-09-24T21:39:31.337Z" }, +] + +[[package]] +name = "google-resumable-media" +version = "2.11.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "google-crc32c" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/cf/64/df6a482d5aa39d7f7be186d892377d605cae6c88525fd851d456e8bbe9c9/google_resumable_media-2.11.0.tar.gz", hash = "sha256:febd83686752799661b4de575f0b993c5c25c349a5362556fc4d7be164056a37", size = 2164914, upload-time = "2026-09-29T19:26:13.546Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5e/2e/4f0a152f2e576e496f31ba1c3c62ed174a8878d06008916a7edc58b1bb28/google_resumable_media-2.11.0-py3-none-any.whl", hash = "sha256:f43d15e6a7f818f762eaead0f369c551f8275a4179c9d6225d0d259f49b87b5d", size = 81515, upload-time = "2026-09-29T19:25:47.31Z" }, +] + +[[package]] +name = "googleapis-common-protos" +version = "1.76.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "protobuf" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/62/b6/bc095b23a3e0d978e75c8c18cabe4c11f791837410670e4486f0d539bfba/googleapis_common_protos-1.76.0.tar.gz", hash = "sha256:71db0e44a1d4c2dd024ebad44ca67129cc1e2892e4861df466764749d5ef8642", size = 156250, upload-time = "2026-10-22T23:43:36.263Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/05/6d/78dc67a9e779e594b49bf62604034d3a6aa428a55afc729cafda4b7333e1/googleapis_common_protos-1.76.0-py3-none-any.whl", hash = "sha256:59e13344a9f3651aa201a03e2bee815a3bf43a4baf1f9ff8a9b62a840ce25fac", size = 307707, upload-time = "2026-10-22T23:43:10.445Z" }, +] + [[package]] name = "h11" version = "0.16.0" @@ -1021,7 +1312,8 @@ resolution-markers = [ "python_full_version >= '3.15' and sys_platform == 'win32'", "python_full_version >= '3.15' and sys_platform == 'emscripten'", "python_full_version >= '3.15' and sys_platform != 'emscripten' and sys_platform != 'win32'", - "python_full_version >= '3.12' and python_full_version < '3.15'", + "python_full_version == '3.14.*'", + "python_full_version >= '3.12' and python_full_version < '3.14'", ] sdist = { url = "https://files.pythonhosted.org/packages/95/b0/c7453d0b6e2073c3264468b106ee1563750cecc910965e67357e3698c83e/numpy-2.5.4.tar.gz", hash = "sha256:9a94cf751c9ad8ebaa835bcd3d40dacf8534ad086b88c38029b65123c7999d2a", size = 20866315, upload-time = "2026-10-10T20:05:31.422Z" } wheels = [ @@ -1092,6 +1384,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/48/7f/c2d1b436b6e7cfebac140c2579a298344b85f2991a2ce5c3615cefb29400/numpy-2.5.4-cp315-cp315t-win_arm64.whl", hash = "sha256:7a14a461d9340f1b46b8648578aed9cdb8b3b018a8fac6c1dde2c9192a01a87f", size = 10883718, upload-time = "2026-10-10T20:05:28.547Z" }, ] +[[package]] +name = "opentelemetry-api" +version = "1.45.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/19/14/cf3a6b6448849656e1e5f4e2101f3988dc6789724050096aba1bc5ccf592/opentelemetry_api-1.45.2.tar.gz", hash = "sha256:d7b0008e21e5fd61cbe7a7f34ca3b6905a78ab677d9bc395e299359c75cda6b4", size = 73277, upload-time = "2026-10-29T17:29:37.888Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a9/2d/610db864d7513158cebb8f36cc88e67e73bd6c7aa1905ef18d89e1281c81/opentelemetry_api-1.45.2-py3-none-any.whl", hash = "sha256:2cbd737377e710ee740d261c94e93fa0f08e6d037c18f17513cc0a2d94479a34", size = 60335, upload-time = "2026-10-29T17:29:06.955Z" }, +] + [[package]] name = "orjson" version = "3.13.0" @@ -1173,7 +1477,8 @@ name = "pandas" version = "2.3.3" source = { registry = "https://pypi.org/simple" } resolution-markers = [ - "python_full_version >= '3.12' and python_full_version < '3.15'", + "python_full_version == '3.14.*'", + "python_full_version >= '3.12' and python_full_version < '3.14'", "python_full_version < '3.12'", ] dependencies = [ @@ -1420,6 +1725,33 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b8/db/14bafcb4af2139e046d03fd00dea7873e48eafe18b7d2797e73d6681f210/prometheus_client-0.23.1-py3-none-any.whl", hash = "sha256:dd1913e6e76b59cfe44e7a4b83e01afc9873c1bdfd2ed8739f1e76aeca115f99", size = 61145, upload-time = "2025-09-18T20:47:23.875Z" }, ] +[[package]] +name = "proto-plus" +version = "1.29.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "protobuf" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/46/70/783e33ffbb4466cc154a94f79b869b92a451e2bd45605054e68ff68b7af6/proto_plus-1.29.0.tar.gz", hash = "sha256:cfb4e62ad7e13dd18f346cabbda00cab39930d36a05791fd81ddb074d6ee884f", size = 58592, upload-time = "2026-09-29T19:26:15.963Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b1/05/a3ef5b1161498e7b5a2a60288a9cf41b9149e94555423a43ec536737ac1a/proto_plus-1.29.0-py3-none-any.whl", hash = "sha256:8acd070469a7aaf43f440b022ef9757c8cac1a9f866e933f59ae98669ddc6c8b", size = 50786, upload-time = "2026-09-29T19:25:50.409Z" }, +] + +[[package]] +name = "protobuf" +version = "7.36.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d9/89/5b8517baa72f84a67b8a307ba953c91057af618bf40bf676f3c03551f8f0/protobuf-7.36.2.tar.gz", hash = "sha256:497d0463ff3316681da6c0b9e8d06cb465d61abce00b613ab42226175644d1bb", size = 512737, upload-time = "2026-09-17T20:07:59.326Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/32/72/98342feb672507c8f3a69e34b4fa8961f608edba5c1a48a6f47156d92cb5/protobuf-7.36.2-cp310-abi3-macosx_10_9_universal2.whl", hash = "sha256:cbc70b17ee27e28894c7fee8bb04be1abead49e936bc70eb60052531eee2079e", size = 456039, upload-time = "2026-09-17T20:07:51.542Z" }, + { url = "https://files.pythonhosted.org/packages/b6/ea/91fdf7c2b8bbd49cde056f00a9df6773532987e1c00fe2830b895af95c7e/protobuf-7.36.2-cp310-abi3-manylinux2014_aarch64.whl", hash = "sha256:e11e1f0180583a2af89db6a2ecd9e8dc40aa6d2988ca175bfd0e6d12ea72d74e", size = 344219, upload-time = "2026-09-17T20:07:52.914Z" }, + { url = "https://files.pythonhosted.org/packages/17/ab/5fd5f8ece73fad885c5a09aa849b32d70472f954ba3a92d3bb5974ea953b/protobuf-7.36.2-cp310-abi3-manylinux2014_s390x.whl", hash = "sha256:f4fee11ec330d238b34a05c9b675f693c20415d1c5bd7d5320cc2f8a798eb9cf", size = 357223, upload-time = "2026-09-17T20:07:53.985Z" }, + { url = "https://files.pythonhosted.org/packages/db/f3/3996583dd2906297a637af12114deddf7658af6e683fedb83be061983fb5/protobuf-7.36.2-cp310-abi3-manylinux2014_x86_64.whl", hash = "sha256:89f23aa53c24553a2416fd4fd1ec06f74fa42b14b546d8883128813f775bbfd2", size = 343223, upload-time = "2026-09-17T20:07:54.931Z" }, + { url = "https://files.pythonhosted.org/packages/fc/1b/dcc64f358fcb51811b58ae40b3d28f820725f116d86487cc20bd4b130701/protobuf-7.36.2-cp310-abi3-win32.whl", hash = "sha256:912c1221170e16c08d1f086762f563dd61ff83c18b5fa6652952dfaded66f728", size = 442998, upload-time = "2026-09-17T20:07:55.826Z" }, + { url = "https://files.pythonhosted.org/packages/8a/55/b77bda4e5e5f5971fb51b07663694690e9afdb9402136c16a522bd621cad/protobuf-7.36.2-cp310-abi3-win_amd64.whl", hash = "sha256:a300819d441e078a5608c0d3c709796bb548136058fda017ae51d425b44fd353", size = 456514, upload-time = "2026-09-17T20:07:57.188Z" }, + { url = "https://files.pythonhosted.org/packages/e4/04/d52c7016b04b6c5108f26691f9d33ec82a9b65d041f1a9c771137693d618/protobuf-7.36.2-py3-none-any.whl", hash = "sha256:bdb3a345d48db958e6ce1f18e508beb0cc981d64f24088427549c866cd039f1e", size = 179806, upload-time = "2026-09-17T20:07:58.211Z" }, +] + [[package]] name = "psutil" version = "7.1.3" @@ -1524,6 +1856,36 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/96/be/7b81a44d6a8e70581dcc1d6f01541f9000a973b1e5d75394aec91e7b179a/pyarrow-26.0.0-cp315-cp315t-win_amd64.whl", hash = "sha256:68cd662e9e2b00876a131950cf32336ace2d0865e1f9418763e3d3be8481dfa4", size = 29389953, upload-time = "2026-10-09T08:26:18.277Z" }, ] +[[package]] +name = "pyasn1" +version = "0.6.5" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/88/7e/3c0da41061a2021cac7cd524fd57092adbe5b515e8bf9005702e366802e2/pyasn1-0.6.5.tar.gz", hash = "sha256:6b11616a6bcf3a40e635f082bb232fa57b5e0dd7f517bd7ddd69ec3794508a47", size = 155152, upload-time = "2026-10-27T06:32:49.125Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/19/1f/3eefd5c84c35cae44549ce1c7f7e58f7945b34f5a6bce07a135438522073/pyasn1-0.6.5-py3-none-any.whl", hash = "sha256:4017b0fce125096b8573b39c989fdb1a4b19cf761e683398184550fea0e66587", size = 84807, upload-time = "2026-10-27T06:32:48.045Z" }, +] + +[[package]] +name = "pyasn1-modules" +version = "0.4.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pyasn1" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/e9/e6/78ebbb10a8c8e4b61a59249394a4a594c1a7af95593dc933a349c8d00964/pyasn1_modules-0.4.2.tar.gz", hash = "sha256:677091de870a80aae844b1ca6134f54652fa2c8c5a52aa396440ac3106e941e6", size = 307892, upload-time = "2025-03-28T02:41:22.17Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/47/8d/d529b5d697919ba8c11ad626e835d4039be708a35b0d22de83a269a6682c/pyasn1_modules-0.4.2-py3-none-any.whl", hash = "sha256:29253a9207ce32b64c3ac6600edc75368f98473906e8fd1043bd6b5b1de2c14a", size = 181259, upload-time = "2025-03-28T02:41:19.028Z" }, +] + +[[package]] +name = "pycparser" +version = "3.12" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/cb/27/eeb9f307bf07060f3d9f9aa0fb8c15b01bdfded0a941e4b2719c7f94cacd/pycparser-3.12.tar.gz", hash = "sha256:f03387877eab82ce01bbdfd0ba7252ee55a90b1c708d5129e2ce915475cf1db6", size = 158785, upload-time = "2026-10-22T13:40:03.56Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b6/ae/315bbeee126a769cbde43cf4908acb4b40408d8bf8bbf334dd7368d8dadf/pycparser-3.12-py3-none-any.whl", hash = "sha256:a076f3f489b39b43ed13563a1dafe42447445bec2e294154ec5c57fcdda4c85e", size = 62600, upload-time = "2026-10-22T13:40:02.021Z" }, +] + [[package]] name = "pydantic" version = "2.14.1" From 86cf1c89932c15fbebafb9c74089825b321fc3b6 Mon Sep 17 00:00:00 2001 From: Ray Walker Date: Fri, 27 Nov 2026 20:00:43 +1100 Subject: [PATCH 2/3] fix(backends): classify stalled reads and unreachable token endpoints, and never delete unconditionally A read that times out part-way through a response body arrives as a requests ConnectionError around urllib3's timeout: it is a TIMEOUT. A token refresh that could not reach the metadata server or token endpoint is TRANSIENT, not a refused credential. A checksum mismatch is TRANSIENT. The cleanup of a dead entry now deletes only when the read named a generation. An empty object, whose ranged read is refused with a 416 that names none, is read again whole first. --- docs/backends/gcs.md | 10 +-- src/cachekit/backends/gcs/backend.py | 20 ++++-- src/cachekit/backends/gcs/error_handler.py | 25 +++++-- tests/integration/test_gcs_integration.py | 7 +- tests/unit/backends/test_gcs_backend.py | 80 ++++++++++++++++++---- 5 files changed, 107 insertions(+), 35 deletions(-) diff --git a/docs/backends/gcs.md b/docs/backends/gcs.md index c5bc390fd..0df9381a6 100644 --- a/docs/backends/gcs.md +++ b/docs/backends/gcs.md @@ -118,17 +118,17 @@ gcloud storage buckets update gs://my-cache-bucket --lifecycle-file=lifecycle.js | Operation | Requests | |-----------|----------| | `get` | One download. A hit, a miss and an absent object each cost one request; an expired or corrupt entry costs a second, to delete it. | -| `set` | One upload that replaces the object. An entry above 8 MiB is a resumable upload of two requests. | -| `exists` | One ranged read of the 14-byte header. | +| `set` | One upload that replaces the object: a single request up to 8 MiB, a resumable upload of several requests above it. The object is replaced when the upload completes. | +| `exists` | One ranged read of the 14-byte header. An empty object costs a second read, and a corrupt or expired one a delete. | | `delete` | One delete. | | `health_check()` | One listing of at most one object under the prefix. | -No request is retried. A failed request raises a `BackendError`: +The backend retries no request. The one exception is in the credentials layer: after an HTTP 401 it refreshes the access token and sends the request again. A failed request raises a `BackendError`: | Failure | `BackendErrorType` | |---------|--------------------| | HTTP 401, 403; credentials missing or refused | `AUTHENTICATION` | -| HTTP 429, 5xx; connection failed | `TRANSIENT` | +| HTTP 429, 5xx; connection failed; token endpoint or metadata server unreachable; checksum mismatch | `TRANSIENT` | | Timeout; HTTP 408 | `TIMEOUT` | | Any other HTTP error, such as a bucket that does not exist | `PERMANENT` | @@ -153,7 +153,7 @@ A 404 for an object is not an error: `get` returns `None` and `delete` returns ` - TTL support: Yes, checked on read; no upper bound below the file format's 10 years - Cross-process: Yes (shared by every process that can reach the bucket) - Persistence: Yes -- Thread-safe: Yes. Threads may share one backend +- Threads: threads may share one backend - Fork: build the backend after `fork()`, not before ## Limitations diff --git a/src/cachekit/backends/gcs/backend.py b/src/cachekit/backends/gcs/backend.py index 245c34a51..283730505 100644 --- a/src/cachekit/backends/gcs/backend.py +++ b/src/cachekit/backends/gcs/backend.py @@ -49,8 +49,8 @@ class GCSBackend: expired entry is a miss, and the read deletes it. An entry nobody reads again stays until a bucket lifecycle rule removes it (see docs/backends/gcs.md). - Authentication is Application Default Credentials only. No request is retried: a failed - request raises a ``BackendError`` and the next call tries again. + Authentication is Application Default Credentials only. The backend retries no request: a + failed one raises a ``BackendError`` and the next call tries again. Examples: Create a backend (requires credentials and a bucket): @@ -65,7 +65,7 @@ class GCSBackend: """ def __init__(self, config: GCSBackendConfig | None = None) -> None: - """Initialize GCSBackend. Builds the client and sends no request. + """Initialize GCSBackend. Builds the client and sends no request to Cloud Storage. Args: config: Optional configuration. Defaults to loading from environment. @@ -97,10 +97,14 @@ def _discard(self, blob: Any) -> None: """Delete an expired or corrupt object that a read just saw. Best effort: the read is a miss either way. The delete is conditional on the generation the read saw, so an entry a writer stored in - between survives. A failure (a read-only identity, a lost race) is logged and dropped. + between survives; a response that named no generation deletes nothing. A failure (a + read-only identity, a lost race) is logged and dropped. """ + generation = blob.generation + if generation is None: + return try: - blob.delete(if_generation_match=blob.generation, timeout=self._timeout, retry=None) + blob.delete(if_generation_match=generation, timeout=self._timeout, retry=None) except Exception as exc: _logger.debug("GCS cleanup of a dead entry failed: %s", redact_error_for_log(exc)) @@ -122,7 +126,9 @@ def _read(self, operation: str, key: str, header_only: bool) -> bytes | None: except NotFound: return None except RequestRangeNotSatisfiable: - data = b"" # an empty object has no byte range to serve: truncated, like any short header + # An empty object has no byte range to serve. Read it whole instead: that response + # carries the generation, which the cleanup of this truncated entry is conditional on. + return self._read(operation, key, header_only=False) except Exception as exc: raise classify_gcs_error(exc, operation=operation, key=key) from exc @@ -157,7 +163,7 @@ def set(self, key: str, value: bytes, ttl: int | None = None) -> None: """Store value in Google Cloud Storage, replacing the key's object in one upload. An entry of up to 8 MiB goes in a single request. A larger one is a resumable upload of - two requests; the object is replaced only when the second completes. + several requests; the object is replaced only when the last completes. Args: key: Cache key to store. diff --git a/src/cachekit/backends/gcs/error_handler.py b/src/cachekit/backends/gcs/error_handler.py index 28f5bfbb8..dc101b690 100644 --- a/src/cachekit/backends/gcs/error_handler.py +++ b/src/cachekit/backends/gcs/error_handler.py @@ -12,12 +12,16 @@ def _classify(exc: Exception) -> tuple[BackendErrorType, str]: """The error type for exc, and the word that names it in the message.""" import requests.exceptions + import urllib3.exceptions from google.api_core.exceptions import GoogleAPICallError - from google.auth.exceptions import DefaultCredentialsError, GoogleAuthError, RefreshError + from google.auth.exceptions import GoogleAuthError, TransportError + from google.cloud.storage.exceptions import DataCorruption + cause = exc.args[0] if exc.args else None # Before the OSError branch: requests' exceptions are OSErrors, and its ConnectTimeout is also - # a ConnectionError. - if isinstance(exc, (requests.exceptions.Timeout, TimeoutError)): + # a ConnectionError. A read that times out part-way through a response body reaches here as a + # plain requests ConnectionError around urllib3's timeout. + if isinstance(exc, (requests.exceptions.Timeout, TimeoutError)) or isinstance(cause, urllib3.exceptions.TimeoutError): return BackendErrorType.TIMEOUT, "timeout" if isinstance(exc, GoogleAPICallError): status = exc.code @@ -28,10 +32,17 @@ def _classify(exc: Exception) -> tuple[BackendErrorType, str]: if status == 429 or (status is not None and status >= 500): return BackendErrorType.TRANSIENT, "transient error" return BackendErrorType.PERMANENT, "permanent error" - if isinstance(exc, (DefaultCredentialsError, RefreshError)): - return BackendErrorType.AUTHENTICATION, "authentication error" - # Any other auth failure is the token endpoint or metadata server being unreachable. - if isinstance(exc, (GoogleAuthError, OSError)): + if isinstance(exc, GoogleAuthError): + # The token endpoint or metadata server being unreachable is not a refused credential. It + # arrives as a TransportError, as a RefreshError wrapping one, or flagged retryable. + unreachable = isinstance(exc, TransportError) or isinstance(cause, TransportError) or getattr(exc, "retryable", False) + return ( + (BackendErrorType.TRANSIENT, "transient error") + if unreachable + else (BackendErrorType.AUTHENTICATION, "authentication error") + ) + # DataCorruption: the bytes received do not match the checksum the server sent with them. + if isinstance(exc, (OSError, DataCorruption)): return BackendErrorType.TRANSIENT, "transient error" return BackendErrorType.UNKNOWN, "unknown error" diff --git a/tests/integration/test_gcs_integration.py b/tests/integration/test_gcs_integration.py index bebbc4786..7adc868b4 100644 --- a/tests/integration/test_gcs_integration.py +++ b/tests/integration/test_gcs_integration.py @@ -83,7 +83,7 @@ def bucket(admin: Any) -> Iterator[Any]: def backend(bucket: Any) -> Any: from cachekit.backends.gcs import GCSBackend, GCSBackendConfig - return GCSBackend(GCSBackendConfig(bucket=bucket.name, timeout=5.0)) + return GCSBackend(GCSBackendConfig(bucket=bucket.name)) def _names(bucket: Any) -> list[str]: @@ -174,11 +174,12 @@ def test_prefix_is_part_of_the_object_name_only(self, bucket: Any) -> None: class TestExpiry: def test_expired_entry_is_a_miss_and_get_deletes_it(self, backend: Any, bucket: Any) -> None: - backend.set("k", b"v", ttl=1) + # The expiry is a whole second, rounded down: a 2-second TTL lasts between 1 and 2 seconds. + backend.set("k", b"v", ttl=2) assert backend.exists("k") is True assert len(_names(bucket)) == 1 - time.sleep(1.1) # the expiry is a whole second: the entry is dead once the clock reaches it + time.sleep(2.1) assert backend.get("k") is None assert _names(bucket) == [] diff --git a/tests/unit/backends/test_gcs_backend.py b/tests/unit/backends/test_gcs_backend.py index cc4e5c27b..a84c13806 100644 --- a/tests/unit/backends/test_gcs_backend.py +++ b/tests/unit/backends/test_gcs_backend.py @@ -7,6 +7,7 @@ from __future__ import annotations +import base64 import contextlib import hashlib import io @@ -23,6 +24,7 @@ pytest.importorskip("google.cloud.storage", reason="needs the gcs extra") +import google_crc32c import requests import requests.adapters import urllib3 @@ -30,6 +32,7 @@ from google.auth.exceptions import DefaultCredentialsError, RefreshError, TransportError from google.auth.transport.requests import AuthorizedSession from google.cloud import storage +from google.cloud.storage.exceptions import DataCorruption from cachekit.backends.base import BaseBackend, TTLInspectableBackend from cachekit.backends.errors import BackendError, BackendErrorType @@ -53,11 +56,20 @@ def _name(key: str) -> str: class _Reply: """One scripted HTTP response, or the exception the transport raises instead.""" - def __init__(self, status: int = 200, body: bytes = b"{}", generation: int | None = None, error: Exception | None = None): + def __init__( + self, + status: int = 200, + body: bytes = b"{}", + generation: int | None = None, + error: Exception | None = None, + headers: dict[str, str] | None = None, + ): self.status = status self.body = body - self.generation = generation self.error = error + self.headers = dict(headers or {}) + if generation is not None: + self.headers["X-Goog-Generation"] = str(generation) class _Transport(requests.adapters.BaseAdapter): @@ -75,9 +87,7 @@ def send(self, request: requests.PreparedRequest, **kwargs: Any) -> requests.Res reply = self.replies.pop(0) if reply.error is not None: raise reply.error - headers = {"Content-Length": str(len(reply.body))} - if reply.generation is not None: - headers["X-Goog-Generation"] = str(reply.generation) + headers = {"Content-Length": str(len(reply.body)), **reply.headers} raw = urllib3.HTTPResponse(body=io.BytesIO(reply.body), headers=headers, status=reply.status, preload_content=False) return self._build.build_response(request, raw) @@ -112,6 +122,10 @@ def backend(transport: _Transport) -> GCSBackend: return GCSBackend(GCSBackendConfig(bucket=BUCKET)) +def _if_generation_match(request: requests.PreparedRequest) -> list[str] | None: + return parse_qs(urlsplit(request.url or "").query).get("ifGenerationMatch") + + def _uploaded(request: requests.PreparedRequest) -> bytes: """The object bytes of a multipart upload request.""" content_type = request.headers["content-type"] @@ -171,7 +185,7 @@ def test_expired_entry_is_a_miss_and_is_deleted(self, backend: GCSBackend, trans assert transport.sent() == [("GET", f"/o/{_name('k')}"), ("DELETE", f"/o/{_name('k')}")] # Only the generation that was read: an entry stored in between survives. - assert parse_qs(urlsplit(transport.requests[1].url or "").query)["ifGenerationMatch"] == ["7"] + assert _if_generation_match(transport.requests[1]) == ["7"] @pytest.mark.parametrize( "body", @@ -183,6 +197,14 @@ def test_corrupt_entry_is_a_miss_and_is_deleted(self, backend: GCSBackend, trans assert backend.get("k") is None assert [method for method, _ in transport.sent()] == ["GET", "DELETE"] + assert _if_generation_match(transport.requests[1]) == ["3"] + + def test_dead_entry_of_unknown_generation_is_not_deleted(self, backend: GCSBackend, transport: _Transport) -> None: + """With no generation to condition on, a delete could remove an entry stored since the read.""" + transport.script(_Reply(body=b"CK")) + + assert backend.get("k") is None + assert [method for method, _ in transport.sent()] == ["GET"] @pytest.mark.parametrize("reserved,flags", [(1, 0), (0, 1), (0, 0x8000)]) @time_machine.travel(1_000_000, tick=False) @@ -213,6 +235,13 @@ def test_reads_only_the_header(self, backend: GCSBackend, transport: _Transport) assert transport.sent() == [("GET", f"/o/{_name('k')}")] assert transport.requests[0].headers["Range"] == "bytes=0-13" + def test_header_is_not_checked_against_the_whole_objects_checksum(self, backend: GCSBackend, transport: _Transport) -> None: + """A ranged response still carries the checksum of the whole object, which 14 bytes never match.""" + whole = base64.b64encode(google_crc32c.Checksum(_header() + b"a long payload").digest()).decode() + transport.script(_Reply(status=206, body=_header(), headers={"X-Goog-Hash": f"crc32c={whole}"})) + + assert backend.exists("k") is True + def test_absent_object(self, backend: GCSBackend, transport: _Transport) -> None: transport.script(_Reply(status=404)) assert backend.exists("k") is False @@ -223,11 +252,22 @@ def test_expired_entry_is_a_miss(self, backend: GCSBackend, transport: _Transpor assert backend.exists("k") is False def test_empty_object_is_a_miss_and_is_deleted(self, backend: GCSBackend, transport: _Transport) -> None: - """An empty object has no first byte, so the ranged read is refused with a 416.""" - transport.script(_Reply(status=416), _Reply(status=204, body=b"")) + """An empty object has no first byte, so the ranged read is refused with a 416. + + The 416 names no generation, so the object is read again, whole, before the conditional delete. + """ + transport.script(_Reply(status=416), _Reply(body=b"", generation=5), _Reply(status=204, body=b"")) assert backend.exists("k") is False - assert [method for method, _ in transport.sent()] == ["GET", "DELETE"] + assert [method for method, _ in transport.sent()] == ["GET", "GET", "DELETE"] + assert "Range" not in transport.requests[1].headers + assert _if_generation_match(transport.requests[2]) == ["5"] + + def test_entry_stored_over_an_empty_object_is_found(self, backend: GCSBackend, transport: _Transport) -> None: + transport.script(_Reply(status=416), _Reply(body=_header() + b"v", generation=6)) + + assert backend.exists("k") is True + assert len(transport.requests) == 2 def test_unknown_transform_is_a_miss_left_untouched(self, backend: GCSBackend, transport: _Transport) -> None: transport.script(_Reply(status=206, body=_header(flags=1))) @@ -330,11 +370,16 @@ def test_prefix_is_not_a_key_prefix(self, transport: _Transport) -> None: (requests.ReadTimeout(), BackendErrorType.TIMEOUT), (requests.ConnectTimeout(), BackendErrorType.TIMEOUT), (TimeoutError(), BackendErrorType.TIMEOUT), + (requests.ConnectionError(urllib3.exceptions.ReadTimeoutError(None, None, "Read timed out.")), BackendErrorType.TIMEOUT), # type: ignore[arg-type] (requests.ConnectionError(), BackendErrorType.TRANSIENT), + (requests.exceptions.ChunkedEncodingError(), BackendErrorType.TRANSIENT), + (DataCorruption(None, "checksum mismatch"), BackendErrorType.TRANSIENT), (ConnectionResetError(), BackendErrorType.TRANSIENT), (RefreshError("token"), BackendErrorType.AUTHENTICATION), (DefaultCredentialsError("none"), BackendErrorType.AUTHENTICATION), (TransportError("metadata server"), BackendErrorType.TRANSIENT), + (RefreshError(TransportError("metadata server")), BackendErrorType.TRANSIENT), + (RefreshError("token endpoint busy", retryable=True), BackendErrorType.TRANSIENT), (ValueError("?"), BackendErrorType.UNKNOWN), ] _OPERATIONS = { @@ -362,7 +407,9 @@ def test_http_status_mapping( assert len(transport.requests) == 1 # no retry @pytest.mark.parametrize("operation", _OPERATIONS) - @pytest.mark.parametrize("error,error_type", _TRANSPORT_CASES, ids=lambda v: type(v).__name__) + @pytest.mark.parametrize( + "error,error_type", _TRANSPORT_CASES, ids=[f"{i}-{type(e).__name__}" for i, (e, _) in enumerate(_TRANSPORT_CASES)] + ) def test_transport_error_mapping( self, backend: GCSBackend, transport: _Transport, operation: str, error: Exception, error_type: BackendErrorType ) -> None: @@ -436,12 +483,19 @@ def test_unhealthy_reports_the_error_and_does_not_raise( @pytest.mark.unit class TestNoBucketLevelRequest: - def test_no_operation_reads_bucket_metadata(self, backend: GCSBackend, transport: _Transport) -> None: + def test_no_operation_reads_bucket_metadata( + self, backend: GCSBackend, transport: _Transport, monkeypatch: pytest.MonkeyPatch + ) -> None: """Every request is to an object or the object listing, so object-level IAM is enough. The client library would otherwise fetch the bucket itself in a background thread, on the - first request and again after every 404. + first request and again after every 404. Its two entry points to that are recorded here, + on the calling thread, so the test does not depend on when a background thread runs. """ + cache_module = pytest.importorskip("google.cloud.storage._bucket_metadata_cache") + fetches: list[str] = [] + for entry_point in ("get_or_queue_fetch", "check_and_evict"): + monkeypatch.setattr(cache_module.BucketMetadataCache, entry_point, lambda self, name: fetches.append(name)) transport.script( _Reply(status=404), # get: miss _Reply(), # set @@ -460,7 +514,7 @@ def test_no_operation_reads_bucket_metadata(self, backend: GCSBackend, transport backend.delete("k") backend.health_check() - assert backend._client._bucket_metadata_cache is None + assert fetches == [] assert transport.replies == [] assert all(path == "/o" or path.startswith("/o/") for _, path in transport.sent()) From 6656fc43f3f5be3fb8fca0691fe19562f32a10ee Mon Sep 17 00:00:00 2001 From: Ray Walker Date: Fri, 27 Nov 2026 20:16:32 +1100 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20address=20coderabbit=20review=20?= =?UTF-8?q?=E2=80=94=20lifecycle=20caveat,=20missing-bucket=20reads,=20nar?= =?UTF-8?q?rower=20cleanup=20catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cleanup of a dead entry drops only a failed request (API, auth or network error); any other exception is a bug and propagates. Docs: applying a lifecycle file replaces the bucket's existing rules; a read of an absent bucket is a miss, not an error; the per-operation request count links to its exceptions. Tests: the unit transport also answers http://, so an ambient STORAGE_EMULATOR_HOST cannot route unit tests to a live server; the thread test fails if a worker is still running. CodeRabbit-Resolved: gcs.md:108:Preserve existing bucket CodeRabbit-Resolved: gcs.md:133:Correct the missing-bucke CodeRabbit-Resolved: README.md:101:Qualify the request coun CodeRabbit-Resolved: test_gcs_integration.py:135:Check that every worke CodeRabbit-Resolved: test_gcs_backend.py:113:Intercept HTTP requests CodeRabbit-Resolved: backend.py:109:Swallowed exceptions in --- docs/backends/README.md | 4 ++-- docs/backends/gcs.md | 7 +++++-- src/cachekit/backends/gcs/backend.py | 10 +++++++--- tests/integration/test_gcs_integration.py | 1 + tests/unit/backends/test_gcs_backend.py | 3 ++- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/docs/backends/README.md b/docs/backends/README.md index d4eac6606..fe16f7881 100644 --- a/docs/backends/README.md +++ b/docs/backends/README.md @@ -98,7 +98,7 @@ class BaseBackend(Protocol): | **[File](file.md)** | set = fsync + a scan of every entry, so slow on a large cache; get waits on a concurrent set ([cost model](file.md#performance-characteristics)) | Yes (disk) | Format shared; one writer process | Yes | File locks | | **[Redis](redis.md)** | One network round trip per operation ([not measured here](../performance.md#not-measured-here)) | Yes (RDB/AOF) | Yes | Yes | Yes | | **[Memcached](memcached.md)** | One network round trip per operation ([not measured here](../performance.md#not-measured-here)) | No | Yes | Yes (max 30d) | No | -| **[Google Cloud Storage](gcs.md)** | One HTTPS request to GCS per operation ([not measured here](../performance.md#not-measured-here)) | Yes | Yes | Yes (checked on read) | No | +| **[Google Cloud Storage](gcs.md)** | One HTTPS request to GCS per ordinary operation ([request counts](gcs.md#requests-per-operation); [not measured here](../performance.md#not-measured-here)) | Yes | Yes | Yes (checked on read) | No | | **[CacheKit Cloud](cachekitio.md)** | 42–45ms p50 hit, measured from MEL ([varies by vantage](cachekitio.md#characteristics)) | Yes | Yes | Yes | Yes | | **[HTTP (custom)](custom.md)** | One HTTP request per operation ([not measured here](../performance.md#not-measured-here)) | Varies | Yes | Varies | Varies | | **[DynamoDB (custom)](custom.md)** | One DynamoDB API request per operation ([not measured here](../performance.md#not-measured-here)) | Yes | Yes | Yes | No | @@ -424,7 +424,7 @@ first call (and runs uncached if nothing listens there): give it `backend=RedisB | **HTTP API** | One HTTP request per operation ([not measured here](../performance.md#not-measured-here)) | Custom cloud services | Network dependent | | **DynamoDB** | One DynamoDB API request per operation ([not measured here](../performance.md#not-measured-here)) | Serverless, low-traffic | High availability | | **Memcached** | One network round trip per operation ([not measured here](../performance.md#not-measured-here)) | Alternative to Redis | No persistence | -| **Google Cloud Storage** | One HTTPS request to GCS per operation ([not measured here](../performance.md#not-measured-here)) | Expensive results kept across runs, no server | No locking; expiry checked on read | +| **Google Cloud Storage** | One HTTPS request to GCS per ordinary operation ([request counts](gcs.md#requests-per-operation); [not measured here](../performance.md#not-measured-here)) | Expensive results kept across runs, no server | No locking; expiry checked on read | --- diff --git a/docs/backends/gcs.md b/docs/backends/gcs.md index 0df9381a6..9bbd13450 100644 --- a/docs/backends/gcs.md +++ b/docs/backends/gcs.md @@ -110,6 +110,9 @@ gcloud storage buckets update gs://my-cache-bucket --lifecycle-file=lifecycle.js `age` is in days and counts from when the object was written. Drop `matchesPrefix` when the bucket holds nothing else. +> [!CAUTION] +> `--lifecycle-file` replaces the bucket's whole lifecycle configuration. If the bucket already has rules, read them first (`gcloud storage buckets describe gs://my-cache-bucket --format="default(lifecycle_config)"`) and apply a file that holds them and the cache rule together. + > [!WARNING] > The rule deletes by age alone. An entry cached with no TTL, or with a TTL longer than `age`, is deleted when it reaches `age` and becomes a miss. @@ -130,9 +133,9 @@ The backend retries no request. The one exception is in the credentials layer: a | HTTP 401, 403; credentials missing or refused | `AUTHENTICATION` | | HTTP 429, 5xx; connection failed; token endpoint or metadata server unreachable; checksum mismatch | `TRANSIENT` | | Timeout; HTTP 408 | `TIMEOUT` | -| Any other HTTP error, such as a bucket that does not exist | `PERMANENT` | +| Any other HTTP error, such as a `set` to a bucket that does not exist | `PERMANENT` | -A 404 for an object is not an error: `get` returns `None` and `delete` returns `False`. Under `@cache`, a failed read is a miss and the function runs, and a failed write skips the backend only. +A 404 on a read or a delete is not an error: `get` returns `None`, `exists` and `delete` return `False`. GCS answers 404 for an absent bucket too, so a wrong bucket name reads as an empty cache; `set` raises, and `health_check()` reports it. Under `@cache`, a failed read is a miss and the function runs, and a failed write skips the backend only. ## When to Use diff --git a/src/cachekit/backends/gcs/backend.py b/src/cachekit/backends/gcs/backend.py index 283730505..7a133700b 100644 --- a/src/cachekit/backends/gcs/backend.py +++ b/src/cachekit/backends/gcs/backend.py @@ -97,15 +97,19 @@ def _discard(self, blob: Any) -> None: """Delete an expired or corrupt object that a read just saw. Best effort: the read is a miss either way. The delete is conditional on the generation the read saw, so an entry a writer stored in - between survives; a response that named no generation deletes nothing. A failure (a - read-only identity, a lost race) is logged and dropped. + between survives; a response that named no generation deletes nothing. A failed request + (a read-only identity, a lost race, the network) is logged and dropped; anything else is + a bug and propagates. """ + from google.api_core.exceptions import GoogleAPICallError + from google.auth.exceptions import GoogleAuthError + generation = blob.generation if generation is None: return try: blob.delete(if_generation_match=generation, timeout=self._timeout, retry=None) - except Exception as exc: + except (GoogleAPICallError, GoogleAuthError, OSError) as exc: _logger.debug("GCS cleanup of a dead entry failed: %s", redact_error_for_log(exc)) def _read(self, operation: str, key: str, header_only: bool) -> bytes | None: diff --git a/tests/integration/test_gcs_integration.py b/tests/integration/test_gcs_integration.py index 7adc868b4..7dc14010f 100644 --- a/tests/integration/test_gcs_integration.py +++ b/tests/integration/test_gcs_integration.py @@ -134,6 +134,7 @@ def work(i: int) -> None: for thread in threads: thread.join(timeout=60) + assert not any(thread.is_alive() for thread in threads) assert errors == [] diff --git a/tests/unit/backends/test_gcs_backend.py b/tests/unit/backends/test_gcs_backend.py index a84c13806..d69cac4c9 100644 --- a/tests/unit/backends/test_gcs_backend.py +++ b/tests/unit/backends/test_gcs_backend.py @@ -110,7 +110,8 @@ def transport(monkeypatch: pytest.MonkeyPatch) -> _Transport: def build(project: str | None) -> storage.Client: credentials = AnonymousCredentials() session = AuthorizedSession(credentials) - session.mount("https://", transport) + for scheme in ("https://", "http://"): # http: an ambient STORAGE_EMULATOR_HOST must not reach a real server + session.mount(scheme, transport) return storage.Client(project=project or "test-project", credentials=credentials, _http=session) monkeypatch.setattr("cachekit.backends.gcs.backend._build_client", build)