Documentation
¶
Overview ¶
Package edgedeploy is the Cadish Edge management plane's Cloudflare API client. It uploads the worker bundle + bindings, ensures the (opt-in) KV namespace, and attaches/detaches the worker routes — the three operations behind `cadish edge deploy / enable / disable` (design §7).
Auth is a Cloudflare API token (env CF_API_TOKEN), never in the Cadishfile. The client speaks the Cloudflare v4 REST API and is fully unit-testable against an httptest server (BaseURL is overridable).
Separation of concerns (design §9, kill switch): deploy uploads the script with NO routes (testable via the *.workers.dev URL, no production traffic); enable attaches the routes (go-live); disable detaches them (instant bypass to the cadish server behind).
Index ¶
Constants ¶
const DefaultBaseURL = "https://api.cloudflare.com/client/v4"
DefaultBaseURL is the Cloudflare v4 API root.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client talks to the Cloudflare API. BaseURL and HTTP are overridable for tests.
func (*Client) Deploy ¶
Deploy uploads the worker script + bindings WITHOUT attaching any route. It first ensures the KV namespace (only when the config uses one) so the binding can reference its id. After Deploy the worker is reachable at its *.workers.dev URL but receives no production traffic until Enable.
func (*Client) Disable ¶
Disable detaches every route pointing at the worker (instant bypass / kill switch). Idempotent: with no such routes it is a no-op.
func (*Client) Enable ¶
Enable attaches the configured routes to the worker (go-live). It is idempotent: a route whose pattern already points at the worker (or, for an exclusion, already runs no worker) is left as-is.
ORDERING (D105 correctness): the no-script EXCLUSION (carve-out) routes are created FIRST and the worker's `<host>/*` route LAST. The carve-outs are the more-specific patterns that negate the worker on paths it must not run; creating `/*` before them would open a window where the worker is live with the excluded paths routing THROUGH it — a silent behavior regression. Building the carve-outs first means that the moment `/*` goes live, every exclusion is already in place.
ATOMICITY: Enable is transactional within a run. If any create fails, the routes THIS run created are rolled back (best-effort delete) before returning, so a partial apply never leaves the worker live over an incomplete carve-out set — and the operation stays re-runnable (each create is idempotent; a re-run resumes from the pre-Enable state). A cleanup that cannot fully complete is surfaced (logged) in the returned error, not swallowed.
type Config ¶
type Config struct {
AccountID string
Zone string // zone name (e.g. example.com) or zone id (32-hex)
WorkerName string
Routes []string
KVNamespace string // "" => no L2, no namespace bound
OriginURL string // CADISH_ORIGIN binding (the cadish server behind)
Upstreams map[string]string // optional CADISH_UPSTREAMS binding (name -> url)
// RouteExclusions are host+prefix CF route globs the worker should NOT run on (D105):
// paths the worker would only ever `pass`. Enable creates one no-script route per
// pattern (a route with the `script` field omitted matches but runs no worker, so CF
// proxies it straight to origin and the more-specific pattern wins over the worker's
// `<host>/*` route); Disable removes them. Empty (the default) → no exclusion routes.
RouteExclusions []string
}
Config is the resolved deploy target + the worker's runtime bindings. Identity (account/zone/worker/routes/kv) comes from the `edge {}` block; OriginURL (and the optional Upstreams map) are deploy-time bindings — the IR carries upstream NAMES only, the concrete URL lives here (D34).