Provision Media

What pithy add media did, and what pithy media provision does

pithy add media writes bindings and touches no Cloudflare account. pithy media provision stands up what those bindings point at.

ResourceWhen
An R2 bucketAlways
media-storage-credentialsAlways
media-r2-credentialsAlways
media-images-signing-keyWhile some record could be private
media-stream-signing-keyWhile some record could be private
The media WorkerAlways — it hosts the four enrichment Workflows

All of it per environment, alongside pithy provision for the resources every capability needs. Which backends are stood up depends on the type map.

Two secrets because media reads one of them

media-storage-credentials is the account id the assets live in, and nothing else. Media’s own. Minting an upload, changing signing, deleting and reading what was served all use the application’s one runtime token, which pithy secrets provision mints per environment.

media-r2-credentials is the R2 key pair and bucket, and it is read by storage’s object store. Media declares the name and never opens the values.

Two signing keys because private media is signed

While visibility.allowed admits anything but public, a non-public Images or Stream asset is uploaded with requireSignedURLs, and the Worker signs a short-lived URL for a caller who may read it.

media-images-signing-key is the account’s Images URL-signing key, read as found, or created as pithy when the account has none. media-stream-signing-key is a Stream signing key. Cloudflare hands its private half back once, at creation, so one is created only when the environment holds none, and a re-run keeps the stored key.

Before anything is created, provisioning refuses if any Images variant is set to neverRequireSignedURLs, naming each: such a variant serves a private image to anyone holding its URL.

The one thing you supply

Every step is idempotent

Find-then-create for resources, create-then-update for the secrets, and a deploy that overwrites. Re-running provisioning against an already-provisioned account is a no-op.

The live Cloudflare and wrangler steps sit behind a seam, so the orchestration — order, idempotency, the per-environment fan-out — is unit-tested against a fake that records its call order, with no account involved.

Three namespaces, three limits, one facade

Media names the same capability twice: an R2 bucket and a host Worker. Both cap at 63, and they are still asked for separately. Records live in D1, so there is no KV namespace.

Every name goes through the naming facade, and each resource asks for its own kind:

That is what stops one number standing in for every kind. A name truncated to another resource’s limit is a name that works and is quietly wrong; a name allowed a looser limit is a create that fails at the API. Asking for the right kind gets the right rule.

It is also what refuses production here rather than quietly provisioning a fourth environment under a name nobody declared.

The project is validated once and the environment once, in a single call, before either asks for anything.

The per-environment posture

acme-staging-media and acme-prod-media are different buckets, and the media Worker is deployed per environment too.

A shared bucket would put staging’s writes in prod’s reads and let a staging teardown delete prod’s media. The project segment carries ownership, because R2’s namespace is flat and account-wide and provisioning reuses what it finds by name — so without it a second Pithy project in the account adopts this one’s bucket.

ESC