config

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxResultRows  = 100000
	DefaultMaxResultBytes = 100 * 1024 * 1024 // 100MB
)

Default query storage limits.

View Source
const (
	DefaultRateLimitEnabled = true
	DefaultRateLimitRPM     = 60
	DefaultRateLimitRPMAnon = 10
	DefaultRateLimitBurst   = 10
)

Default rate limiting settings.

View Source
const DefaultBaseURL = "/app"

DefaultBaseURL is the default base URL path for the frontend.

View Source
const DefaultDemoTargetDB = "demo:demo@localhost/demo"

DefaultDemoTargetDB is the default value for DemoTargetDB.

Variables

View Source
var (
	ErrDSNRequired    = errors.New("DBB_DSN environment variable is required")
	ErrKeyRequired    = errors.New("either DBB_KEY or DBB_KEYFILE must be set")
	ErrInvalidKeySize = errors.New("encryption key must be 32 bytes")
)

Configuration errors.

Functions

func DefaultKeyFilePath

func DefaultKeyFilePath() (string, error)

DefaultKeyFilePath returns the path to the default key file (~/.dbbat/key).

Types

type Config

type Config struct {
	// Proxy listen address.
	ListenPG string `koanf:"listen_pg"`

	// REST API listen address.
	ListenAPI string `koanf:"listen_api"`

	// PostgreSQL DSN for DBBat storage.
	DSN string `koanf:"dsn"`

	// Base64-encoded encryption key (alternative to KeyFile).
	Key string `koanf:"key"`

	// Path to file containing encryption key (alternative to Key).
	KeyFile string `koanf:"keyfile"`

	// ConfigFile path (not loaded from config, set via CLI).
	ConfigFile string `koanf:"-"`

	// Encryption key for database credentials (32 bytes).
	// Populated from Key or KeyFile after loading.
	EncryptionKey []byte `koanf:"-"`

	// RunMode controls whether test data is provisioned on startup.
	RunMode RunMode `koanf:"run_mode"`

	// DemoTargetDB specifies the only allowed database target in demo mode.
	// Format: "user:password@host/dbname" (e.g., "demo:demo@localhost/demo")
	// Only applies when RunMode is "demo". If empty, defaults to "demo:demo@localhost/demo".
	DemoTargetDB string `koanf:"demo_target_db"`

	// QueryStorage holds query result storage configuration.
	QueryStorage QueryStorageConfig `koanf:"query_storage"`

	// RateLimit holds rate limiting configuration.
	RateLimit RateLimitConfig `koanf:"rate_limit"`

	// BaseURL is the base URL path for the frontend app (default: "/app").
	BaseURL string `koanf:"base_url"`

	// Redirects contains dev redirect rules parsed from DBB_REDIRECTS env var.
	// Not loaded from config file, parsed from environment only.
	Redirects []RedirectRule `koanf:"-"`
}

Config holds the application configuration.

func Load

func Load(opts LoadOptions, cliOverrides ...func(*Config)) (*Config, error)

Load reads configuration from environment variables and optional config file. Priority order: CLI overrides > Environment variables > Config file > Defaults

func (*Config) GetDemoTarget

func (c *Config) GetDemoTarget() *DemoTarget

GetDemoTarget parses and returns the demo target configuration. Returns nil if not in demo mode.

func (*Config) IsDemoMode

func (c *Config) IsDemoMode() bool

IsDemoMode returns true if running in demo mode.

func (*Config) ValidateDemoTarget

func (c *Config) ValidateDemoTarget(username, password, host, database string) string

ValidateDemoTarget checks if the given credentials match the demo target. Returns an error message if validation fails, or empty string if valid.

type DemoTarget

type DemoTarget struct {
	Username string
	Password string
	Host     string
	Database string
}

DemoTarget holds the parsed demo target database credentials.

func ParseDemoTargetDB

func ParseDemoTargetDB(s string) *DemoTarget

ParseDemoTargetDB parses a demo target string in format "user:pass@host/dbname".

type LoadOptions

type LoadOptions struct {
	// ConfigFile is the path to a config file (YAML, JSON, or TOML).
	ConfigFile string
}

LoadOptions configures how configuration is loaded.

type QueryStorageConfig

type QueryStorageConfig struct {
	// MaxResultRows is the maximum number of rows to store per query.
	MaxResultRows int `koanf:"max_result_rows"`

	// MaxResultBytes is the maximum total bytes to store per query.
	MaxResultBytes int64 `koanf:"max_result_bytes"`

	// StoreResults enables/disables result storage globally.
	StoreResults bool `koanf:"store_results"`
}

QueryStorageConfig holds configuration for query result storage.

type RateLimitConfig

type RateLimitConfig struct {
	// Enabled enables/disables rate limiting.
	Enabled bool `koanf:"enabled"`

	// RequestsPerMinute is the rate limit for authenticated users.
	RequestsPerMinute int `koanf:"requests_per_minute"`

	// RequestsPerMinuteAnon is the rate limit for unauthenticated requests (by IP).
	RequestsPerMinuteAnon int `koanf:"requests_per_minute_anon"`

	// Burst allows short bursts above the rate limit.
	Burst int `koanf:"burst"`
}

RateLimitConfig holds configuration for API rate limiting.

type RedirectRule

type RedirectRule struct {
	// PathPrefix is the path prefix to match (e.g., "/app").
	PathPrefix string
	// TargetHost is the target host to proxy to (e.g., "localhost:5173").
	TargetHost string
	// TargetPath is the path on the target (e.g., "/").
	TargetPath string
}

RedirectRule represents a path-based redirect for development proxying.

type RunMode

type RunMode string

RunMode represents the application run mode.

const (
	// RunModeDefault is the default production mode.
	RunModeDefault RunMode = ""
	// RunModeTest provisions test data on startup.
	RunModeTest RunMode = "test"
	// RunModeDemo provisions demo data on startup with additional protections.
	RunModeDemo RunMode = "demo"
)

Jump to

Keyboard shortcuts

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