2020-01-21 20:15:40 +00:00
|
|
|
package validator
|
|
|
|
|
2020-04-05 12:37:21 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2020-01-21 20:15:40 +00:00
|
|
|
|
2020-04-05 12:37:21 +00:00
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
|
|
)
|
2020-01-21 20:15:40 +00:00
|
|
|
|
2020-04-20 21:03:38 +00:00
|
|
|
// ValidateNotifier validates and update notifier configuration.
|
2020-01-21 20:15:40 +00:00
|
|
|
func ValidateNotifier(configuration *schema.NotifierConfiguration, validator *schema.StructValidator) {
|
2021-08-07 03:58:08 +00:00
|
|
|
if configuration.SMTP == nil && configuration.FileSystem == nil {
|
|
|
|
validator.Push(fmt.Errorf(errFmtNotifierNotConfigured))
|
|
|
|
|
|
|
|
return
|
|
|
|
} else if configuration.SMTP != nil && configuration.FileSystem != nil {
|
|
|
|
validator.Push(fmt.Errorf(errFmtNotifierMultipleConfigured))
|
2020-01-21 20:15:40 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if configuration.FileSystem != nil {
|
|
|
|
if configuration.FileSystem.Filename == "" {
|
2021-08-07 03:58:08 +00:00
|
|
|
validator.Push(fmt.Errorf(errFmtNotifierFileSystemFileNameNotConfigured))
|
2020-01-21 20:15:40 +00:00
|
|
|
}
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2020-01-21 20:15:40 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:44:37 +00:00
|
|
|
validateSMTPNotifier(configuration.SMTP, validator)
|
|
|
|
}
|
2020-04-09 00:21:28 +00:00
|
|
|
|
2021-04-16 01:44:37 +00:00
|
|
|
func validateSMTPNotifier(configuration *schema.SMTPNotifierConfiguration, validator *schema.StructValidator) {
|
|
|
|
if configuration.StartupCheckAddress == "" {
|
|
|
|
configuration.StartupCheckAddress = "test@authelia.com"
|
|
|
|
}
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2021-04-16 01:44:37 +00:00
|
|
|
if configuration.Host == "" {
|
2021-08-07 03:58:08 +00:00
|
|
|
validator.Push(fmt.Errorf(errFmtNotifierSMTPNotConfigured, "host"))
|
2021-04-16 01:44:37 +00:00
|
|
|
}
|
2020-11-04 23:22:10 +00:00
|
|
|
|
2021-04-16 01:44:37 +00:00
|
|
|
if configuration.Port == 0 {
|
2021-08-07 03:58:08 +00:00
|
|
|
validator.Push(fmt.Errorf(errFmtNotifierSMTPNotConfigured, "port"))
|
2021-04-16 01:44:37 +00:00
|
|
|
}
|
2021-01-04 10:28:55 +00:00
|
|
|
|
2021-08-10 00:52:41 +00:00
|
|
|
if configuration.Timeout == 0 {
|
|
|
|
configuration.Timeout = schema.DefaultSMTPNotifierConfiguration.Timeout
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:44:37 +00:00
|
|
|
if configuration.Sender == "" {
|
2021-08-07 03:58:08 +00:00
|
|
|
validator.Push(fmt.Errorf(errFmtNotifierSMTPNotConfigured, "sender"))
|
2021-04-16 01:44:37 +00:00
|
|
|
}
|
2021-01-04 10:28:55 +00:00
|
|
|
|
2021-04-16 01:44:37 +00:00
|
|
|
if configuration.Subject == "" {
|
|
|
|
configuration.Subject = schema.DefaultSMTPNotifierConfiguration.Subject
|
|
|
|
}
|
2021-01-04 10:28:55 +00:00
|
|
|
|
2021-04-16 01:44:37 +00:00
|
|
|
if configuration.Identifier == "" {
|
|
|
|
configuration.Identifier = schema.DefaultSMTPNotifierConfiguration.Identifier
|
|
|
|
}
|
2021-01-04 10:28:55 +00:00
|
|
|
|
2021-04-16 01:44:37 +00:00
|
|
|
if configuration.TLS == nil {
|
|
|
|
configuration.TLS = schema.DefaultSMTPNotifierConfiguration.TLS
|
|
|
|
}
|
2021-01-04 10:28:55 +00:00
|
|
|
|
2021-04-16 01:44:37 +00:00
|
|
|
if configuration.TLS.ServerName == "" {
|
|
|
|
configuration.TLS.ServerName = configuration.Host
|
2020-01-21 20:15:40 +00:00
|
|
|
}
|
|
|
|
}
|