479c27e5a8
Phase 2a: userstore domain_admin/superadmin Rollen, User.TenantID,
ListByTenant, UpsertLDAPUser mit tenantID
Phase 2b: storage.Save() mit tenantID *int64, email_refs Tabelle,
GetTenantForMail, GetAllIDsByTenant, StatsByTenant
Phase 2c: JWT-Claims tenant_id/tenant_slug, Session.TenantID,
Login Domain-Erkennung via E-Mail-Domain
Phase 3: tenantMiddleware, Handler-Filterung (Users, Mail, Stats)
Phase 5: SMTP Domain-Routing via DomainToTenantFunc Callback,
config smtp.tenant_routing + default_tenant_id
Phase 8: archivmail migrate-tenants Subkommando
PROJ-2: Upload-Seite /admin/upload mit DropZone + Progress-Polling
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
103 lines
2.9 KiB
Go
103 lines
2.9 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// APIConfig holds configuration for the HTTP API server.
|
|
type APIConfig struct {
|
|
Bind string `yaml:"bind"`
|
|
Secret string `yaml:"secret"`
|
|
}
|
|
|
|
// Config is the full application configuration loaded from YAML.
|
|
type Config struct {
|
|
Server ServerConfig `yaml:"server"`
|
|
Storage StorageConfig `yaml:"storage"`
|
|
Database DatabaseConfig `yaml:"database"`
|
|
SMTP SMTPConfig `yaml:"smtp"`
|
|
API APIConfig `yaml:"api"`
|
|
Index IndexConfig `yaml:"index"`
|
|
Audit AuditConfig `yaml:"audit"`
|
|
Logging LoggingConfig `yaml:"logging"`
|
|
}
|
|
|
|
// ServerConfig holds port settings for the main services.
|
|
type ServerConfig struct {
|
|
APIPort int `yaml:"api_port"`
|
|
SMTPPort int `yaml:"smtp_port"`
|
|
}
|
|
|
|
// StorageConfig holds file system paths for email storage.
|
|
type StorageConfig struct {
|
|
StorePath string `yaml:"store_path"`
|
|
AStorePath string `yaml:"astore_path"`
|
|
XapianPath string `yaml:"xapian_path"`
|
|
Keyfile string `yaml:"keyfile"`
|
|
}
|
|
|
|
// DatabaseConfig holds PostgreSQL connection settings.
|
|
type DatabaseConfig struct {
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
Name string `yaml:"name"`
|
|
User string `yaml:"user"`
|
|
Password string `yaml:"password"`
|
|
SSLMode string `yaml:"sslmode"`
|
|
}
|
|
|
|
// DSN builds a PostgreSQL connection string from the config fields.
|
|
func (d DatabaseConfig) DSN() string {
|
|
return fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s",
|
|
d.User, d.Password, d.Host, d.Port, d.Name, d.SSLMode)
|
|
}
|
|
|
|
// SMTPConfig holds settings for the embedded SMTP server.
|
|
type SMTPConfig struct {
|
|
Enabled bool `yaml:"enabled"`
|
|
Bind string `yaml:"bind"`
|
|
Domain string `yaml:"domain"`
|
|
TLSCert string `yaml:"tls_cert"`
|
|
TLSKey string `yaml:"tls_key"`
|
|
MaxSizeMB int `yaml:"max_size_mb"`
|
|
AllowedIPs []string `yaml:"allowed_ips"`
|
|
TenantRouting string `yaml:"tenant_routing"` // "domain" or "default"
|
|
DefaultTenantID int64 `yaml:"default_tenant_id"` // used when routing is "default" or domain lookup fails
|
|
}
|
|
|
|
// IndexConfig holds full-text index settings.
|
|
type IndexConfig struct {
|
|
Path string `yaml:"path"`
|
|
Backend string `yaml:"backend"`
|
|
BatchSize int `yaml:"batch_size"`
|
|
AsyncQueueSize int `yaml:"async_queue_size"`
|
|
}
|
|
|
|
// AuditConfig holds audit log settings.
|
|
type AuditConfig struct {
|
|
LogPath string `yaml:"log_path"`
|
|
RetentionDays int `yaml:"retention_days"`
|
|
}
|
|
|
|
// LoggingConfig holds application logging settings.
|
|
type LoggingConfig struct {
|
|
Path string `yaml:"path"`
|
|
Level string `yaml:"level"`
|
|
}
|
|
|
|
// Load reads a YAML config file from path and returns a parsed Config.
|
|
func Load(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var cfg Config
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
return &cfg, nil
|
|
}
|