2020-04-23 08:47:27 +07:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
|
|
"github.com/authelia/authelia/internal/utils"
|
|
|
|
)
|
|
|
|
|
2020-04-28 13:39:54 +07:00
|
|
|
// ValidateKeys determines if a provided key is valid.
|
2020-04-23 08:47:27 +07:00
|
|
|
func ValidateKeys(validator *schema.StructValidator, keys []string) {
|
|
|
|
var errStrings []string
|
|
|
|
for _, key := range keys {
|
|
|
|
if utils.IsStringInSlice(key, validKeys) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, err := range errStrings {
|
|
|
|
validator.Push(errors.New(err))
|
|
|
|
}
|
|
|
|
}
|