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>
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package configuration
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"strings"
|
|
|
|
"github.com/authelia/authelia/internal/utils"
|
|
)
|
|
|
|
func getEnvConfigMap(keys []string, prefix, delimiter string) (keyMap map[string]string, ignoredKeys []string) {
|
|
keyMap = make(map[string]string)
|
|
|
|
for _, key := range keys {
|
|
if strings.Contains(key, delimiter) {
|
|
originalKey := prefix + strings.ToUpper(strings.ReplaceAll(key, constDelimiter, delimiter))
|
|
keyMap[originalKey] = key
|
|
}
|
|
|
|
// Secret envs should be ignored by the env parser.
|
|
if isSecretKey(key) {
|
|
originalKey := strings.ToUpper(strings.ReplaceAll(key, constDelimiter, delimiter)) + constSecretSuffix
|
|
|
|
ignoredKeys = append(ignoredKeys, prefix+originalKey)
|
|
}
|
|
}
|
|
|
|
return keyMap, ignoredKeys
|
|
}
|
|
|
|
func getSecretConfigMap(keys []string, prefix, delimiter string) (keyMap map[string]string) {
|
|
keyMap = make(map[string]string)
|
|
|
|
for _, key := range keys {
|
|
if isSecretKey(key) {
|
|
originalKey := strings.ToUpper(strings.ReplaceAll(key, constDelimiter, delimiter)) + constSecretSuffix
|
|
|
|
keyMap[prefix+originalKey] = key
|
|
}
|
|
}
|
|
|
|
return keyMap
|
|
}
|
|
|
|
func isSecretKey(key string) (isSecretKey bool) {
|
|
return utils.IsStringInSliceSuffix(key, secretSuffixes)
|
|
}
|
|
|
|
func loadSecret(path string) (value string, err error) {
|
|
content, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return strings.TrimRight(string(content), "\n"), err
|
|
}
|