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