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 ¶
- func Encode(m *Manifest, encKey []byte) ([]byte, error)
- func Key(kind, name string) string
- func Save(path string, m *Manifest, encKey []byte) error
- type Manifest
- func (m *Manifest) AllRecords() []Record
- func (m *Manifest) Get(kind, name string) (Record, bool)
- func (m *Manifest) GetRaw(kind, name string) (Record, bool)
- func (m *Manifest) List() []Record
- func (m *Manifest) Orphans(declared map[string]bool) []Record
- func (m *Manifest) Set(kind, name, id, updatedAt string)
- func (m *Manifest) SetRecord(rec Record)
- func (m *Manifest) Tombstone(kind, name, deletedAt string)
- type Record
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Key ¶
Key is the canonical map key for a (kind, name) pair. Exported so callers can build the "declared" set passed to Orphans.
Types ¶
type Manifest ¶
type Manifest struct {
Version int `json:"version"`
Resources map[string]Record `json:"resources"`
}
Manifest maps "kind:name" → Record.
func Load ¶
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 (*Manifest) AllRecords ¶ added in v1.2.2
AllRecords returns every record including deletion tombstones, sorted by kind:name.
func (*Manifest) GetRaw ¶ added in v1.2.2
GetRaw returns the raw record including tombstones (for state sync).
func (*Manifest) Orphans ¶
Orphans returns active 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 ¶
Set records (or replaces) an active resource, preserving ConfigHash/Protected if an existing non-deleted entry matches, and clearing any prior tombstone.
type Record ¶
type Record struct {
Kind string `json:"kind"` // r2, d1, kv, hyperdrive, queue, queue_consumer, vectorize, ai_gateway, workflow, secrets_store, dispatch_namespace
Name string `json:"name"` // declared name
ID string `json:"id"` // CF resource UUID / identifier
UpdatedAt string `json:"updated_at"` // RFC3339, stamped by the caller
DeletedAt string `json:"deleted_at,omitempty"` // RFC3339 tombstone when destroyed
ConfigHash string `json:"config_hash,omitempty"` // SHA-256 fingerprint for idempotent plan checks (e.g. Hyperdrive)
Protected bool `json:"protected,omitempty"` // Refuse deletion during teardown when true
// Adopted marks a resource that already existed when NextDeploy first
// recorded it (matched by name, not created by us). Teardown never deletes
// adopted resources: they may belong to another app or predate NextDeploy.
Adopted bool `json:"adopted,omitempty"`
// Jurisdiction is an R2 bucket's data jurisdiction (e.g. "eu"); every R2
// API call for such a bucket must carry it.
Jurisdiction string `json:"jurisdiction,omitempty"`
}
Record is one provisioned Cloudflare resource.
func (Record) EffectiveTimestamp ¶ added in v1.2.2
EffectiveTimestamp returns the most recent mutation timestamp on r (DeletedAt if tombstoned more recently than UpdatedAt, otherwise UpdatedAt).