config

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 (
	StorageLocal = "local"
	StorageS3    = "s3"
)

Storage backends.

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

View Source
var PrivateNetworks = []netip.Prefix{
	netip.MustParsePrefix("10.0.0.0/8"),
	netip.MustParsePrefix("172.16.0.0/12"),
	netip.MustParsePrefix("192.168.0.0/16"),
	netip.MustParsePrefix("100.64.0.0/10"),
	netip.MustParsePrefix("127.0.0.0/8"),
	netip.MustParsePrefix("fc00::/7"),
	netip.MustParsePrefix("::1/128"),
}

PrivateNetworks is what the trusted-proxy keyword "private" stands for: RFC 1918, shared address space (RFC 6598), loopback and IPv6 unique local and loopback addresses.

Functions

func DecodeKey

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

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

func ParseTrustedProxies

func ParseTrustedProxies(list []string) (nets []netip.Prefix, invalid []string)

ParseTrustedProxies reads http.trusted_proxies: CIDRs, single addresses and the keyword "private". It returns the networks and the entries that are none of those.

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"`
	Storage    StorageConfig    `koanf:"storage"`
	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 the local files folder: with storage.backend "local" (the default) every file ReputeCast keeps outside the database lives there (digital products' files, lead magnets, chunked uploads, audience exports). When the process is split with --role, every web and worker process needs the same folder, so a split install uses storage.backend "s3" instead.

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 and answers signup forms' country rules. 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 or addresses whose X-Forwarded-For header
	// is trusted. The keyword "private" stands for every private, shared
	// (carrier-grade NAT) and loopback network: the router in front of a
	// platform such as Render, Railway or Kubernetes (PrivateNetworks).
	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 S3Config

type S3Config struct {
	Bucket string `koanf:"bucket"`
	Region string `koanf:"region"`
	// Endpoint is the service's URL for a provider other than AWS
	// (https://nyc3.digitaloceanspaces.com, http://minio:9000); empty is AWS.
	Endpoint string `koanf:"endpoint"`
	// PathStyle addresses the bucket in the path (MinIO and most
	// self-hosted services) instead of the host name.
	PathStyle bool `koanf:"path_style"`
	// Prefix is prepended to every key ("reputecast/"), to share a bucket.
	Prefix          string `koanf:"prefix"`
	AccessKeyID     string `koanf:"access_key_id"`
	SecretAccessKey string `koanf:"secret_access_key"`
	// SSE is server-side encryption: "" (the bucket's default), "AES256" or
	// "aws:kms" (with KMSKeyID, else the account's default key).
	SSE      string `koanf:"sse"`
	KMSKeyID string `koanf:"kms_key_id"`
}

S3Config is an S3-compatible bucket (AWS S3, MinIO, Cloudflare R2, DigitalOcean Spaces, Backblaze B2, Wasabi…). Without an access key the default AWS credential chain is used (environment, shared files, IAM role, IRSA).

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 StorageConfig

type StorageConfig struct {
	// Backend is "local" (default) or "s3".
	Backend string   `koanf:"backend"`
	S3      S3Config `koanf:"s3"`
}

StorageConfig chooses where files kept outside the database live: the local files folder (files.dir) or an S3-compatible bucket, so several web and worker replicas share them without a ReadWriteMany volume.

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