config

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIConfig added in v0.2.2

type AIConfig struct {
	// OpenAI API key
	APIKey string `koanf:"api_key"`
	// Model to use for AI SQL generation (default: gpt-4o)
	Model string `koanf:"model"`
	// MaxTokens is the maximum number of tokens to generate (default: 1024)
	MaxTokens int `koanf:"max_tokens"`
	// Temperature controls randomness in generation (0.0-1.0, default: 0.1)
	Temperature float32 `koanf:"temperature"`
	// Enabled indicates whether AI features are enabled
	Enabled bool `koanf:"enabled"`
	// BaseURL for OpenAI API (default: "", which uses the standard OpenAI API endpoint)
	BaseURL string `koanf:"base_url"`
}

AIConfig contains AI service (OpenAI) settings

type AlertsConfig added in v0.6.0

type AlertsConfig struct {
	Enabled            bool          `koanf:"enabled"`
	EvaluationInterval time.Duration `koanf:"evaluation_interval"`
	DefaultLookback    time.Duration `koanf:"default_lookback"`
	HistoryLimit       int           `koanf:"history_limit"`
}

AlertsConfig controls scheduling behaviour for alert rules. SMTP and other delivery settings are stored in the database and managed via Admin UI.

type AuthConfig

type AuthConfig struct {
	AdminEmails           []string      `koanf:"admin_emails"`
	SessionDuration       time.Duration `koanf:"session_duration"`
	MaxConcurrentSessions int           `koanf:"max_concurrent_sessions"`
	APITokenSecret        string        `koanf:"api_token_secret"`
	DefaultTokenExpiry    time.Duration `koanf:"default_token_expiry"`
}

AuthConfig contains authentication settings

type ClickhouseConfig

type ClickhouseConfig struct {
	Host     string `koanf:"host"`
	Port     int    `koanf:"port"`
	Database string `koanf:"database"`
	Username string `koanf:"username"`
	Password string `koanf:"password"`
}

ClickhouseConfig contains Clickhouse database settings

type Config

type Config struct {
	Server       ServerConfig       `koanf:"server"`
	SQLite       SQLiteConfig       `koanf:"sqlite"`
	Clickhouse   ClickhouseConfig   `koanf:"clickhouse"`
	OIDC         OIDCConfig         `koanf:"oidc"`
	Auth         AuthConfig         `koanf:"auth"`
	Logging      LoggingConfig      `koanf:"logging"`
	AI           AIConfig           `koanf:"ai"`
	Alerts       AlertsConfig       `koanf:"alerts"`
	Query        QueryConfig        `koanf:"query"`
	Provisioning ProvisioningConfig `koanf:"provisioning"`
}

Config represents the application configuration

func Load

func Load(path string) (*Config, error)

Load loads the configuration from a file and environment variables. Environment variables with the prefix LOGCHEF_ can override file values. E.g., LOGCHEF_SERVER__PORT will override server.port

func LoadRuntimeConfig added in v0.6.0

func LoadRuntimeConfig(ctx context.Context, staticConfig *Config, store SettingsStore) *Config

LoadRuntimeConfig loads configuration from both static config and database. Database values override static config values for non-essential settings.

type LoggingConfig

type LoggingConfig struct {
	// Level sets the minimum log level (debug, info, warn, error)
	Level string `koanf:"level"`
}

LoggingConfig contains logging settings

type OIDCConfig

type OIDCConfig struct {
	// Provider URL for OIDC discovery
	ProviderURL string `koanf:"provider_url"` // Base URL for OIDC provider discovery
	// Different endpoints for OIDC flow
	AuthURL  string `koanf:"auth_url"`  // URL for browser auth redirects
	TokenURL string `koanf:"token_url"` // URL for token exchange (server-to-server)

	ClientID     string   `koanf:"client_id"`
	ClientSecret string   `koanf:"client_secret"`
	RedirectURL  string   `koanf:"redirect_url"`
	Scopes       []string `koanf:"scopes"`

	CLIClientID string `koanf:"cli_client_id"`
}

OIDCConfig contains OpenID Connect settings

type ProvisionMember added in v1.4.0

type ProvisionMember struct {
	Email string `koanf:"email"`
	// Role is the team-level role: "admin", "editor", or "member".
	Role string `koanf:"role"`
}

ProvisionMember declares a team member by email with a role.

type ProvisionSource added in v1.4.0

