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 ( 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 ¶
ConfigFilePath returns the YAML config file path inside dir.
func DefaultConfigDir ¶
DefaultConfigDir returns the per-user config directory (~/.angelmsger/openobserve).
func ExplainField ¶
ExplainField returns a human-readable provenance label for a field key.
func ResolveConfigDir ¶
ResolveConfigDir picks the config directory to use when --config was not supplied.
func UnknownContextHint ¶
UnknownContextHint builds the hint shown when a context override names a context that does not exist.
Types ¶
type AuthConfig ¶
type AuthConfig struct {
Scheme string `yaml:"scheme"`
Username string `yaml:"username,omitempty"`
}
AuthConfig holds non-secret auth settings.
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 struct {
Format string `yaml:"format"`
Timeout time.Duration `yaml:"timeout"`
MaxRetries int `yaml:"max_retries"`
// ReadOnly blocks every mutating client method. Settable from the config
// file, from OPENOBSERVE_CLI_READ_ONLY, or temporarily overridden via
// --allow-writes.
ReadOnly bool `yaml:"read_only,omitempty"`
}
Defaults holds tunable runtime defaults.
type File ¶
type File struct {
CurrentContext string
Contexts []NamedContext
Defaults Defaults
}
File is the parsed config file: a set of named contexts plus the shared runtime defaults and the name of the current context.
func ReadFile ¶
ReadFile reads and parses the config file in dir. The bool return is false when the file does not exist.
func (File) Context ¶
func (f File) Context(name string) (NamedContext, bool)
Context returns the context whose name matches, case-insensitively. The returned struct carries the canonical (as-stored) name; callers that intend to persist a reference to the context must use the returned NamedContext.Name.
func (File) ContextNames ¶
ContextNames returns every context name, in file order.
func (*File) Upsert ¶
func (f *File) Upsert(nc NamedContext)
Upsert inserts or replaces a context by (case-insensitive) name, preserving file order for existing entries.
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 struct {
Name string
BaseURL string
Org string
Auth AuthConfig
}
NamedContext is one named OpenObserve server profile inside the config file. Runtime defaults are shared across contexts and live in File.Defaults.
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
// 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.