configver

package
v1.0.430 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 11 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 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

View Source
const DefaultMax = 50

DefaultMax is the default maximum number of retained versions.

Variables

View Source
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

func New(dir string, maxVersions int) *Store

New returns a store rooted at dir keeping at most maxVersions versions (maxVersions <= 0 selects DefaultMax). Call Init before first use.

func (*Store) Dir

func (s *Store) Dir() string

Dir returns the store directory (read by the diagnostics summarizer).

func (*Store) Init

func (s *Store) Init()

Init creates the directory and resumes the sequence counter from the highest existing vN.json.

func (*Store) Integrity added in v1.0.194

func (s *Store) Integrity() (present, readable int)

Integrity scans the version directory and reports how many candidate v{N}.json files exist (present) versus how many parsed cleanly via ListMeta (readable). present > readable means one or more files are corrupt or unreadable and have been silently excluded from List/ListMeta (D1.2-flag-F5) — those versions are unusable rollback targets even though they still count toward the max-versions retention window. Callers use this to raise an operator-visible diagnostic instead of relying on the obs.Printf skip lines, which are invisible without log/SSH access.

func (*Store) List

func (s *Store) List() []Meta

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

func (s *Store) ListMeta() []Meta

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

func (s *Store) Load(ver int) (Meta, json.RawMessage, error)

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

func (s *Store) Save(actor, action, createdAt string, config json.RawMessage) (int, error)

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) Seq

func (s *Store) Seq() int

Seq returns the current sequence counter (the last assigned version).

func (*Store) SetDirForTest

func (s *Store) SetDirForTest(dir string)

SetDirForTest redirects the store to dir. Test isolation only.

func (*Store) SetSeqForTest

func (s *Store) SetSeqForTest(n int)

SetSeqForTest overrides the sequence counter. Test isolation only.

Jump to

Keyboard shortcuts

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