sync

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileChecksum

func FileChecksum(path string) (string, error)

FileChecksum computes sha256 of a file's contents. Returns empty string (not error) for missing files.

Types

type Engine

type Engine struct {
	DryRun bool
	// contains filtered or unexported fields
}

Engine manages the sync loop.

func NewEngine

func NewEngine(cfg *config.Config, vc *vault.Client, username, statePath string) *Engine

NewEngine creates a new sync engine.

func (*Engine) RunLoop

func (e *Engine) RunLoop(ctx context.Context, opts ...RunLoopOption) error

RunLoop runs the hybrid event/poll sync loop until ctx is cancelled. It performs an initial RunOnce up front, fires any AfterInitialSync hook, then enters the ticker / event loop. The initial RunOnce error is logged but does not abort the loop — per-rule isolation is the engine's invariant.

func (*Engine) RunOnce

func (e *Engine) RunOnce(ctx context.Context) error

RunOnce executes a single sync cycle across all rules.

func (*Engine) State

func (e *Engine) State() *StateStore

State returns the underlying state store for external access.

func (*Engine) TriggerSync

func (e *Engine) TriggerSync()

TriggerSync requests an immediate sync cycle.

func (*Engine) UpdateConfig added in v0.22.0

func (e *Engine) UpdateConfig(rules []config.Rule, interval time.Duration)

UpdateConfig swaps the engine's dynamic configuration at runtime: the rule set and the poll interval. Called by the daemon's config-refresh loop when the remote overlay (or an edited local config) changes them. No-op when nothing changed. On a rule change, state entries for removed rules are pruned (so state.json converges with the rule set) and an immediate sync is triggered; on an interval change the run loop's ticker is reset.

type RuleState

type RuleState struct {
	VaultVersion int       `json:"vault_version"`
	LastSynced   time.Time `json:"last_synced"`
	FileChecksum string    `json:"file_checksum"`
	// RuleHash fingerprints the rule's render-affecting definition (vault key
	// and target path/format/template/merge) as of the last write. The skip
	// gate compares it so a template edit re-applies even when the secret
	// version and on-disk file are both unchanged. Empty in state written by
	// older versions, which forces a one-time reconciling re-sync on upgrade.
	RuleHash string `json:"rule_hash,omitempty"`
}

RuleState tracks the sync state for a single rule.

type RunLoopOption

type RunLoopOption func(*runLoopConfig)

RunLoopOption tunes RunLoop's behaviour without exposing the engine's internal sequencing to callers.

func AfterInitialSync

func AfterInitialSync(fn func()) RunLoopOption

AfterInitialSync registers a callback invoked exactly once, synchronously, after RunLoop's initial RunOnce returns and before the ticker / event loop starts. The daemon uses this to gate sd_notify(READY=1) and the web server's readiness flag on the initial sync completing — without leaking the initial-sync-then- loop sequencing to every caller via a separately-exported RunLoopAfterInitial entry point.

type StateStore

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

StateStore manages sync state persistence.

func NewStateStore

func NewStateStore(path string) *StateStore

NewStateStore creates a new state store at the given path.

func (*StateStore) Get

func (s *StateStore) Get(name string) RuleState

Get returns the state for a rule. Returns zero-value RuleState if not found.

func (*StateStore) Load

func (s *StateStore) Load() error

Load reads the state file from disk. If the file doesn't exist, starts empty.

func (*StateStore) Prune added in v0.22.0

func (s *StateStore) Prune(keep map[string]bool) int

Prune removes state entries for rules not present in keep, returning the number removed. Used when the rule set changes at runtime (remote config refresh) so state.json doesn't accumulate orphaned entries for rules that no longer exist. The caller is responsible for Save.

func (*StateStore) Rules

func (s *StateStore) Rules() map[string]RuleState

Rules returns a copy of all rule states.

func (*StateStore) Save

func (s *StateStore) Save() error

Save writes the state file to disk atomically.

func (*StateStore) Set

func (s *StateStore) Set(name string, rs RuleState)

Set updates the state for a rule.

Jump to

Keyboard shortcuts

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