config

package
v0.45.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 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 config is the SDK-owned configuration layer: it resolves WHERE to talk (Control/Broker URLs) and AS WHOM (identity/environment), from either injected environment variables (the file-less path) or ~/.config/jentic/config.yaml.

It is deliberately UX-free. The presentational Mode/Theme concepts are NOT part of this package — they live in the CLI's clictx wrapper, which embeds the ResolvedState produced here (impl/1.2 §3a, 7.0_public_sdk.md). This keeps client/config importable by third parties with no Cobra/UX baggage.

Index

Constants

View Source
const (
	// DefaultBaseURL is the Jentic control-plane (auth surface) base URL used
	// for agent registration and token minting when no environment overrides it.
	// Loopback + http by design: the out-of-the-box target is a local install
	// (`jenticctl install`), and 127.0.0.1 (not localhost) so the token-exchange
	// audience matches the backend's canonical_base_url byte-for-byte.
	DefaultBaseURL = "http://127.0.0.1:8000"

	// DefaultBrokerScheme is the scheme of the broker target used by execute.
	DefaultBrokerScheme = "https"

	// DefaultBrokerHost is the host of the broker target used by execute. It is a
	// bare host[:port] with NO scheme — the scheme lives in DefaultBrokerScheme.
	// Callers assemble the URL as scheme + "://" + host, so embedding a scheme
	// here would double it.
	DefaultBrokerHost = "127.0.0.1:8100"
)

Default control-plane and broker endpoints for a local Jentic install.

These live in the public SDK config package (ARCH-3) — not internal/config — because they are part of the SDK's connection contract: a downstream importer constructing a client.Config, or resolving a broker target, needs the same canonical defaults the CLI uses, without reaching into a CLI-private package. internal/config re-exports these so existing CLI call sites are unchanged.

View Source
const (
	FilelessIdentity    = "jentic.file-less-agent"
	FilelessEnvironment = "jentic.ephemeral"
)

Reserved sentinel identity/environment names for the file-less path. They use a "jentic." prefix containing a dot precisely so they can NEVER collide with a real on-disk identity/environment name (those are validated to a dot-free charset by ValidName), keeping the ephemeral path's token-state/key filenames disjoint from any disk-mode name (impl/1.2 §3, impl/4.1 §1).

Variables

This section is empty.

Functions

func CacheDir

func CacheDir() (string, error)

CacheDir resolves the Jentic cache directory. It honors XDG_CACHE_HOME first (OPS-1) so the cache location is predictable and overridable on EVERY OS — matching ConfigDir/StateDir, and important for Docker volume mounts and cross-machine docs where os.UserCacheDir's platform-native path (~/Library/ Caches on macOS, %LocalAppData% on Windows) would ignore the operator's XDG_CACHE_HOME. When XDG_CACHE_HOME is unset it defers to os.UserCacheDir. Cache contents are disposable; never store tokens here (see StateDir).

func ConfigDir

func ConfigDir() (string, error)

ConfigDir resolves the Jentic config directory. It enforces the XDG layout (~/.config/jentic) on EVERY OS — including Windows, where it ignores %AppData% — so paths are predictable for Docker volume mounts and cross-machine docs (impl/1.2 §2). Honors XDG_CONFIG_HOME.

Named ConfigDir (not Dir) deliberately: it forms a symmetric trio with CacheDir/StateDir and matches every impl-guide call site (config.ConfigDir()); renaming only this one would break that symmetry.

func MutateConfig

func MutateConfig(mutator func(*Config) error) error

MutateConfig loads the current config, applies the mutator, and writes it back atomically under an advisory cross-process lock.

Concurrency: registration (Phase 4.1) and other writers do read-modify-write on config.yaml; two concurrent CI pipelines registering the same identity could interleave and clobber one another's status/client_id. We hold an advisory flock for the whole critical section. The lock is on a SEPARATE config.lock sidecar (never config.yaml itself) so the atomic rename below cannot replace the file we hold the lock on.

Unknown-key preservation: a naive Unmarshal(Config) + Marshal(Config) round-trip SILENTLY DROPS any key the struct doesn't know. Two real populations depend on unknown keys surviving: (1) the mixed-version reality (an older binary mutating a newer binary's config must not strip newer fields), and (2) the enterprise overlay's extension data. So we parse into a yaml.Node tree, decode the typed Config view for the mutator, then merge the mutated typed view BACK onto the original node — unknown keys and comments pass through untouched (impl/1.3 §2).

func SanitizeName

func SanitizeName(s string) string

SanitizeName coerces an arbitrary string into a name that satisfies ValidName (ARCH-22: the single canonical "arbitrary string → valid config name" primitive, replacing the two subtly-divergent sanitizers in cmdcore/register and api/migrate). It lowercases, collapses non-charset runs to "-", trims leading/trailing "-", prefixes "x" when the result doesn't start with an alnum, and clamps to 64 chars. Returns "" only when nothing survives (empty input) — callers supply their own fallback ("default"/"agent"). It is idempotent on names that already satisfy ValidName.

func StateDir

