2020-01-22 03:15:40 +07:00
|
|
|
package validator
|
|
|
|
|
2020-04-05 19:37:21 +07:00
|
|
|
import (
|
|
|
|
"fmt"
|
2020-01-22 03:15:40 +07:00
|
|
|
|
2021-08-11 08:04:35 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
2020-04-05 19:37:21 +07:00
|
|
|
)
|
2020-01-22 03:15:40 +07:00
|
|
|
|
2020-04-21 04:03:38 +07:00
|
|
|
// ValidateNotifier validates and update notifier configuration.
|
2020-01-22 03:15:40 +07:00
|
|
|
func ValidateNotifier(configuration *schema.NotifierConfiguration, validator *schema.StructValidator) {
|
2021-08-07 10:58:08 +07: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-22 03:15:40 +07:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if configuration.FileSystem != nil {
|
|
|
|
if configuration.FileSystem.Filename == "" {
|
2021-08-07 10:58:08 +07:00
|
|
|
validator.Push(fmt.Errorf(errFmtNotifierFileSystemFileNameNotConfigured))
|
2020-01-22 03:15:40 +07:00
|
|
|
}
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2020-01-22 03:15:40 +07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-16 08:44:37 +07:00
|
|
|
validateSMTPNotifier(configuration.SMTP, validator)
|
|
|
|
}
|
2020-04-09 07:21:28 +07:00
|
|
|
|
2021-04-16 08:44:37 +07:00
|
|
|
func validateSMTPNotifier(configuration *schema.SMTPNotifierConfiguration, validator *schema.StructValidator) {
|
|
|
|
if configuration.StartupCheckAddress == "" {
|
2021-11-30 18:15:21 +07:00
|
|
|
configuration.StartupCheckAddress = schema.DefaultSMTPNotifierConfiguration.StartupCheckAddress
|
2021-04-16 08:44:37 +07:00
|
|
|
}
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2021-04-16 08:44:37 +07:00
|
|
|
if configuration.Host == "" {
|
2021-08-07 10:58:08 +07:00
|
|
|
validator.Push(fmt.Errorf(errFmtNotifierSMTPNotConfigured, "host"))
|
2021-04-16 08:44:37 +07:00
|
|
|
}
|
2020-11-05 06:22:10 +07:00
|
|
|
|
2021-04-16 08:44:37 +07:00
|
|
|
if configuration.Port == 0 {
|
2021-08-07 10:58:08 +07:00
|
|
|
validator.Push(fmt.Errorf(errFmtNotifierSMTPNotConfigured, "port"))
|
2021-04-16 08:44:37 +07:00
|
|
|
}
|
2021-01-04 17:28:55 +07:00
|
|
|
|
2021-08-10 07:52:41 +07:00
|
|
|
if configuration.Timeout == 0 {
|
|
|
|
configuration.Timeout = schema.DefaultSMTPNotifierConfiguration.Timeout
|
|
|
|
}
|
|
|
|
|
2021-11-30 18:15:21 +07:00
|
|
|
if configuration.Sender.Address == "" {
|
2021-08-07 10:58:08 +07:00
|
|
|
validator.Push(fmt.Errorf(errFmtNotifierSMTPNotConfigured, "sender"))
|
2021-04-16 08:44:37 +07:00
|
|
|
}
|
2021-01-04 17:28:55 +07:00
|
|
|
|
2021-04-16 08:44:37 +07:00
|
|
|
if configuration.Subject == "" {
|
|
|
|
configuration.Subject = schema.DefaultSMTPNotifierConfiguration.Subject
|
|
|
|
}
|
2021-01-04 17:28:55 +07:00
|
|
|
|
2021-04-16 08:44:37 +07:00
|
|
|
if configuration.Identifier == "" {
|
|
|
|
configuration.Identifier = schema.DefaultSMTPNotifierConfiguration.Identifier
|
|
|
|
}
|
2021-01-04 17:28:55 +07:00
|
|
|
|
2021-04-16 08:44:37 +07:00
|
|
|
if configuration.TLS == nil {
|
|
|
|
configuration.TLS = schema.DefaultSMTPNotifierConfiguration.TLS
|
|
|
|
}
|
2021-01-04 17:28:55 +07:00
|
|
|
|
2021-04-16 08:44:37 +07:00
|
|
|
if configuration.TLS.ServerName == "" {
|
|
|
|
configuration.TLS.ServerName = configuration.Host
|
2020-01-22 03:15:40 +07:00
|
|
|
}
|
|
|
|
}
|