cfstate

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 Encode

func Encode(m *Manifest, encKey []byte) ([]byte, error)

Encode serializes and encrypts a manifest for local or remote storage.

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 Decode

func Decode(data, encKey []byte) (*Manifest, error)

Decode decrypts and parses a manifest from its encrypted representation.

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) AllRecords added in v1.2.2

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

AllRecords returns every record including deletion tombstones, sorted by kind:name.

func (*Manifest) Get

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

Get returns the active (non-tombstoned) recorded resource, if any.

func (*Manifest) GetRaw added in v1.2.2

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

GetRaw returns the raw record including tombstones (for state sync).

func (*Manifest) List

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

List returns all active (non-tombstoned) records sorted by kind:name.

func (*Manifest) Orphans

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

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

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

Set records (or replaces) an active resource, preserving ConfigHash/Protected if an existing non-deleted entry matches, and clearing any prior tombstone.

func (*Manifest) SetRecord added in v1.2.2

func (m *Manifest) SetRecord(rec Record)

SetRecord writes a full Record verbatim (used by drivers setting ConfigHash / Protected and by state_sync merges preserving tombstones).

func (*Manifest) Tombstone added in v1.2.2

func (m *Manifest) Tombstone(kind, name, deletedAt string)

Tombstone marks a resource as deleted at deletedAt so remote state merges never resurrect a destroyed resource from a stale peer copy.

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
}

Record is one provisioned Cloudflare resource.

func (Record) EffectiveTimestamp added in v1.2.2

func (r Record) EffectiveTimestamp() string

EffectiveTimestamp returns the most recent mutation timestamp on r (DeletedAt if tombstoned more recently than UpdatedAt, otherwise UpdatedAt).

func (Record) IsDeleted added in v1.2.2

func (r Record) IsDeleted() bool

IsDeleted reports whether this record is a deletion tombstone.

Jump to

Keyboard shortcuts

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