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-04-16 08:44:37 +07:00
|
|
|
if configuration.SMTP == nil && configuration.FileSystem == nil ||
|
|
|
|
configuration.SMTP != nil && configuration.FileSystem != nil {
|
2020-01-22 03:15:40 +07:00
|
|
|
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"))
|
|
|
|
}
|
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 == "" {
|
|
|
|
validator.Push(fmt.Errorf("Host of SMTP notifier must be provided"))
|
|
|
|
}
|
2020-11-05 06:22:10 +07:00
|
|
|
|
2021-04-16 08:44:37 +07:00
|
|
|
if configuration.Port == 0 {
|
|
|
|
validator.Push(fmt.Errorf("Port of SMTP notifier must be provided"))
|
|
|
|
}
|
2021-01-04 17:28:55 +07:00
|
|
|
|
2021-04-16 08:44:37 +07:00
|
|
|
if configuration.Sender == "" {
|
|
|
|
validator.Push(fmt.Errorf("Sender of SMTP notifier must be provided"))
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|