func StateDir() (string, error)

StateDir resolves the XDG *state* directory (~/.local/state/jentic). OAuth tokens are STATE, not cache: they are active cryptographic sessions that MUST survive an OS cache purge (purging ~/.cache mid-run would destroy every agent's session and trigger a re-exchange storm), so tokens are never stored under CacheDir. Honors XDG_STATE_HOME; like ConfigDir it enforces the XDG layout on every OS.

func ValidName

func ValidName(name string) bool

ValidName reports whether name is a legal identity/environment/context name. This is the single source of truth for the charset; client/auth aliases it.

func WriteFileAtomic added in v0.45.1

func WriteFileAtomic(path string, data []byte) error

WriteFileAtomic writes data to path via a temp file in the SAME directory, fsync'd, then renamed into place — so a crash / ENOSPC between truncate and write can never leave a partial or empty file, and a pre-existing temp symlink or mode cannot redirect or widen the write. All config and credential files share the 0600 mode, so it is fixed here rather than a parameter.

Types

type Config

type Config struct {
	ActiveContext string              `yaml:"active_context"`
	Contexts      map[string]Context  `yaml:"contexts"`
	Environments  map[string]Env      `yaml:"environments"`
	Identities    map[string]Identity `yaml:"identities"`
	// Theme is global (one presentation preference per machine), deliberately not
	// per-context: you don't want dark in one context and light in another.
	Theme string `yaml:"theme,omitempty"`
}

Config is the on-disk schema for ~/.config/jentic/config.yaml. Environments and Identities are decoupled and glued together by Contexts.

Mode/Theme are retained here because they are PERSISTED; only the resolved, in-memory representation splits UX out (see ResolvedState). This package reads these strings but never interprets them.

func Load

func Load() (*Config, error)

Load reads and parses ~/.config/jentic/config.yaml WITHOUT resolving the active context. It is the read-only counterpart to MutateConfig, used by helpers that need the raw config (e.g. clientIDFor in Phase 4.2). Returns an empty Config (not an error) when the file does not exist yet.

type Context

type Context struct {
	Environment string `yaml:"environment"`
	Identity    string `yaml:"identity"`
	Mode        string `yaml:"mode"` // "human" or "agent"; any other value fails closed to agent
}

Context binds an environment + identity + interaction mode. Mode lives here (not on Config) because it is a security/behavior property of the actor: a prod admin context is "human" while a CI agent context is "agent" and must stay fenced. context use flips the whole I/O + fencing posture atomically.

type Env

type Env struct {
	BaseURL string `yaml:"base_url"` // Control Plane (registry, auth, executions)
	// BrokerURL is the Data Plane endpoint used by execute/history (Phase 5).
	// Optional here; when unset for a REMOTE control plane, `jentic execute`
	// fail-closes with a recovery directive rather than silently dialing the
	// local default (see the remote-broker guard in api/execute.go).
	BrokerURL string `yaml:"broker_url,omitempty"`
	// CACertPath optionally points at a custom CA bundle for verifying TLS to
	// self-hosted deployments behind a private CA. It never mutates the OS trust
	// store.
	CACertPath string `yaml:"ca_cert_path,omitempty"`
}

Env is a deployment target. BaseURL and BrokerURL are separate, explicit fields because Control Plane and Broker frequently live on different domains in enterprise deployments — BrokerURL is NEVER derived from BaseURL.

type EnvRegState

type EnvRegState struct {
	ClientID string `yaml:"client_id"`
	Status   string `yaml:"status"` // "pending", "approved"
}

EnvRegState is the registration record for one (identity, environment) pair.

type Identity

type Identity struct {
	Type         string                 `yaml:"type"` // "agent", "user"
	Environments map[string]EnvRegState `yaml:"environments,omitempty"`
}

Identity is an actor (agent or user). Per-environment registration state lives under Environments, keyed by environment name.

type ResolvedState

type ResolvedState struct {
	IdentityName        string
	EnvironmentName     string
	BaseURL             string
	BrokerURL           string // Data Plane / Broker endpoint (Phase 5); separate from BaseURL
	CACertPath          string // optional custom CA bundle for TLS verification (SEC-3)
	InjectedBearerToken string
	SessionID           string // X-Jentic-Session-Id (telemetry, Phase 5)

	// PersistedMode / PersistedTheme are the raw strings read from config.yaml (or
	// env-derived defaults). The SDK does NOT act on them; the CLI wrapper
	// interprets them. They live here so the CLI need not re-parse the file.
	PersistedMode  string
	PersistedTheme string
}

ResolvedState is the UX-free, SDK-owned result of config resolution. It carries exactly what client.Config needs to talk to the API. The CLI wraps this with its presentational Mode/Theme (impl/1.2 §3a); the SDK never interprets the Persisted* strings.

func LoadState

func LoadState(cmdContextOverride string) (*ResolvedState, error)

LoadState resolves the active configuration, prioritizing environment variables (the file-less path) over disk. cmdContextOverride, when non-empty, selects a context other than the persisted active one.

Jump to

Keyboard shortcuts

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