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
|
|
|
|
2020-04-05 19:37:21 +07:00
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
|
|
)
|
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 == "" {
|
|
|
|
configuration.StartupCheckAddress = "test@authelia.com"
|
|
|
|
}
|
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-04-16 08:44:37 +07:00
|
|
|
if configuration.Sender == "" {
|
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
|
|
|
}
|
|
|
|
}
|