config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 10 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 (
	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

ConfigFilePath returns the YAML config file path inside dir.

func DefaultConfigDir

func DefaultConfigDir() (string, error)

DefaultConfigDir returns the per-user config directory (~/.angelmsger/openobserve).

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)

ResolveConfigDir picks the config directory to use when --config was not supplied.

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

WriteFile persists a File to dir/config.yaml, creating dir with 0700 permissions. Secrets are never written here.

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

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

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

func (f File) ContextNames() []string

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

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

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