type ProvisionSource struct {
	// Name is the unique identifier and display name for this source.
	Name string `koanf:"name"`

	// ClickHouse connection details.
	Host      string `koanf:"host"`
	Username  string `koanf:"username"`
	Password  string `koanf:"password"`
	Database  string `koanf:"database"`
	TableName string `koanf:"table_name"`

	// SecretRef stores the environment variable or file path that provided the password.
	// Used by the export command to generate round-trippable config (passwords are never exported).
	// If set and Password is empty, the value is resolved from the environment at startup.
	SecretRef string `koanf:"secret_ref"`

	Description       string `koanf:"description"`
	TTLDays           int    `koanf:"ttl_days"`
	MetaTSField       string `koanf:"meta_ts_field"`
	MetaSeverityField string `koanf:"meta_severity_field"`
}

ProvisionSource declares a ClickHouse data source.

func (*ProvisionSource) ResolvedPassword added in v1.4.0

func (s *ProvisionSource) ResolvedPassword() string

ResolvedPassword returns the password, resolving from SecretRef env var if needed.

type ProvisionTeam added in v1.4.0

type ProvisionTeam struct {
	// Name is the unique identifier and display name for this team.
	Name        string `koanf:"name"`
	Description string `koanf:"description"`

	// Sources lists source Names that this team should have access to.
	Sources []string `koanf:"sources"`

	// Members declares the team membership with roles.
	Members []ProvisionMember `koanf:"members"`
}

ProvisionTeam declares a team with members and source links.

type ProvisioningConfig added in v1.4.0

type ProvisioningConfig struct {
	// File is an optional path to a separate provisioning.toml file.
	// If relative, resolved against the main config.toml directory.
	// When set, the provisioning config is loaded from this file instead of inline.
	File string `koanf:"file"`

	// ManageSources enables declarative management of ClickHouse data sources.
	// When true, sources listed in Sources are created/updated/adopted and marked managed.
	ManageSources bool `koanf:"manage_sources"`

	// ManageTeams enables declarative management of teams, memberships, and source links.
	// When true, teams listed in Teams are created/updated/adopted and marked managed.
	ManageTeams bool `koanf:"manage_teams"`

	// Prune removes managed resources that are no longer declared in config.
	// WARNING: Pruning a team/source cascades to saved queries and alerts via FK constraints.
	// Default: false (safe mode — orphaned managed resources are logged but not deleted).
	Prune bool `koanf:"prune"`

	// DryRun logs all reconciliation actions without applying them.
	// The transaction is rolled back after computing the diff.
	DryRun bool `koanf:"dry_run"`

	// Sources declares ClickHouse data sources to manage.
	// Each source is identified by its Name (must be unique).
	Sources []ProvisionSource `koanf:"sources"`

	// Teams declares teams with their memberships and source access.
	// Each team is identified by its Name (must be unique).
	Teams []ProvisionTeam `koanf:"teams"`
}

ProvisioningConfig declares the desired state for teams, sources, and access control. When absent from config.toml, provisioning is disabled and Logchef operates in UI-only mode.

func (*ProvisioningConfig) Enabled added in v1.4.0

func (c *ProvisioningConfig) Enabled() bool

Enabled returns true if any provisioning management is configured.

type QueryConfig added in v1.3.0

type QueryConfig struct {
	// MaxLimit caps any LIMIT clause to prevent excessive result sets (default: 1000000)
	MaxLimit int `koanf:"max_limit"`
}

QueryConfig contains settings for query execution

type SQLiteConfig

type SQLiteConfig struct {
	Path string `koanf:"path"`
}

SQLiteConfig contains SQLite database settings

type ServerConfig

type ServerConfig struct {
	Port              int           `koanf:"port"`
	Host              string        `koanf:"host"`
	FrontendURL       string        `koanf:"frontend_url"`
	HTTPServerTimeout time.Duration `koanf:"http_server_timeout"`
	// SecureCookie controls the Secure flag on auth cookies.
	// Set to false for local development over HTTP. Defaults to true.
	SecureCookie *bool `koanf:"secure_cookie"`
}

ServerConfig contains HTTP server settings

func (*ServerConfig) IsSecureCookie added in v1.5.0

func (s *ServerConfig) IsSecureCookie() bool

IsSecureCookie returns whether cookies should have the Secure flag set.

type SettingsStore added in v0.6.0

type SettingsStore interface {
	GetSettingWithDefault(ctx context.Context, key, defaultValue string) string
	GetBoolSetting(ctx context.Context, key string, defaultValue bool) bool
	GetIntSetting(ctx context.Context, key string, defaultValue int) int
	GetFloat64Setting(ctx context.Context, key string, defaultValue float64) float64
	GetDurationSetting(ctx context.Context, key string, defaultValue time.Duration) time.Duration
}

SettingsStore defines the interface for retrieving settings from the database.

Jump to

Keyboard shortcuts

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