cf

package
v0.33.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cf implements the dispatch.Dispatcher interface using a Cloudflare Worker as the token mint. The Worker runs the mintcore WASM module compiled from cmd/mint-wasm, with a thin TypeScript adapter (workersrc/) handling I/O. Credentials are read from env vars (CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_API_TOKEN) — no secrets are passed as CLI flags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultWorkerSourceDir

func DefaultWorkerSourceDir() string

DefaultWorkerSourceDir returns the default path to the Worker source directory. This assumes the CLI is run from the repository root.

func EmbeddedWorkerSource

func EmbeddedWorkerSource() fs.FS

EmbeddedWorkerSource returns the embedded Worker source filesystem for testing embed integrity.

func ValidateCloudflareEnv

func ValidateCloudflareEnv() error

ValidateCloudflareEnv checks that required Cloudflare environment variables are set. Returns an error listing all missing variables.

func ValidateWorkerName

func ValidateWorkerName(name string) bool

ValidateWorkerName checks if a string is a valid CF Worker name.

Types

type Config

type Config struct {
	// AccountID is the Cloudflare account ID. Read from
	// CLOUDFLARE_ACCOUNT_ID env var.
	AccountID string

	// WorkerName is the Worker script name (e.g. "fullsend-mint",
	// "fullsend-mint-test"). Defaults to "fullsend-mint".
	WorkerName string

	// DeployMode controls whether the Worker is deployed as a durable
	// production Worker or an ephemeral preview.
	DeployMode DeployMode

	// SourceDir overrides the embedded Worker source with a local
	// directory. When set, the provisioner uses this path directly
	// instead of extracting embedded files. The directory must
	// contain the workersrc tree including mintcore.wasm and
	// wasm_exec.js (staged by `make wasm-stage`).
	SourceDir string

	// EnvVars are non-secret environment variables to set on the Worker
	// (e.g. ROLE_APP_IDS, ALLOWED_ORGS, OIDC_AUDIENCE).
	EnvVars map[string]string

	// Version is the fullsend semver stamped on the deployed Worker.
	Version string

	// Commit is the git SHA stamped on the deployed Worker.
	Commit string
}

Config holds the inputs for CF Worker mint provisioning.

type DeployMode

type DeployMode int

DeployMode controls Worker deployment behavior.

const (
	// DeployDurable deploys a persistent, production Worker.
	DeployDurable DeployMode = iota
	// DeployPreview deploys an ephemeral preview Worker for testing.
	DeployPreview
)

type LiveWranglerRunner

type LiveWranglerRunner struct {
	// AccountID is passed to wrangler via CLOUDFLARE_ACCOUNT_ID.
	AccountID string
}

LiveWranglerRunner executes wrangler commands via the CLI.

func NewLiveWranglerRunner

func NewLiveWranglerRunner(accountID string) *LiveWranglerRunner

NewLiveWranglerRunner creates a runner that uses the real wrangler CLI.

func (*LiveWranglerRunner) Delete

func (r *LiveWranglerRunner) Delete(ctx context.Context, workerName string) error

Delete removes a Worker deployment via wrangler delete.

func (*LiveWranglerRunner) Deploy

func (r *LiveWranglerRunner) Deploy(ctx context.Context, sourceDir, workerName string, preview bool, envVars map[string]string) (string, error)

Deploy deploys a Worker from sourceDir using wrangler deploy.

func (*LiveWranglerRunner) PutSecret

func (r *LiveWranglerRunner) PutSecret(ctx context.Context, workerName, secretName string, value []byte) error

PutSecret stores a secret value on a Worker via wrangler secret put.

type Provisioner

type Provisioner struct {
	// contains filtered or unexported fields
}

Provisioner creates Cloudflare Worker infrastructure for token minting.

func NewProvisioner

func NewProvisioner(cfg Config, wrangler WranglerRunner) *Provisioner

NewProvisioner creates a new CF Provisioner with defaults applied.

func (*Provisioner) Name

func (p *Provisioner) Name() string

Name returns the dispatcher identifier.

func (*Provisioner) OrgSecretNames

func (p *Provisioner) OrgSecretNames() []string

OrgSecretNames returns nil — PEM secrets are stored as Worker secrets.

func (*Provisioner) OrgVariableNames

func (p *Provisioner) OrgVariableNames() []string

OrgVariableNames returns the org variables this dispatcher manages.

func (*Provisioner) Provision

func (p *Provisioner) Provision(ctx context.Context) (map[string]string, error)

Provision deploys the Cloudflare Worker mint and returns the Worker URL as FULLSEND_MINT_URL.

func (*Provisioner) StoreAgentPEM

func (p *Provisioner) StoreAgentPEM(ctx context.Context, role string, pemData []byte) error

StoreAgentPEM stores a role's PEM key as a Cloudflare Worker secret. Secret names follow the convention <ROLE>_APP_PEM (e.g. CODER_APP_PEM).

func (*Provisioner) Teardown

func (p *Provisioner) Teardown(ctx context.Context) error

Teardown removes a preview Worker deployment. Only valid when DeployMode is DeployPreview.

type WranglerRunner

type WranglerRunner interface {
	// Deploy deploys a Worker from sourceDir. Returns the Worker URL.
	Deploy(ctx context.Context, sourceDir, workerName string, preview bool, envVars map[string]string) (url string, err error)

	// PutSecret stores a secret value on a Worker.
	PutSecret(ctx context.Context, workerName, secretName string, value []byte) error

	// Delete removes a Worker deployment.
	Delete(ctx context.Context, workerName string) error
}

WranglerRunner abstracts wrangler CLI operations for testing.

Jump to

Keyboard shortcuts

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