Documentation
¶
Overview ¶
Package config resolves CLI configuration from layered sources: CLI flags, environment variables, a .env file, a YAML config file and built-in defaults, in that precedence order (highest first).
Secrets (passwords, tokens) are never stored in the YAML config file. They are surfaced through Resolved.Secrets when supplied via flags/env/.env, or loaded from the OS keychain by the auth package.
Index ¶
- Constants
- func ConfigFilePath(dir string) string
- func DefaultConfigDir() (string, error)
- func ExplainField(sources map[string]string, field string) string
- func ResolveConfigDir() (string, error)
- func UnknownContextHint(name string, available []string) string
- func WriteFile(dir string, f File) error
- type AuthConfig
- type Config
- type Defaults
- type File
- type FlagValues
- type LoadOptions
- type NamedContext
- type Resolved
- type Secrets
Constants ¶
const ( // SchemeBasic is email+password HTTP Basic auth. SchemeBasic = "basic" // SchemeToken is a pre-generated credential sent as-is in the // Authorization header (the base64 portion of a Basic token, or a full // "Basic …"/"Bearer …" value). SchemeToken = "token" )
Auth scheme values.
const ( ContextSourceFlag = "flag" // --use-context ContextSourceEnv = "env" // OPENOBSERVE_CONTEXT ContextSourceCurrent = "current_context" // the file's current_context ContextSourceSingle = "single" // the sole defined context ContextSourceDefault = "default-name" // a context literally named "default" ContextSourceNone = "none" // nothing selected (no/empty config) )
Context selection sources, reported on Resolved.ContextSource. The first two are explicit (the caller named a context for this invocation); the rest are implicit (the CLI fell back to a stored or sole context).
const ( FieldServer = fieldServer FieldOrg = fieldOrg FieldAuthScheme = fieldAuthScheme FieldAuthUser = fieldAuthUsername FieldFormat = fieldFormat FieldTimeout = fieldTimeout FieldMaxRetries = fieldMaxRetries FieldReadOnly = fieldReadOnly )
Field key accessors for callers outside this package (e.g. config show).
const DefaultContextName = "default"
DefaultContextName is the name given to an unnamed context.
Variables ¶
This section is empty.
Functions ¶
func ConfigFilePath ¶
func DefaultConfigDir ¶
func ExplainField ¶
ExplainField returns a human-readable provenance label for a field key.
func ResolveConfigDir ¶
func UnknownContextHint ¶
UnknownContextHint builds the hint shown when a context override names a context that does not exist.
Types ¶
type AuthConfig ¶
type AuthConfig = pkgcfg.AuthConfig
The persistent config-file model moved to the public pkg/config so the desktop GUI can read/write the same file. These aliases keep the existing internal callers (loader.go, internal/app) compiling unchanged. The layered loader (flags/env/file) stays in this package.
type Config ¶
type Config struct {
BaseURL string `yaml:"server"`
Org string `yaml:"org"`
Auth AuthConfig `yaml:"auth"`
Defaults Defaults `yaml:"defaults"`
}
Config holds the resolved, non-secret configuration.
type Defaults ¶
The persistent config-file model moved to the public pkg/config so the desktop GUI can read/write the same file. These aliases keep the existing internal callers (loader.go, internal/app) compiling unchanged. The layered loader (flags/env/file) stays in this package.
type File ¶
The persistent config-file model moved to the public pkg/config so the desktop GUI can read/write the same file. These aliases keep the existing internal callers (loader.go, internal/app) compiling unchanged. The layered loader (flags/env/file) stays in this package.
type FlagValues ¶
FlagValues carries the global CLI flags that override configuration. Empty fields are ignored (not treated as overrides).
type LoadOptions ¶
type LoadOptions struct {
// ConfigDir overrides the directory containing config.yaml.
ConfigDir string
// DotenvPath overrides the .env file path. Empty means ".env".
DotenvPath string
// Flags carries global flag overrides (highest precedence).
Flags FlagValues
// Context selects a named context (from the --use-context flag). It wins
// over OPENOBSERVE_CONTEXT and the file's current_context.
Context string
}
LoadOptions controls where configuration is read from. All fields are optional; sensible defaults are used when empty.
type NamedContext ¶
type NamedContext = pkgcfg.NamedContext
The persistent config-file model moved to the public pkg/config so the desktop GUI can read/write the same file. These aliases keep the existing internal callers (loader.go, internal/app) compiling unchanged. The layered loader (flags/env/file) stays in this package.
type Resolved ¶
type Resolved struct {
Config Config
Secrets Secrets
// Sources maps a field key to the layer name that supplied its final
// value: "flag", "env", "dotenv", "file", "default".
Sources map[string]string
// ActiveContext is the name of the context whose fields were applied.
// Empty when no config file (or no contexts) exists — pure-env usage.
ActiveContext string
// ContextSource records which precedence rule chose ActiveContext (one of
// the ContextSource* constants), so callers can tell an explicit choice
// (flag/env) from an implicit fallback (current_context, sole, default).
ContextSource string
// ContextNames lists every context defined in the file, in file order.
ContextNames []string
}
Resolved is the outcome of Load: the merged Config plus provenance and any transient secrets.
func Load ¶
func Load(opt LoadOptions) (*Resolved, error)
Load resolves configuration from all sources and returns the merged result with per-field provenance.
func (*Resolved) ContextSelectedExplicitly ¶ added in v0.5.0
ContextSelectedExplicitly reports whether the active context was chosen for this invocation (via --use-context or OPENOBSERVE_CONTEXT) rather than fallen back to from the file's current_context, the sole context, or a "default" context. It is the signal used to decide whether to nudge an agent that may not realise which of several contexts it is hitting.