authelia/internal/configuration/validator/notifier.go
James Elliott cc4f47f21c
fix: removed deprecated smtp/ldap options (#1912)
This removes the deprecated options from 4.25. This includes the LDAP filters which allow {0} or {1} placeholders. The new aliases are documented. Additionally it refactors the keys validator to use uniform messages for most replaced keys.
2021-04-16 11:44:37 +10:00

62 lines
1.7 KiB
Go

package validator
import (
"fmt"
"github.com/authelia/authelia/internal/configuration/schema"
)
// ValidateNotifier validates and update notifier configuration.
func ValidateNotifier(configuration *schema.NotifierConfiguration, validator *schema.StructValidator) {
if configuration.SMTP == nil && configuration.FileSystem == nil ||
configuration.SMTP != nil && configuration.FileSystem != nil {
validator.Push(fmt.Errorf("Notifier should be either `smtp` or `filesystem`"))
return
}
if configuration.FileSystem != nil {
if configuration.FileSystem.Filename == "" {
validator.Push(fmt.Errorf("Filename of filesystem notifier must not be empty"))
}
return
}
validateSMTPNotifier(configuration.SMTP, validator)
}
func validateSMTPNotifier(configuration *schema.SMTPNotifierConfiguration, validator *schema.StructValidator) {
if configuration.StartupCheckAddress == "" {
configuration.StartupCheckAddress = "test@authelia.com"
}
if configuration.Host == "" {
validator.Push(fmt.Errorf("Host of SMTP notifier must be provided"))
}
if configuration.Port == 0 {
validator.Push(fmt.Errorf("Port of SMTP notifier must be provided"))
}
if configuration.Sender == "" {
validator.Push(fmt.Errorf("Sender of SMTP notifier must be provided"))
}
if configuration.Subject == "" {
configuration.Subject = schema.DefaultSMTPNotifierConfiguration.Subject
}
if configuration.Identifier == "" {
configuration.Identifier = schema.DefaultSMTPNotifierConfiguration.Identifier
}
if configuration.TLS == nil {
configuration.TLS = schema.DefaultSMTPNotifierConfiguration.TLS
}
if configuration.TLS.ServerName == "" {
configuration.TLS.ServerName = configuration.Host
}
}