chore: OpenVPN user and password as nullable
- Username and password can be the empty string for custom provider
This commit is contained in:
21
internal/configuration/sources/env/openvpn.go
vendored
21
internal/configuration/sources/env/openvpn.go
vendored
@@ -72,14 +72,25 @@ func (r *Reader) readOpenVPN() (
|
||||
return openVPN, nil
|
||||
}
|
||||
|
||||
func (r *Reader) readOpenVPNUser() (user string) {
|
||||
_, user = r.getEnvWithRetro("OPENVPN_USER", "USER")
|
||||
func (r *Reader) readOpenVPNUser() (user *string) {
|
||||
user = new(string)
|
||||
_, *user = r.getEnvWithRetro("OPENVPN_USER", "USER")
|
||||
if *user == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove spaces in user ID to simplify user's life, thanks @JeordyR
|
||||
return strings.ReplaceAll(user, " ", "")
|
||||
*user = strings.ReplaceAll(*user, " ", "")
|
||||
return user
|
||||
}
|
||||
|
||||
func (r *Reader) readOpenVPNPassword() (password string) {
|
||||
_, password = r.getEnvWithRetro("OPENVPN_PASSWORD", "PASSWORD")
|
||||
func (r *Reader) readOpenVPNPassword() (password *string) {
|
||||
password = new(string)
|
||||
_, *password = r.getEnvWithRetro("OPENVPN_PASSWORD", "PASSWORD")
|
||||
if *password == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return password
|
||||
}
|
||||
|
||||
|
||||
@@ -25,18 +25,3 @@ func readSecretFileAsStringPtr(secretPathEnvKey, defaultSecretPath string) (
|
||||
}
|
||||
return files.ReadFromFile(path)
|
||||
}
|
||||
|
||||
func readSecretFileAsString(secretPathEnvKey, defaultSecretPath string) (
|
||||
s string, err error) {
|
||||
path := getCleanedEnv(secretPathEnvKey)
|
||||
if path == "" {
|
||||
path = defaultSecretPath
|
||||
}
|
||||
stringPtr, err := files.ReadFromFile(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
} else if stringPtr == nil {
|
||||
return "", nil
|
||||
}
|
||||
return *stringPtr, nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func readOpenVPN() (
|
||||
settings settings.OpenVPN, err error) {
|
||||
settings.User, err = readSecretFileAsString(
|
||||
settings.User, err = readSecretFileAsStringPtr(
|
||||
"OPENVPN_USER_SECRETFILE",
|
||||
"/run/secrets/openvpn_user",
|
||||
)
|
||||
@@ -16,7 +16,7 @@ func readOpenVPN() (
|
||||
return settings, fmt.Errorf("cannot read user file: %w", err)
|
||||
}
|
||||
|
||||
settings.Password, err = readSecretFileAsString(
|
||||
settings.Password, err = readSecretFileAsStringPtr(
|
||||
"OPENVPN_PASSWORD_SECRETFILE",
|
||||
"/run/secrets/openvpn_password",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user