feat: validate configuration on startup, fail fast on bad config (closes #52) #53
@@ -262,15 +262,16 @@ func (c *Config) ensureStateDirWritable() error {
|
||||
// validate checks that all required configuration values are set and
|
||||
// that every value is within its valid range.
|
||||
func (c *Config) validate() error {
|
||||
// The signing key value is never echoed in error messages.
|
||||
if c.SigningKey == "" {
|
||||
return fmt.Errorf("signing_key is required")
|
||||
return fmt.Errorf("config key %q: a value is required", "signing_key")
|
||||
}
|
||||
|
||||
// Minimum key length for security (32 bytes = 256 bits)
|
||||
const minKeyLength = 32
|
||||
if len(c.SigningKey) < minKeyLength {
|
||||
return fmt.Errorf("signing_key must be at least %d characters, got %d",
|
||||
minKeyLength, len(c.SigningKey))
|
||||
return fmt.Errorf("config key %q: value must be at least %d characters, got %d",
|
||||
"signing_key", minKeyLength, len(c.SigningKey))
|
||||
}
|
||||
|
||||
const maxPort = 65535
|
||||
|
||||
Reference in New Issue
Block a user