mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
a44f0cf959
* fix: redis sentinel secret missing * refactor: use consts for authentication_backend.file.password errs * fix: unit test for new default port * test: cover additional misses * test: fix windows/linux specific test error * test: more windows specific tests * test: remove superfluous url.IsAbs * test: validator 100% coverage
53 lines
2.0 KiB
Go
53 lines
2.0 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'"))
|
|
}
|
|
|
|
switch {
|
|
case configuration.MySQL != nil:
|
|
validateSQLConfiguration(&configuration.MySQL.SQLStorageConfiguration, validator)
|
|
case configuration.PostgreSQL != nil:
|
|
validatePostgreSQLConfiguration(configuration.PostgreSQL, validator)
|
|
case configuration.Local != nil:
|
|
validateLocalStorageConfiguration(configuration.Local, validator)
|
|
}
|
|
}
|
|
|
|
func validateSQLConfiguration(configuration *schema.SQLStorageConfiguration, validator *schema.StructValidator) {
|
|
if configuration.Password == "" || configuration.Username == "" {
|
|
validator.Push(errors.New("the SQL username and password must be provided"))
|
|
}
|
|
|
|
if configuration.Database == "" {
|
|
validator.Push(errors.New("the SQL database must be provided"))
|
|
}
|
|
}
|
|
|
|
func validatePostgreSQLConfiguration(configuration *schema.PostgreSQLStorageConfiguration, validator *schema.StructValidator) {
|
|
validateSQLConfiguration(&configuration.SQLStorageConfiguration, validator)
|
|
|
|
if configuration.SSLMode == "" {
|
|
configuration.SSLMode = testModeDisabled
|
|
}
|
|
|
|
if !(configuration.SSLMode == testModeDisabled || 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'"))
|
|
}
|
|
}
|