- Migration v2: INSERT → INSERT OR IGNORE for idempotency - Config: validate server.tls_cert and server.tls_key are non-empty - gRPC: add input validation matching REST handlers - gRPC: add logger to zone/record services, log timestamp parse errors - REST+gRPC: extract SOA defaults into shared db.ApplySOADefaults() - DNS: simplify SOA query condition (remove dead code from precedence bug) - Startup: consolidate shutdown into shutdownAll(), clean up gRPC listener on error path, shut down sibling servers when one fails Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
mcdslconfig "git.wntrmute.dev/kyle/mcdsl/config"
|
|
)
|
|
|
|
// Config is the top-level MCNS configuration.
|
|
type Config struct {
|
|
mcdslconfig.Base
|
|
DNS DNSConfig `toml:"dns"`
|
|
}
|
|
|
|
// DNSConfig holds the DNS server settings.
|
|
type DNSConfig struct {
|
|
ListenAddr string `toml:"listen_addr"`
|
|
Upstreams []string `toml:"upstreams"`
|
|
}
|
|
|
|
// Load reads a TOML config file, applies environment variable overrides
|
|
// (MCNS_ prefix), sets defaults, and validates required fields.
|
|
func Load(path string) (*Config, error) {
|
|
cfg, err := mcdslconfig.Load[Config](path, "MCNS")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Apply DNS defaults.
|
|
if cfg.DNS.ListenAddr == "" {
|
|
cfg.DNS.ListenAddr = ":53"
|
|
}
|
|
if len(cfg.DNS.Upstreams) == 0 {
|
|
cfg.DNS.Upstreams = []string{"1.1.1.1:53", "8.8.8.8:53"}
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
// Validate implements the mcdsl config.Validator interface.
|
|
func (c *Config) Validate() error {
|
|
if c.Database.Path == "" {
|
|
return fmt.Errorf("database.path is required")
|
|
}
|
|
if c.MCIAS.ServerURL == "" {
|
|
return fmt.Errorf("mcias.server_url is required")
|
|
}
|
|
if c.Server.TLSCert == "" {
|
|
return fmt.Errorf("server.tls_cert is required")
|
|
}
|
|
if c.Server.TLSKey == "" {
|
|
return fmt.Errorf("server.tls_key is required")
|
|
}
|
|
return nil
|
|
}
|