2022-01-06 06:40:23 -05:00
|
|
|
package secrets
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
2022-05-27 17:22:50 +00:00
|
|
|
"strings"
|
2022-01-06 06:40:23 -05:00
|
|
|
|
|
|
|
|
"github.com/qdm12/gluetun/internal/configuration/sources/files"
|
|
|
|
|
)
|
|
|
|
|
|
2022-05-27 17:22:50 +00:00
|
|
|
// getCleanedEnv returns an environment variable value with
|
|
|
|
|
// surrounding spaces and trailing new line characters removed.
|
|
|
|
|
func getCleanedEnv(envKey string) (value string) {
|
|
|
|
|
value = os.Getenv(envKey)
|
|
|
|
|
value = strings.TrimSpace(value)
|
|
|
|
|
value = strings.TrimSuffix(value, "\r\n")
|
|
|
|
|
value = strings.TrimSuffix(value, "\n")
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
func readSecretFileAsStringPtr(secretPathEnvKey, defaultSecretPath string) (
|
|
|
|
|
stringPtr *string, err error) {
|
2022-05-27 17:22:50 +00:00
|
|
|
path := getCleanedEnv(secretPathEnvKey)
|
2022-01-06 06:40:23 -05:00
|
|
|
if path == "" {
|
|
|
|
|
path = defaultSecretPath
|
|
|
|
|
}
|
|
|
|
|
return files.ReadFromFile(path)
|
|
|
|
|
}
|