identity

package
v0.6.19 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package identity resolves the NodeID this agent reports to the admin server. It implements the resolution policy decided in the refactor plan (decision 15):

  1. UUIDv4 persisted at ${StateDir}/node_id. Stable across restarts.
  2. If the file cannot be read or written: fallback to "<hostname>-<random8>" and log a WARN.

Resolution is performed once at agent boot. The resulting NodeID is constant for the lifetime of the process; the agent never re-reads the file. Operators rotating the file see no effect until the next restart, which matches the goal of stable identity.

Index

Constants

View Source
const FileName = "node_id"

FileName is the path component, relative to the state directory, where the NodeID is persisted.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resolved

type Resolved struct {
	// NodeID is the value the agent will use in NodeRegistration.
	NodeID string

	// Persistent is true when the value came from (or was newly written to)
	// the state directory; false when the value is ephemeral and will not
	// survive a restart.
	Persistent bool

	// Source is a short human-readable label for diagnostics.
	// Values: "loaded", "created", "ephemeral-hostname", "ephemeral-random".
	Source string
}

Resolved describes the outcome of NodeID resolution.

type Resolver

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

Resolver looks up or assigns the NodeID. Use New to construct one.

func New

func New(stateDir string, logger *slog.Logger) *Resolver

New constructs a Resolver. stateDir is the directory under which node_id is read/written (typically the value of the framework's state_dir configuration key, e.g. "./.nucleus-state"). The logger is used for the single WARN we emit on fallback.

func (*Resolver) Resolve

func (r *Resolver) Resolve() Resolved

Resolve returns the NodeID this process will use. It is idempotent: the first call may write a fresh UUIDv4 to disk; subsequent calls return the same string by reading the file again.

Resolve never returns an error: if persistence fails, it falls back to an ephemeral value and surfaces the failure via the Source field and a WARN log line. The agent prefers "running with a less-than-ideal node id" over "refusing to start".

Jump to

Keyboard shortcuts

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