diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2022-09-16 14:21:05 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-16 14:21:05 +1000 |
| commit | 9c72bc8977359ef5b79996d2b9bd41882438d11d (patch) | |
| tree | 64eda7f64adc8f36bd2ec7f55f6a70b85702acb9 /internal/configuration/helpers.go | |
| parent | 15110b732a4a24c9bd611477627bdd06291e10b2 (diff) | |
ci: gen github tmpl locales and commitlint (#3759)
This adds several automatic generators for Authelia docs etc.
Diffstat (limited to 'internal/configuration/helpers.go')
| -rw-r--r-- | internal/configuration/helpers.go | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/internal/configuration/helpers.go b/internal/configuration/helpers.go index 0f5e0b215..22b793e9a 100644 --- a/internal/configuration/helpers.go +++ b/internal/configuration/helpers.go @@ -12,15 +12,12 @@ func getEnvConfigMap(keys []string, prefix, delimiter string) (keyMap map[string for _, key := range keys { if strings.Contains(key, delimiter) { - originalKey := prefix + strings.ToUpper(strings.ReplaceAll(key, constDelimiter, delimiter)) - keyMap[originalKey] = key + keyMap[ToEnvironmentKey(key, prefix, delimiter)] = 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) + if IsSecretKey(key) { + ignoredKeys = append(ignoredKeys, ToEnvironmentSecretKey(key, prefix, delimiter)) } } @@ -31,7 +28,7 @@ func getSecretConfigMap(keys []string, prefix, delimiter string) (keyMap map[str keyMap = make(map[string]string) for _, key := range keys { - if isSecretKey(key) { + if IsSecretKey(key) { originalKey := strings.ToUpper(strings.ReplaceAll(key, constDelimiter, delimiter)) + constSecretSuffix keyMap[prefix+originalKey] = key @@ -41,7 +38,22 @@ func getSecretConfigMap(keys []string, prefix, delimiter string) (keyMap map[str return keyMap } -func isSecretKey(key string) (isSecretKey bool) { +// ToEnvironmentKey converts a key into the environment variable name. +func ToEnvironmentKey(key, prefix, delimiter string) string { + return prefix + strings.ToUpper(strings.ReplaceAll(key, constDelimiter, delimiter)) +} + +// ToEnvironmentSecretKey converts a key into the environment variable name. +func ToEnvironmentSecretKey(key, prefix, delimiter string) string { + return prefix + strings.ToUpper(strings.ReplaceAll(key, constDelimiter, delimiter)) + constSecretSuffix +} + +// IsSecretKey returns true if the provided key is a secret enabled key. +func IsSecretKey(key string) (isSecretKey bool) { + if strings.Contains(key, "[]") { + return false + } + return utils.IsStringInSliceSuffix(key, secretSuffixes) } |
