mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
b9fb33d806
* [FEATURE] File Secret Loading * add a validator for secrets * run the secrets validator before the main config validator * only allow a secret to be defined in one of: config, env, file env * remove LF if found in file * update configuration before main config validation * fix unit tests * implement secret testing * refactor the secrets validator * make check os agnostic * update docs * add warning when user attempts to use ENV instead of ENV file * discourage ENV in docs * update config template * oxford comma * apply suggestions from code review * rename Validate to ValidateConfiguration * add k8s example * add deprecation notice in docs and warning * style changes
52 lines
1.9 KiB
Go
52 lines
1.9 KiB
Go
package validator
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
)
|
|
|
|
// ValidateStorage validates storage configuration.
|
|
func ValidateStorage(configuration schema.StorageConfiguration, validator *schema.StructValidator) {
|
|
if configuration.Local == nil && configuration.MySQL == nil && configuration.PostgreSQL == nil {
|
|
validator.Push(errors.New("A storage configuration must be provided. It could be 'local', 'mysql' or 'postgres'"))
|
|
}
|
|
|
|
if configuration.MySQL != nil {
|
|
validateSQLConfiguration(&configuration.MySQL.SQLStorageConfiguration, validator)
|
|
} else if configuration.PostgreSQL != nil {
|
|
validatePostgreSQLConfiguration(configuration.PostgreSQL, validator)
|
|
} else if configuration.Local != nil {
|
|
validateLocalStorageConfiguration(configuration.Local, validator)
|
|
}
|
|
}
|
|
|
|
func validateSQLConfiguration(configuration *schema.SQLStorageConfiguration, validator *schema.StructValidator) {
|
|
if configuration.Password == "" || configuration.Username == "" {
|
|
validator.Push(errors.New("Username and password must be provided"))
|
|
}
|
|
|
|
if configuration.Database == "" {
|
|
validator.Push(errors.New("A database must be provided"))
|
|
}
|
|
}
|
|
|
|
func validatePostgreSQLConfiguration(configuration *schema.PostgreSQLStorageConfiguration, validator *schema.StructValidator) {
|
|
validateSQLConfiguration(&configuration.SQLStorageConfiguration, validator)
|
|
|
|
if configuration.SSLMode == "" {
|
|
configuration.SSLMode = "disable"
|
|
}
|
|
|
|
if !(configuration.SSLMode == "disable" || configuration.SSLMode == "require" ||
|
|
configuration.SSLMode == "verify-ca" || configuration.SSLMode == "verify-full") {
|
|
validator.Push(errors.New("SSL mode must be 'disable', 'require', 'verify-ca', or 'verify-full'"))
|
|
}
|
|
}
|
|
|
|
func validateLocalStorageConfiguration(configuration *schema.LocalStorageConfiguration, validator *schema.StructValidator) {
|
|
if configuration.Path == "" {
|
|
validator.Push(errors.New("A file path must be provided with key 'path'"))
|
|
}
|
|
}
|