config

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package config holds Console's runtime configuration. Configuration is read from environment variables with sensible defaults; the CLI layers flags on top. Keeping this dependency-free (env + defaults, no YAML parser) keeps the binary small and the config surface obvious.

Index

Constants

View Source
const (
	// AuthAuto enables authentication whenever at least one token is configured.
	AuthAuto = "auto"
	// AuthDisabled turns authentication off even if tokens are configured. It is
	// the documented escape hatch for deployments fronted by an authenticating
	// proxy; it is never used in quickstarts.
	AuthDisabled = "disabled"
)

Auth modes accepted by Config.AuthMode (CONSOLE_AUTH).

View Source
const (
	// CookieSecureAuto sets Secure when the request is TLS or carries
	// X-Forwarded-Proto: https.
	CookieSecureAuto = "auto"
	// CookieSecureAlways always sets Secure.
	CookieSecureAlways = "always"
)

Session cookie Secure-attribute modes accepted by Config.CookieSecure (CONSOLE_COOKIE_SECURE).

View Source
const (
	LogText = "text"
	LogJSON = "json"
)

Log formats accepted by Config.LogFormat.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Addr is the HTTP listen address. Defaults to loopback (127.0.0.1:8080)
	// because the API and dashboard have no built-in authentication yet —
	// exposing them requires an authenticating reverse proxy. Set ":8080" (all
	// interfaces) deliberately, behind such a proxy. See docs/security/.
	Addr string
	// DB is the storage DSN. For SQLite this is a file path ("console.db") or
	// "" / ":memory:" for an in-memory database.
	DB string
	// StorePlugin is the path to an out-of-process storage-backend plugin
	// executable (e.g. console-plugin-postgres). When set, it replaces the
	// built-in SQLite store; the plugin inherits this process's environment.
	StorePlugin string
	// NotifyPlugins are paths to out-of-process notifier plugin executables
	// (e.g. console-plugin-slack). Each is launched and registered as a sink;
	// plugins inherit this process's environment (e.g. CONSOLE_SLACK_WEBHOOK_URL).
	NotifyPlugins []string
	// StatusPlugins are paths to out-of-process status-provider plugin
	// executables (e.g. console-plugin-cloudflare). Each is launched and
	// registered with the status engine; plugins inherit this process's
	// environment (e.g. CLOUDFLARE_API_TOKEN).
	StatusPlugins []string
	// LLMPlugin is the path to an out-of-process LLM provider plugin executable
	// (e.g. console-plugin-anthropic). When set, it supplies the AI-Assisted
	// onboarding provider over gRPC; empty disables AI-Assisted mode. The plugin
	// inherits this process's environment (e.g. ANTHROPIC_API_KEY).
	LLMPlugin string
	// Metrics enables in-process metrics collection (internal/obs). When false
	// the App uses the allocation-free no-op Recorder. Defaults to true.
	Metrics bool
	// MetricsAddr, when set, serves /metrics on a separate listener at this
	// address instead of the main one (CONSOLE_METRICS_ADDR).
	MetricsAddr string
	// LogFormat selects the log encoding: "text" (default) or "json"
	// (CONSOLE_LOG_FORMAT). Check with Validate.
	LogFormat string
	// Version is the build version reported by console_build_info. It is set
	// by the caller (not read from the environment); empty becomes "unknown".
	Version string
	// AuthMode is CONSOLE_AUTH: "auto" (default) or "disabled". Check with Validate.
	AuthMode string
	// Tokens are the static API tokens (CONSOLE_{ADMIN,WRITE,READ,EVAL}_TOKENS
	// and _FILE variants). Secret; renders as counts only.
	Tokens Tokens
	// CookieSecure is CONSOLE_COOKIE_SECURE: "auto" (default) or "always".
	// Check with Validate.
	CookieSecure string
	// contains filtered or unexported fields
}

Config is the resolved runtime configuration.

func Default

func Default() Config

Default returns the baseline configuration before env/flag overrides.

func FromEnv

func FromEnv() Config

FromEnv returns the default config with any CONSOLE_* environment overrides applied. Recognized variables:

CONSOLE_ADDR          HTTP listen address (default "127.0.0.1:8080", loopback)
CONSOLE_DB            storage DSN / SQLite path (default "console.db")
CONSOLE_STORE_PLUGIN   path to an out-of-process storage-backend plugin
CONSOLE_NOTIFY_PLUGINS comma/space-separated notifier plugin paths
CONSOLE_STATUS_PLUGINS comma/space-separated status-provider plugin paths
CONSOLE_LLM_PLUGIN     path to an out-of-process LLM provider plugin
CONSOLE_METRICS        "off"/"false"/"0"/"no" disables metrics (default on)
CONSOLE_METRICS_ADDR   serve /metrics on this separate address (default: main listener)
CONSOLE_LOG_FORMAT     "text" (default) or "json"; anything else fails Validate
CONSOLE_AUTH           "auto" (default) or "disabled"; anything else fails Validate
CONSOLE_COOKIE_SECURE  session cookie Secure flag: "auto" (default) or "always"
CONSOLE_{ADMIN,WRITE,READ,EVAL}_TOKENS  comma-separated API tokens per scope
CONSOLE_{...}_TOKENS_FILE  same, one token per line (blank lines and # comments
                       ignored); setting both NAME and NAME_FILE is an error

Provider-specific variables (e.g. ANTHROPIC_API_KEY, CLOUDFLARE_API_TOKEN, CONSOLE_SLACK_WEBHOOK_URL, CONSOLE_MODEL) are read by the relevant plugin, which inherits this process's environment — the host does not consume them.

func (Config) AuthEnabled added in v0.8.0

func (c Config) AuthEnabled() bool

AuthEnabled reports whether authentication is on: CONSOLE_AUTH is not "disabled" and at least one token is configured.

func (Config) Validate added in v0.8.0

func (c Config) Validate() error

Validate reports a configuration error, e.g. an unknown CONSOLE_LOG_FORMAT.

type Tokens added in v0.8.0

type Tokens struct {
	Admin, Write, Read, Eval []string
}

Tokens holds the configured API tokens per scope. The values are secrets: Tokens implements fmt.Stringer, fmt.GoStringer, and slog.LogValuer so that printing or logging a Config (or a Tokens) shows only counts, never values.

func (Tokens) Count added in v0.8.0

func (t Tokens) Count() int

Count returns the total number of configured tokens across all scopes.

func (Tokens) GoString added in v0.8.0

func (t Tokens) GoString() string

GoString makes %#v redact too.

func (Tokens) LogValue added in v0.8.0

func (t Tokens) LogValue() slog.Value

LogValue makes slog render counts only.

func (Tokens) String added in v0.8.0

func (t Tokens) String() string

String reports counts only; token values are never rendered.

Jump to

Keyboard shortcuts

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