mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
a7e867a699
This commit replaces github.com/spf13/viper with github.com/knadh/koanf. Koanf is very similar library to viper, with less dependencies and several quality of life differences. This also allows most config options to be defined by ENV. Lastly it also enables the use of split configuration files which can be configured by setting the --config flag multiple times. Co-authored-by: Amir Zarrinkafsh <nightah@me.com>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package validator
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
"github.com/authelia/authelia/internal/utils"
|
|
)
|
|
|
|
// ValidateKeys determines if all provided keys are valid.
|
|
func ValidateKeys(keys []string, prefix string, validator *schema.StructValidator) {
|
|
var errStrings []string
|
|
|
|
for _, key := range keys {
|
|
expectedKey := reKeyReplacer.ReplaceAllString(key, "[]")
|
|
|
|
if utils.IsStringInSlice(expectedKey, ValidKeys) {
|
|
continue
|
|
}
|
|
|
|
if newKey, ok := replacedKeys[expectedKey]; ok {
|
|
validator.Push(fmt.Errorf(errFmtReplacedConfigurationKey, key, newKey))
|
|
continue
|
|
}
|
|
|
|
if err, ok := specificErrorKeys[expectedKey]; ok {
|
|
if !utils.IsStringInSlice(err, errStrings) {
|
|
errStrings = append(errStrings, err)
|
|
}
|
|
} else {
|
|
if strings.HasPrefix(key, prefix) {
|
|
validator.PushWarning(fmt.Errorf("configuration environment variable not expected: %s", key))
|
|
} else {
|
|
validator.Push(fmt.Errorf("configuration key not expected: %s", key))
|
|
}
|
|
}
|
|
}
|
|
|
|
for _, err := range errStrings {
|
|
validator.Push(errors.New(err))
|
|
}
|
|
}
|