catoverride

package
v1.0.310 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 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 catoverride is the admin-owned category-override engine for the signed SaaS URL-category feed (F3a-1, per roadmap/FEEDS-DISTRIBUTION-F3-DESIGN.md §7.2).

It holds the three override kinds an administrator layers ON TOP of the feed-owned snapshot — additions, recategorizations, and tombstones — and the PURE composition function that folds them into an effective host→category view the policy engine reads. The override keys carry the SAME suffix semantics as a feed entry (a key `example.com` covers `example.com` and every subdomain, matching the engine's per-category suffix walk, F0 §7.5).

SCOPE (F3a-1): this package is the schema, normalization/validation boundary, persistence (a schema-versioned, strict-decoded envelope via fileutil.AtomicWrite), and the pure composition. It carries NO API, NO CP→DP wire, NO GUI, and NO downloader — those are later slices. Normalization is delegated to internal/urlcatfeed so the override host/category grammar is byte-identical to the feed producer/verifier.

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the on-disk envelope schema for overrides.json. A file carrying a HIGHER version was written by a newer binary this one cannot safely interpret, so Load fails closed rather than silently mis-reading it (the downgrade guard, F3a §A.5.1).

Variables

View Source
var (
	// ErrSchemaTooNew is returned by Load when the file's schema_version exceeds
	// this binary's SchemaVersion — a downgrade into a binary that cannot safely
	// interpret the newer schema. Fail closed; never mutate the file.
	ErrSchemaTooNew = errors.New("catoverride: overrides file schema is newer than this binary supports")
	// ErrUnknownField is returned when the file carries JSON keys the contract
	// does not define (strict decode).
	ErrUnknownField = errors.New("catoverride: overrides file has unknown fields")
	// ErrPersist marks a durable full-set replacement failure: the replacement
	// was rolled back and the previous override set is live in memory AND on a
	// reload (2D-B.0b, the 2D-A doctrine).
	ErrPersist = errors.New("catoverride: override persistence failed")
)

Distinct load errors so callers/tests can assert the exact class.

View Source
var (
	ErrDuplicateHost   = errors.New("catoverride: host appears in more than one override map")
	ErrTombstoneClash  = errors.New("catoverride: host is both tombstoned and added/recategorized")
	ErrCategoryCase    = errors.New("catoverride: category names collide case-insensitively")
	ErrMultiCategory   = errors.New("catoverride: host assigned to more than one category")
	ErrSuffixConflict  = errors.New("catoverride: ancestor/descendant hosts in different categories")
	ErrInvalidHost     = errors.New("catoverride: invalid override host")
	ErrInvalidCategory = errors.New("catoverride: invalid override category name")
)

Validation error sentinels — tests assert the exact class via errors.Is.

Functions

func ComposeMembership added in v1.0.207

func ComposeMembership(feed map[string][]string, o Overrides) map[string][]string

ComposeMembership is ComposeView over a host→CATEGORIES map: the membership companion used when the baseline taxonomy is many-to-many (a host in several categories at once). Suppression and insertion semantics are IDENTICAL to ComposeView — same tombstone/assert-key suffix suppression, same override insertion — so the two compositions always agree on which keys survive.

An override key is the sole authority over its subtree, so an inserted recategorization/addition replaces the WHOLE membership list for its key with the single override category. A tombstone removes every category for the covered subtree. That keeps a removal a real removal: a multi-category host cannot survive a tombstone through one of its other categories.

func ComposeView

func ComposeView(feed map[string]string, o Overrides) map[string]string

ComposeView folds the overrides onto a feed-owned snapshot and returns the effective host→category view (F0 §7.2). It is PURE and deterministic: the snapshot is not mutated, and repeated calls on equal input return equal output.

Precedence (admin layer 1 over feed layer 2): every override key carries host+subdomain SUFFIX scope (F0 §7.5), so an override key GOVERNS ITS WHOLE SUBTREE. Start from the feed snapshot and drop every entry that is equal to or a subdomain of a tombstone OR of an added/recategorized key — a descendant feed host must not survive in a different category than the override that covers it (which the policy engine's per-category suffix walk could otherwise match in both, F0 §7.4). Then insert the recategorizations and additions. Validate already forbids tombstoning a host the admin also asserts, so no override erases another.

Note: this makes each override key the sole authority over its subtree. A residual ancestor/descendant conflict between an override key and a feed ANCESTOR outside its subtree (e.g. an override for `app.example.com` while the feed keeps `example.com` in another category) is an override↔feed interaction that can only be detected against the live feed at activation (F3b), since overrides are validated in isolation here.

func SealedKeys added in v1.0.207

func SealedKeys(o Overrides) map[string]bool

SealedKeys returns the set of override boundary keys — the hosts an override makes AUTHORITATIVE for their whole subtree (recategorizations, additions, and tombstones). A membership suffix-walk that reaches one of these keys must STOP there rather than climbing to an ancestor baseline category: the override is the sole authority for the key and its subdomains, so an ancestor category it did not assert must not leak back in. This mirrors the keys ComposeMembership makes authoritative (out[host] replacement + subtree suppression), so the two stay consistent by construction.

func Validate

func Validate(o Overrides) error

Validate enforces the override model on an ALREADY-normalized set. It assumes hosts/categories are canonical (Normalize guarantees this) and checks the cross-field invariants. Deterministic: it walks maps in sorted host order so a rejection message is stable.

Types

type Overrides

type Overrides struct {
	Added         map[string]string `json:"added,omitempty"`         // host → category to insert
	Recategorized map[string]string `json:"recategorized,omitempty"` // host → category to repoint
	Tombstones    []string          `json:"tombstones,omitempty"`    // hosts to suppress (self + subdomains)
}

Overrides is the admin-owned override set. Maps key on the NORMALIZED host (urlcatfeed.NormalizeHost) and values are CANONICAL category names (urlcatfeed.CanonicalCategoryName). All three kinds carry host+subdomain suffix scope (F0 §7.5).

func Normalize

func Normalize(o Overrides) (Overrides, error)

Normalize returns a canonicalized, validated copy of o: every host is NormalizeHost-reduced, every category CanonicalCategoryName-reduced, and the whole set is run through Validate. Any violation rejects the WHOLE set (all-or-nothing) — it never returns a partially-normalized value.

type RevisionConflictError added in v1.0.218

type RevisionConflictError struct {
	Current  string
	Asserted string
}

RevisionConflictError reports a failed optimistic-revision fence on the full-set replacement: the client asserted the override revision it loaded (the caller-supplied content fingerprint) and the current set differs. Same structured-409 contract as the other 2D fences.

func (*RevisionConflictError) Error added in v1.0.218

func (e *RevisionConflictError) Error() string

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds the current overrides with race-safe access and file persistence.

func New

func New() *Store

New builds an empty store.

func (*Store) Get

func (s *Store) Get() Overrides

Get returns a deep copy of the current overrides (safe to mutate/serialize).

func (*Store) Load

func (s *Store) Load(path string) error

Load reads the schema-versioned envelope from path. A missing file is the normal first-run state (empty overrides, no error). A present file is STRICTLY decoded (unknown fields rejected), its schema is checked (a newer schema fails closed via ErrSchemaTooNew), and its overrides are normalized + validated before they become live — a structurally-corrupt or invalid file returns an error and leaves the store empty, never partially applied.

func (*Store) Path

func (s *Store) Path() string

Path reports the persistence path ("" ⇒ persistence disabled).

func (*Store) ReplaceAll

func (s *Store) ReplaceAll(o Overrides) error

ReplaceAll validates then wholesale-replaces the override set. An empty set is a legitimate value (clears every override) — the store-level counterpart to the wire deletion-propagation the later CP→DP slice adds. Invalid input is rejected and the current set is left untouched (all-or-nothing). Holds mutMu so a bulk install (cluster apply / import / rollback) orders against the fenced durable replacement; memory-only — the callers' separate Save() reacquires the domain and publishes the current committed state.

func (*Store) ReplaceAllDurable added in v1.0.218

func (s *Store) ReplaceAllDurable(expectedRev *string, next Overrides, revOf func(Overrides) string) (Overrides, error)

ReplaceAllDurable is the fenced durable FULL-SET replacement (2D-B.0b):

fence (optional expected revision, computed by the caller-supplied revOf
over the CURRENT set) → normalize/validate the target → replace → durable
save → success — all under mutMu, one serialization domain, no detached
check, no TOCTOU, no last-write-wins.

revOf is the caller's canonical content-revision function (production: the saasFeedOverridesFingerprint that is already the durable authority revision truth). Fence mismatch ⇒ *RevisionConflictError (nothing ran). Validation failure ⇒ error, current set untouched. Persistence failure ⇒ the previous set is restored (memory AND a reload agree) + ErrPersist — a failed full-set replacement is never present after restart. ErrReplacedNotSynced follows the landed-content doctrine. On success the stored (normalized) set is returned for the caller's response/recompose.

func (*Store) Save

func (s *Store) Save() error

Save persists the current overrides as the schema-versioned envelope via an atomic (temp+fsync+rename+parent-fsync) write. A no-path store is a no-op. PUBLIC entry: acquires mutMu first (commit-boundary doctrine) so a standalone save can never observe — or publish — an in-flight durable replacement; the durable primitive holds mutMu and calls saveLocked directly (mutMu is not reentrant — never call Save from inside it).

func (*Store) SetPathForTest

func (s *Store) SetPathForTest(path string)

SetPathForTest points persistence at path without loading (test helper + used by callers that construct-then-Load).

Jump to

Keyboard shortcuts

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