edgedeploy

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
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

type Client struct {
	BaseURL string
	HTTP    *http.Client
	// contains filtered or unexported fields
}

Client talks to the Cloudflare API. BaseURL and HTTP are overridable for tests.

func New

func New(token string) *Client

New returns a Client authenticated with the given API token.

func (*Client) Deploy

func (c *Client) Deploy(ctx context.Context, cfg Config, scriptSource string) error

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

func (c *Client) Disable(ctx context.Context, cfg Config) error

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

func (c *Client) Enable(ctx context.Context, cfg Config) error

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL