cfstate

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cfstate is the persistent, encrypted record of the Cloudflare resources NextDeploy has provisioned (D1, KV, Hyperdrive, Queues, Vectorize, …) keyed by kind+name → real CF ID.

Why it exists: name-based `ensure*` already prevents duplicate creation, but a manifest lets the engine (a) skip live `list` round-trips on re-runs and (b) detect orphans — resources it recorded but the user no longer declares in nextdeploy.yml. The file is AES-256-GCM encrypted (the resource graph of an account is sensitive metadata) and written 0600.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(kind, name string) string

Key is the canonical map key for a (kind, name) pair. Exported so callers can build the "declared" set passed to Orphans.

func Save

func Save(path string, m *Manifest, encKey []byte) error

Save writes the manifest AES-256-GCM encrypted (key must be 32 bytes) to path, mode 0600. Parent dirs are created.

Types

type Manifest

type Manifest struct {
	Version   int               `json:"version"`
	Resources map[string]Record `json:"resources"`
}

Manifest maps "kind:name" → Record.

func Load

func Load(path string, encKey []byte) (*Manifest, error)

Load reads + decrypts the manifest. A missing file yields a fresh (empty) manifest, not an error — first run is normal. A decrypt failure (wrong key or corruption) IS an error so a split-brain isn't silently masked.

func New

func New() *Manifest

New returns an empty manifest.

func (*Manifest) Get

func (m *Manifest) Get(kind, name string) (Record, bool)

Get returns the recorded resource, if any.

func (*Manifest) List

func (m *Manifest) List() []Record

List returns all records sorted by kind:name (deterministic).

func (*Manifest) Orphans

func (m *Manifest) Orphans(declared map[string]bool) []Record

Orphans returns recorded resources whose key is NOT in declared (the set of "kind:name" the user currently declares). These were provisioned earlier but dropped from nextdeploy.yml — candidates for manual cleanup.

func (*Manifest) Set

func (m *Manifest) Set(kind, name, id, updatedAt string)

Set records (or replaces) a resource.

type Record

type Record struct {
	Kind      string `json:"kind"`       // d1, kv, hyperdrive, queue, vectorize, ai_gateway
	Name      string `json:"name"`       // declared name
	ID        string `json:"id"`         // CF resource UUID / identifier
	UpdatedAt string `json:"updated_at"` // RFC3339, stamped by the caller
}

Record is one provisioned Cloudflare resource.

Jump to

Keyboard shortcuts

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