config

package
v1.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package config loads ReputeCast configuration from defaults, an optional YAML file, REPUTECAST_* environment variables and command-line flags, in that order of precedence (later wins).

Index

Constants

View Source
const (
	RoleWeb    = "web"
	RoleWorker = "worker"
	RoleIngest = "ingest"
)

Role names for --role. The default runs all of them in one process.

View Source
const EnvPrefix = "REPUTECAST_"

EnvPrefix is the prefix of every environment variable ReputeCast reads. REPUTECAST_HTTP__ADDR maps to http.addr: a double underscore separates levels so that single underscores can stay inside key names.

View Source
const MetricsDefaultAddr = ":9464"

MetricsDefaultAddr is where /metrics listens unless configured otherwise (the Prometheus exporter default for applications).

Variables

This section is empty.

Functions

func DecodeKey

func DecodeKey(s string) ([]byte, error)

DecodeKey decodes a base64 (standard or URL) 32-byte key.

Types

type AuthConfig

type AuthConfig struct {
	SessionLifetime   time.Duration `koanf:"session_lifetime"`
	SessionIdle       time.Duration `koanf:"session_idle"`
	CookieName        string        `koanf:"cookie_name"`
	CookieSecure      bool          `koanf:"cookie_secure"`
	BreachedCheck     bool          `koanf:"breached_check"`
	PasswordMinLength int           `koanf:"password_min_length"`
}

AuthConfig holds sign-in defaults. Instance admins can change most of these at runtime in Instance admin › Authentication; these are the bootstrap values.

type Config

type Config struct {
	Env        string           `koanf:"env"`
	Roles      []string         `koanf:"roles"`
	HTTP       HTTPConfig       `koanf:"http"`
	Database   DatabaseConfig   `koanf:"database"`
	Secrets    SecretsConfig    `koanf:"secrets"`
	Log        LogConfig        `koanf:"log"`
	Auth       AuthConfig       `koanf:"auth"`
	Worker     WorkerConfig     `koanf:"worker"`
	Updates    UpdatesConfig    `koanf:"updates"`
	Metrics    MetricsConfig    `koanf:"metrics"`
	Webhooks   WebhooksConfig   `koanf:"webhooks"`
	Providers  ProvidersConfig  `koanf:"providers"`
	HostRepute HostReputeConfig `koanf:"hostrepute"`
	DNS        DNSConfig        `koanf:"dns"`
	Mail       MailConfig       `koanf:"mail"`
	Connect    ConnectConfig    `koanf:"connect"`
	I18n       I18nConfig       `koanf:"i18n"`
	Files      FilesConfig      `koanf:"files"`
	GeoIP      GeoIPConfig      `koanf:"geoip"`
}

Config is the full runtime configuration.

func Defaults

func Defaults() Config

Defaults returns the configuration used when nothing else is set.

func Load

func Load(configFile string, flags *pflag.FlagSet) (*Config, error)

Load builds the configuration. configFile may be empty; flags may be nil.

func (*Config) FilesDir

func (c *Config) FilesDir() string

FilesDir is the folder uploaded files are kept in.

func (*Config) HasRole

func (c *Config) HasRole(role string) bool

HasRole reports whether this process runs the given role.

func (*Config) IsDevelopment

func (c *Config) IsDevelopment() bool

IsDevelopment reports whether the instance runs in development mode.

func (*Config) PseudoLocale

func (c *Config) PseudoLocale() bool

PseudoLocale reports whether members can pick the pseudo-locale: always in development, elsewhere when i18n.pseudo_locale is on.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the configuration for mistakes that would otherwise fail late.

type ConnectConfig

type ConnectConfig struct {
	// SESTemplateURL is the published CloudFormation template the "Launch
	// stack in AWS" link opens. AWS reads quick-create templates from S3, so
	// instances that publish their own copy point this at it.
	SESTemplateURL string `koanf:"ses_template_url"`
}

ConnectConfig configures "Connect a sending provider".

type DNSConfig

type DNSConfig struct {
	Servers []string      `koanf:"servers"`
	Timeout time.Duration `koanf:"timeout"`
}

DNSConfig configures the resolvers used for authentication checks and blocklist lookups. Empty uses the system resolvers; DNSBLs such as Spamhaus refuse queries that come through public resolvers.

type DatabaseConfig

type DatabaseConfig struct {
	URL      string `koanf:"url"`
	MaxConns int32  `koanf:"max_conns"`
	// SegmentRole is the SELECT-only role user-written SQL segments run as.
	SegmentRole string `koanf:"segment_role"`
}

DatabaseConfig configures Postgres.

type FilesConfig

type FilesConfig struct {
	// Dir defaults to a "files" folder next to the secret key file (the
	// data volume, /var/lib/reputecast, in the container image).
	Dir string `koanf:"dir"`
}

FilesConfig is where uploaded files live: digital products' files and lead magnets (design expansion phase 7). They can be large, so they stay out of the database. When the process is split with --role, every web and worker process needs the same folder.

type GeoIPConfig

type GeoIPConfig struct {
	Database string `koanf:"database"`
}

GeoIPConfig is the operator's MaxMind DB file (GeoLite2-City/Country, DB-IP Lite City/Country) that places readers' opens and clicks in the campaign report. Empty is off. ReputeCast never downloads it: replace the file and restart to update it.

type HTTPConfig

