config

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 9 Imported by: 0

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

View Source
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.

View Source
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).

View Source
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).

View Source
const DefaultContextName = "default"

DefaultContextName is the name given to an unnamed context.

Variables

This section is empty.

Functions

func ConfigFilePath

func ConfigFilePath(dir string) string

func DefaultConfigDir

func DefaultConfigDir() (string, error)

func ExplainField

func ExplainField(sources map[string]string, field string) string

ExplainField returns a human-readable provenance label for a field key.

func ResolveConfigDir

func ResolveConfigDir() (string, error)

func UnknownContextHint

func UnknownContextHint(name string, available []string) string

UnknownContextHint builds the hint shown when a context override names a context that does not exist.

func WriteFile

func WriteFile(dir string, f File) error

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

type Defaults = pkgcfg.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

type File = pkgcfg.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.

func ReadFile

func ReadFile(dir string) (File, bool, error)

type FlagValues

type FlagValues struct {
	BaseURL string
	Org     string
	Format  string
	Timeout string
}

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

func (r *Resolved) ContextSelectedExplicitly() bool

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.

type Secrets

type Secrets struct {
	Password string
	Token    string
}

Secrets holds credentials observed in non-file layers. Empty fields mean the secret was not supplied via flags/env/.env and must come from the keychain.

Jump to

Keyboard shortcuts

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