Documentation
¶
Overview ¶
Package configver implements the numbered config-version snapshot store (ADR-0002 extraction; engine was the store half of configversion.go in package main).
The store owns version numbering (mutex + startup dir-scan resume), the on-disk envelope ({meta, config} as vN.json, atomic 0o600 writes), the max-versions prune, and list/load. It deliberately never sees the typed configuration: the envelope's config half crosses the boundary as json.RawMessage, because the concrete type (main's configBackup) is a hub spanning every config store. Capture/apply/diff/validation and the API handlers stay in package main.
On-disk format is unchanged: /<dir>/v{N}.json containing {"meta": {version, created_at, actor, action}, "config": {...}}.
Index ¶
- Constants
- Variables
- type Meta
- type Store
- func (s *Store) Dir() string
- func (s *Store) Init()
- func (s *Store) List() []Meta
- func (s *Store) ListMeta() []Meta
- func (s *Store) Load(ver int) (Meta, json.RawMessage, error)
- func (s *Store) Save(actor, action, createdAt string, config json.RawMessage) (int, error)
- func (s *Store) SaveWithNote(actor, action, createdAt, note string, config json.RawMessage) (int, error)
- func (s *Store) Seq() int
- func (s *Store) SetDirForTest(dir string)
- func (s *Store) SetSeqForTest(n int)
Constants ¶
const DefaultMax = 50
DefaultMax is the default maximum number of retained versions.
Variables ¶
var ErrCorrupt = errors.New("corrupt version file")
ErrCorrupt marks a version file that exists but cannot be parsed as an envelope. Callers use it to distinguish "not found" (read error) from "unusable" — the rollback API maps the former to 404, the latter to 500.
Functions ¶
This section is empty.
Types ¶
type Meta ¶
type Meta struct {
Version int `json:"version"`
CreatedAt string `json:"created_at"`
Actor string `json:"actor"`
Action string `json:"action"` // what triggered the snapshot (e.g. "policy.update", "blocklist.import")
Note string `json:"note,omitempty"` // optional free-text reason (e.g. a policy-draft commit comment)
}
Meta is the version metadata half of the on-disk envelope.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a numbered snapshot store rooted at one directory.
func New ¶
New returns a store rooted at dir keeping at most maxVersions versions (maxVersions <= 0 selects DefaultMax). Call Init before first use.
func (*Store) Init ¶
func (s *Store) Init()
Init creates the directory and resumes the sequence counter from the highest existing vN.json.
func (*Store) List ¶
List returns all readable version metadata sorted descending by version. Unreadable or unparseable files are skipped with a log line (D1.2-flag-F5: the rollback UI never sees them otherwise) — never an error. The result is always non-nil.
func (*Store) ListMeta ¶ added in v1.0.115
ListMeta is List without the config bodies: it decodes only each file's meta object, so a metadata-only caller (e.g. the support-bundle collector) never copies up to `max` config snapshots into memory. Same descending order and skip-on-error semantics as List; the result is always non-nil.
func (*Store) Load ¶
Load reads one version. A read failure is returned as-is (os.IsNotExist checkable → the API's 404); an unparseable envelope wraps ErrCorrupt. The config half is returned raw for the caller to unmarshal.
func (*Store) Save ¶
Save assigns the next version number, writes the envelope atomically (0o600), prunes beyond max, and returns the assigned version. The sequence number is consumed even when the write fails (unchanged behavior — a gap, not a reuse).
func (*Store) SaveWithNote ¶ added in v1.0.92
func (s *Store) SaveWithNote(actor, action, createdAt, note string, config json.RawMessage) (int, error)
SaveWithNote is Save plus an optional free-text note recorded in the version metadata (used by the policy-draft commit path to persist the commit comment).
func (*Store) SetDirForTest ¶
SetDirForTest redirects the store to dir. Test isolation only.
func (*Store) SetSeqForTest ¶
SetSeqForTest overrides the sequence counter. Test isolation only.