type HTTPConfig struct {
	Addr string `koanf:"addr"`
	// PublicURL is the externally reachable base URL. It is used for provider
	// webhooks, SSO redirects, passkeys (relying party) and public pages.
	PublicURL string `koanf:"public_url"`
	// PublicURLLocked pins the public URL to PublicURL: an address saved in
	// Instance admin is ignored and can't be changed there. For an operator
	// who runs the instance for someone else and owns its DNS and TLS
	// (REPUTECAST_HTTP__PUBLIC_URL_LOCKED).
	PublicURLLocked bool `koanf:"public_url_locked"`
	// TrustedProxies lists CIDRs whose X-Forwarded-For header is trusted.
	TrustedProxies []string `koanf:"trusted_proxies"`
	// RateLimitAuth and RateLimitAPI are requests per minute: sign-in
	// endpoints per client IP, and the API per key, per signed-in session,
	// or per IP for anonymous calls.
	RateLimitAuth int `koanf:"rate_limit_auth"`
	RateLimitAPI  int `koanf:"rate_limit_api"`
	// RateLimitIP caps, per minute, the API requests of signed-in browsers
	// from one address together: each session has RateLimitAPI, and an
	// office behind one NAT shares this (review 2026-11 OP-6).
	RateLimitIP     int           `koanf:"rate_limit_ip"`
	ReadTimeout     time.Duration `koanf:"read_timeout"`
	WriteTimeout    time.Duration `koanf:"write_timeout"`
	ShutdownTimeout time.Duration `koanf:"shutdown_timeout"`
}

HTTPConfig configures the HTTP listener.

type HostReputeConfig

type HostReputeConfig struct {
	APIURL       string `koanf:"api_url"`
	AuthURL      string `koanf:"auth_url"`
	TokenURL     string `koanf:"token_url"`
	RevokeURL    string `koanf:"revoke_url"`
	ClientID     string `koanf:"client_id"`
	ClientSecret string `koanf:"client_secret"`
	// Demo serves a built-in, offline HostRepute (sample data, instant OAuth
	// approval) for development and screenshots.
	Demo bool `koanf:"demo"`
}

HostReputeConfig configures the optional HostRepute integration. ReputeCast is a public OAuth client of HostRepute (PKCE, no secret); instances that registered their own client can set its id and secret.

type I18nConfig

type I18nConfig struct {
	// PseudoLocale offers "Pseudo (+40%)" in Language & region outside
	// development, to check layouts on a staging instance: every string
	// accented, about 40% longer and wrapped in ⟦ ⟧.
	PseudoLocale bool `koanf:"pseudo_locale"`
}

I18nConfig configures the app languages.

type LogConfig

type LogConfig struct {
	Level  string `koanf:"level"`
	Format string `koanf:"format"` // "text" or "json"
}

LogConfig configures log/slog.

type MailConfig

type MailConfig struct {
	// DevSMTP is where, in development only, mail for the demo's sample
	// providers is delivered instead of a real provider (Mailpit).
	DevSMTP string `koanf:"dev_smtp"`
}

MailConfig configures system mail (password resets, invitations, notifications), which goes out through the System stream's provider.

type MetricsConfig

type MetricsConfig struct {
	Enabled bool   `koanf:"enabled"`
	Addr    string `koanf:"addr"`  // the metrics listener; empty serves none
	Token   string `koanf:"token"` // lets the main listener serve /metrics; never logged
}

MetricsConfig configures the Prometheus endpoint. By default /metrics is served on its own listener (Addr, ":9464"), which a reverse proxy never exposes. The main listener answers /metrics only to a request carrying Token as a bearer token; without a token it answers 404 there.

type ProvidersConfig

type ProvidersConfig struct {
	// AllowPrivateNetworks lets provider URLs a workspace enters resolve to
	// loopback and private (RFC 1918) addresses. Off by default so workspace
	// admins can't reach internal services (SSRF); link-local and cloud
	// metadata addresses are always blocked. It also decides whether a
	// community adapter's process may listen on such an address (a sidecar);
	// plain http:// only reaches those.
	AllowPrivateNetworks bool `koanf:"allow_private_networks"`
}

ProvidersConfig configures calls to sending-provider APIs.

type SecretsConfig

type SecretsConfig struct {
	// Key is a base64-encoded 32-byte key. Rotate by moving the current key
	// to PreviousKeys and setting a new Key.
	Key          string   `koanf:"key"`
	PreviousKeys []string `koanf:"previous_keys"`
	// KeyFile is used when Key is empty. The file is created with a fresh
	// key on first start, so a one-command install works without extra setup.
	KeyFile string `koanf:"key_file"`
}

SecretsConfig holds the master key used to encrypt provider credentials, OIDC client secrets and other secrets at rest.

type UpdatesConfig

type UpdatesConfig struct {
	Check bool   `koanf:"check"`
	Repo  string `koanf:"repo"`
	// ManagedBy names who upgrades this instance when the server's operator
	// does (a hosting company, an IT team). Version & updates then says so
	// instead of showing the docker compose upgrade command.
	ManagedBy string `koanf:"managed_by"`
}

UpdatesConfig configures the release check against GitHub.

type WebhooksConfig

type WebhooksConfig struct {
	// AllowPrivateNetworks lets endpoints resolve to loopback and private
	// (RFC 1918) addresses, for receivers on the same network. Off by
	// default: user-supplied URLs must not reach internal services (SSRF).
	// Link-local and cloud metadata addresses are always blocked.
	AllowPrivateNetworks bool `koanf:"allow_private_networks"`
}

WebhooksConfig configures outgoing webhooks and the audit stream.

type WorkerConfig

type WorkerConfig struct {
	Concurrency int `koanf:"concurrency"`
}

WorkerConfig configures background jobs.

Jump to

Keyboard shortcuts

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