Documentation
¶
Overview ¶
Package config loads daemon settings from environment variables and flags.
Index ¶
- Constants
- Variables
- func MissingModel(role, provider string) error
- func SplitComposerModel(spec string) (provider, model string, err error)
- func ValidWorkspaceID(id string) bool
- type Config
- func (c *Config) ComposerReady() error
- func (c *Config) DeciderReady() error
- func (c *Config) DeciderSpec() string
- func (c *Config) ListensLocally() bool
- func (c *Config) OTLPHeaderMap() (map[string]string, error)
- func (c *Config) Postgres() bool
- func (c *Config) RedactAddresses() bool
- func (c *Config) SMTPAddr() string
- func (c *Config) SMTPMissing() []string
- func (c *Config) SMTPSecret() (string, error)
- func (c *Config) SecureCookies() bool
- func (c *Config) TrustedProxyPrefixes() ([]netip.Prefix, error)
- func (c *Config) Validate() error
- func (c *Config) ValidateDatabase() error
- type Setting
Constants ¶
const ( SMTPStartTLS = "starttls" // plain connection upgraded with STARTTLS, which the server must offer SMTPImplicit = "implicit" // TLS from the first byte (SMTPS) SMTPNoTLS = "none" // no encryption: only for a mail server on this machine )
SMTP TLS modes, as MAILRULES_SMTP_TLS takes them.
Variables ¶
var ComposerProviders = []string{"anthropic", "openai", "ollama"}
ComposerProviders are the providers the rule composer can write with.
Functions ¶
func MissingModel ¶
MissingModel is the error for a provider spec that names a provider with no default model and no model: role is what the spec is for ("decider", "composer").
func SplitComposerModel ¶
SplitComposerModel reads MAILRULES_COMPOSER_MODEL (the composer_model setting): a bare model name is a Claude model on Anthropic, as it always was; provider:model names the provider (anthropic, openai or ollama), and everything after the first colon is the model, so ollama:llama3.2:3b is the model llama3.2:3b. On error provider and model are still what was written, so a caller can tell a missing model from an unknown provider.
func ValidWorkspaceID ¶
ValidWorkspaceID reports whether id can name an Anthropic workspace: empty (none), or wrkspc_ followed by letters and digits, as the Claude Console shows them. Nothing else may reach the anthropic-workspace-id header.
Types ¶
type Config ¶
type Config struct {
DataDir string
// The hosted build's Postgres (MAI-150); all empty = SQLite in DataDir. DatabaseURL is
// the app role's, WorkerDatabaseURL the worker role's (empty = DatabaseURL), and
// MigrateDatabaseURL the owner's, read by `mailrules migrate` alone. Never logged.
DatabaseURL string
WorkerDatabaseURL string
MigrateDatabaseURL string
Listen string
Mode string
MasterKey string
MasterKeyFile string
// NewMasterKey lets the daemon start although the master key cannot open any stored
// mailbox password or model key; see ext/daemon's openMasterKey.
NewMasterKey bool
// TenantKeyCache is how long a tenant's unwrapped data key stays in memory before the
// key provider is asked for it again (store.Keyring).
TenantKeyCache time.Duration
DryRun bool
Decider string
DeciderModel string
FallbackModel string
ComposerModel string
EscalateBelow float64
MinConfidence float64
BodyChars int
ModelConcurrency int
OpenRouterAPIKey string
CloudflareAccountID string
CloudflareAPIToken string
AnthropicAPIKey string
// AnthropicWorkspaceID names the workspace every Claude request runs in (the
// anthropic-workspace-id header). Only a key that covers a whole organisation needs it;
// empty = none sent.
AnthropicWorkspaceID string
OpenAIBaseURL string
OpenAIAPIKey string
OllamaURL string
PricesFile string
LogLevel string
// LogRedactAddresses is auto, true or false; see RedactAddresses.
LogRedactAddresses string
// CookieSecure is auto, true or false; see SecureCookies.
CookieSecure string
// TrustedProxies lists the reverse proxies whose X-Forwarded-For header is believed,
// as IP addresses or CIDR ranges separated by commas; see TrustedProxyPrefixes.
TrustedProxies string
// The outgoing mail server the summary email is sent through. SMTPPort 0 means the
// usual port for SMTPTLS; SMTPPasswordFile names a file holding the password, like
// MasterKeyFile. Never logged.
SMTPHost string
SMTPPort int
SMTPUser string
SMTPPassword string
SMTPPasswordFile string
SMTPFrom string
SMTPTLS string // starttls | implicit | none (none: localhost only)
// PublicURL is where the web app is reached from the user's mail program: links in the
// summary email start with it.
PublicURL string
// OpenTelemetry export of the metrics and the log (MAI-239): off while OTLPEndpoint is
// empty. OTLPHeaders holds the receiver's key: never logged, never quoted in an error.
OTLPEndpoint string
OTLPHeaders string
OTLPProtocol string
ServiceName string
// Environment names the deployment (staging, production): deployment.environment.name.
Environment string
}
Config holds every setting from the backend plan's Configuration table.
func Load ¶
Load reads settings from the environment, then lets flags in args override them. It does not validate; call Validate before serving.
func (*Config) ComposerReady ¶
ComposerReady is DeciderReady for the rule composer's model.
func (*Config) DeciderReady ¶
DeciderReady reports what the chosen decider still needs before it can run. It is not part of Validate: a fresh install starts without a key so the first-run wizard can collect one, and mail waits for review until then.
func (*Config) DeciderSpec ¶
DeciderSpec is the decider as models.NewRouter takes it: "name" or "name:model".
func (*Config) ListensLocally ¶
ListensLocally reports whether the HTTP address is loopback-only.
func (*Config) OTLPHeaderMap ¶ added in v0.3.0
OTLPHeaderMap reads OTEL_EXPORTER_OTLP_HEADERS as the OpenTelemetry specification writes it: key=value pairs separated by commas, each value percent-decoded, spaces around keys and values ignored. Its error says which pair is wrong by position, never by content.
func (*Config) Postgres ¶ added in v0.3.0
Postgres reports whether the daemon's database is Postgres rather than SQLite in DataDir.
func (*Config) RedactAddresses ¶ added in v0.3.0
RedactAddresses reports whether email addresses are replaced by tags in the log. "auto" means yes in cloud mode, where the log and the error tracker hold other people's addresses, and no when self-hosting, where they help the operator.
func (*Config) SMTPAddr ¶
SMTPAddr is the mail server's host:port, with the usual port for the TLS mode when none is set.
func (*Config) SMTPMissing ¶
SMTPMissing lists the environment variables still to set before the summary email can be sent, in the order to set them; empty when it can be. A user name needs a password and a password a user name.
func (*Config) SMTPSecret ¶
SMTPSecret returns the mail server's password: MAILRULES_SMTP_PASSWORD, or the contents of MAILRULES_SMTP_PASSWORD_FILE without its line ending.
func (*Config) SecureCookies ¶
SecureCookies reports whether login cookies are marked HTTPS-only. "auto" means yes unless the daemon listens on loopback only. Set "false" when the daemon listens on every interface but is only published to this machine over plain HTTP (the Docker Compose setup); set "true" behind a TLS proxy.
func (*Config) TrustedProxyPrefixes ¶ added in v0.1.2
TrustedProxyPrefixes parses MAILRULES_TRUSTED_PROXIES: IP addresses and CIDR ranges separated by commas or spaces. A bare address names just itself. A range that covers every address (/0) is refused: it would let anyone forge X-Forwarded-For.
func (*Config) ValidateDatabase ¶ added in v0.3.0
ValidateDatabase reports what is wrong with the Postgres URLs, never quoting one: they hold passwords.
type Setting ¶ added in v0.1.1
type Setting struct {
Group string // the heading it is listed under
Env string // the environment variable
Flag string // the command-line flag, without the leading --
Default string // the default as the flag package prints it; empty for none
Help string // what it does, for a reader of the reference
}
Setting describes one setting as the settings reference (docs/guide/settings.md) lists it.
Directories
¶
| Path | Synopsis |
|---|---|
|
Command docgen writes the settings reference, docs/guide/settings.md, from the settings internal/config registers, so the page cannot drift from the daemon.
|
Command docgen writes the settings reference, docs/guide/settings.md, from the settings internal/config registers, so the page cannot drift from the daemon. |