2020-04-23 01:47:27 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
|
|
"github.com/authelia/authelia/internal/utils"
|
|
|
|
)
|
|
|
|
|
2020-04-28 06:39:54 +00:00
|
|
|
// ValidateKeys determines if a provided key is valid.
|
2020-04-23 01:47:27 +00:00
|
|
|
func ValidateKeys(validator *schema.StructValidator, keys []string) {
|
|
|
|
var errStrings []string
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2020-04-23 01:47:27 +00:00
|
|
|
for _, key := range keys {
|
|
|
|
if utils.IsStringInSlice(key, validKeys) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-03-22 09:04:09 +00:00
|
|
|
if isSecretKey(key) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:44:37 +00:00
|
|
|
if newKey, ok := replacedKeys[key]; ok {
|
|
|
|
validator.Push(fmt.Errorf(errFmtReplacedConfigurationKey, key, newKey))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-04-23 01:47:27 +00:00
|
|
|
if err, ok := specificErrorKeys[key]; ok {
|
|
|
|
if !utils.IsStringInSlice(err, errStrings) {
|
|
|
|
errStrings = append(errStrings, err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
validator.Push(fmt.Errorf("config key not expected: %s", key))
|
|
|
|
}
|
|
|
|
}
|
2020-05-05 19:35:32 +00:00
|
|
|
|
2020-04-23 01:47:27 +00:00
|
|
|
for _, err := range errStrings {
|
|
|
|
validator.Push(errors.New(err))
|
|
|
|
}
|
|
|
|
}
|