fix(settings): use qdm12/gosettings env.Get
This commit is contained in:
2
go.mod
2
go.mod
@@ -8,7 +8,7 @@ require (
|
|||||||
github.com/golang/mock v1.6.0
|
github.com/golang/mock v1.6.0
|
||||||
github.com/qdm12/dns v1.11.0
|
github.com/qdm12/dns v1.11.0
|
||||||
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6
|
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6
|
||||||
github.com/qdm12/gosettings v0.3.0-rc4
|
github.com/qdm12/gosettings v0.3.0-rc7
|
||||||
github.com/qdm12/goshutdown v0.3.0
|
github.com/qdm12/goshutdown v0.3.0
|
||||||
github.com/qdm12/gosplash v0.1.0
|
github.com/qdm12/gosplash v0.1.0
|
||||||
github.com/qdm12/gotree v0.2.0
|
github.com/qdm12/gotree v0.2.0
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -91,10 +91,8 @@ github.com/qdm12/golibs v0.0.0-20210603202746-e5494e9c2ebb/go.mod h1:15RBzkun0i8
|
|||||||
github.com/qdm12/golibs v0.0.0-20210723175634-a75ca7fd74c2/go.mod h1:6aRbg4Z/bTbm9JfxsGXfWKHi7zsOvPfUTK1S5HuAFKg=
|
github.com/qdm12/golibs v0.0.0-20210723175634-a75ca7fd74c2/go.mod h1:6aRbg4Z/bTbm9JfxsGXfWKHi7zsOvPfUTK1S5HuAFKg=
|
||||||
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6 h1:bge5AL7cjHJMPz+5IOz5yF01q/l8No6+lIEBieA8gMg=
|
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6 h1:bge5AL7cjHJMPz+5IOz5yF01q/l8No6+lIEBieA8gMg=
|
||||||
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6/go.mod h1:6aRbg4Z/bTbm9JfxsGXfWKHi7zsOvPfUTK1S5HuAFKg=
|
github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6/go.mod h1:6aRbg4Z/bTbm9JfxsGXfWKHi7zsOvPfUTK1S5HuAFKg=
|
||||||
github.com/qdm12/gosettings v0.3.0-rc3 h1:ySstdo7i3h5z6iJ6R96YykC+JuluaVqncHxsFzndyUI=
|
github.com/qdm12/gosettings v0.3.0-rc7 h1:fRIJe+pUIe2uzKjqtNnWIUsZsvpoPbXv5a/xo5utvbs=
|
||||||
github.com/qdm12/gosettings v0.3.0-rc3/go.mod h1:+hHzN8lsE63T01t6SruGzc6xkpvfsZFod/ooDs8FWnQ=
|
github.com/qdm12/gosettings v0.3.0-rc7/go.mod h1:+hHzN8lsE63T01t6SruGzc6xkpvfsZFod/ooDs8FWnQ=
|
||||||
github.com/qdm12/gosettings v0.3.0-rc4 h1:rk0IG6mEs85zV2NzEH/XRbZx4FGGYpmcpGysFjEYL50=
|
|
||||||
github.com/qdm12/gosettings v0.3.0-rc4/go.mod h1:+hHzN8lsE63T01t6SruGzc6xkpvfsZFod/ooDs8FWnQ=
|
|
||||||
github.com/qdm12/goshutdown v0.3.0 h1:pqBpJkdwlZlfTEx4QHtS8u8CXx6pG0fVo6S1N0MpSEM=
|
github.com/qdm12/goshutdown v0.3.0 h1:pqBpJkdwlZlfTEx4QHtS8u8CXx6pG0fVo6S1N0MpSEM=
|
||||||
github.com/qdm12/goshutdown v0.3.0/go.mod h1:EqZ46No00kCTZ5qzdd3qIzY6ayhMt24QI8Mh8LVQYmM=
|
github.com/qdm12/goshutdown v0.3.0/go.mod h1:EqZ46No00kCTZ5qzdd3qIzY6ayhMt24QI8Mh8LVQYmM=
|
||||||
github.com/qdm12/gosplash v0.1.0 h1:Sfl+zIjFZFP7b0iqf2l5UkmEY97XBnaKkH3FNY6Gf7g=
|
github.com/qdm12/gosplash v0.1.0 h1:Sfl+zIjFZFP7b0iqf2l5UkmEY97XBnaKkH3FNY6Gf7g=
|
||||||
|
|||||||
3
internal/configuration/sources/env/health.go
vendored
3
internal/configuration/sources/env/health.go
vendored
@@ -5,10 +5,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Source) ReadHealth() (health settings.Health, err error) {
|
func (s *Source) ReadHealth() (health settings.Health, err error) {
|
||||||
health.ServerAddress = getCleanedEnv("HEALTH_SERVER_ADDRESS")
|
health.ServerAddress = env.Get("HEALTH_SERVER_ADDRESS")
|
||||||
_, health.TargetAddress = s.getEnvWithRetro("HEALTH_TARGET_ADDRESS", "HEALTH_ADDRESS_TO_PING")
|
_, health.TargetAddress = s.getEnvWithRetro("HEALTH_TARGET_ADDRESS", "HEALTH_ADDRESS_TO_PING")
|
||||||
|
|
||||||
successWaitPtr, err := envToDurationPtr("HEALTH_SUCCESS_WAIT_DURATION")
|
successWaitPtr, err := envToDurationPtr("HEALTH_SUCCESS_WAIT_DURATION")
|
||||||
|
|||||||
27
internal/configuration/sources/env/helpers.go
vendored
27
internal/configuration/sources/env/helpers.go
vendored
@@ -7,22 +7,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
"github.com/qdm12/govalid/binary"
|
"github.com/qdm12/govalid/binary"
|
||||||
"github.com/qdm12/govalid/integer"
|
"github.com/qdm12/govalid/integer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
func envToCSV(envKey string) (values []string) {
|
func envToCSV(envKey string) (values []string) {
|
||||||
csv := getCleanedEnv(envKey)
|
csv := env.Get(envKey)
|
||||||
if csv == "" {
|
if csv == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -30,7 +21,7 @@ func envToCSV(envKey string) (values []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func envToFloat64(envKey string) (f float64, err error) {
|
func envToFloat64(envKey string) (f float64, err error) {
|
||||||
s := getCleanedEnv(envKey)
|
s := env.Get(envKey)
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -39,7 +30,7 @@ func envToFloat64(envKey string) (f float64, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func envToStringPtr(envKey string) (stringPtr *string) {
|
func envToStringPtr(envKey string) (stringPtr *string) {
|
||||||
s := getCleanedEnv(envKey)
|
s := env.Get(envKey)
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -47,7 +38,7 @@ func envToStringPtr(envKey string) (stringPtr *string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func envToBoolPtr(envKey string) (boolPtr *bool, err error) {
|
func envToBoolPtr(envKey string) (boolPtr *bool, err error) {
|
||||||
s := getCleanedEnv(envKey)
|
s := env.Get(envKey)
|
||||||
value, err := binary.Validate(s)
|
value, err := binary.Validate(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -56,7 +47,7 @@ func envToBoolPtr(envKey string) (boolPtr *bool, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func envToIntPtr(envKey string) (intPtr *int, err error) {
|
func envToIntPtr(envKey string) (intPtr *int, err error) {
|
||||||
s := getCleanedEnv(envKey)
|
s := env.Get(envKey)
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil, nil //nolint:nilnil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
@@ -68,7 +59,7 @@ func envToIntPtr(envKey string) (intPtr *int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func envToUint8Ptr(envKey string) (uint8Ptr *uint8, err error) {
|
func envToUint8Ptr(envKey string) (uint8Ptr *uint8, err error) {
|
||||||
s := getCleanedEnv(envKey)
|
s := env.Get(envKey)
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil, nil //nolint:nilnil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
@@ -85,7 +76,7 @@ func envToUint8Ptr(envKey string) (uint8Ptr *uint8, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func envToUint16Ptr(envKey string) (uint16Ptr *uint16, err error) {
|
func envToUint16Ptr(envKey string) (uint16Ptr *uint16, err error) {
|
||||||
s := getCleanedEnv(envKey)
|
s := env.Get(envKey)
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil, nil //nolint:nilnil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
@@ -102,7 +93,7 @@ func envToUint16Ptr(envKey string) (uint16Ptr *uint16, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func envToDurationPtr(envKey string) (durationPtr *time.Duration, err error) {
|
func envToDurationPtr(envKey string) (durationPtr *time.Duration, err error) {
|
||||||
s := getCleanedEnv(envKey)
|
s := env.Get(envKey)
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil, nil //nolint:nilnil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
|
|||||||
3
internal/configuration/sources/env/log.go
vendored
3
internal/configuration/sources/env/log.go
vendored
@@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
"github.com/qdm12/log"
|
"github.com/qdm12/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ func readLog() (log settings.Log, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readLogLevel() (level *log.Level, err error) {
|
func readLogLevel() (level *log.Level, err error) {
|
||||||
s := getCleanedEnv("LOG_LEVEL")
|
s := env.Get("LOG_LEVEL")
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil, nil //nolint:nilnil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
|
|||||||
11
internal/configuration/sources/env/openvpn.go
vendored
11
internal/configuration/sources/env/openvpn.go
vendored
@@ -5,6 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
"github.com/qdm12/govalid/binary"
|
"github.com/qdm12/govalid/binary"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,10 +16,10 @@ func (s *Source) readOpenVPN() (
|
|||||||
"OPENVPN_KEY_PASSPHRASE", "OPENVPN_ENCRYPTED_KEY"}, err)
|
"OPENVPN_KEY_PASSPHRASE", "OPENVPN_ENCRYPTED_KEY"}, err)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
openVPN.Version = getCleanedEnv("OPENVPN_VERSION")
|
openVPN.Version = env.Get("OPENVPN_VERSION")
|
||||||
openVPN.User = s.readOpenVPNUser()
|
openVPN.User = s.readOpenVPNUser()
|
||||||
openVPN.Password = s.readOpenVPNPassword()
|
openVPN.Password = s.readOpenVPNPassword()
|
||||||
confFile := getCleanedEnv("OPENVPN_CUSTOM_CONFIG")
|
confFile := env.Get("OPENVPN_CUSTOM_CONFIG")
|
||||||
if confFile != "" {
|
if confFile != "" {
|
||||||
openVPN.ConfFile = &confFile
|
openVPN.ConfFile = &confFile
|
||||||
}
|
}
|
||||||
@@ -26,7 +27,7 @@ func (s *Source) readOpenVPN() (
|
|||||||
ciphersKey, _ := s.getEnvWithRetro("OPENVPN_CIPHERS", "OPENVPN_CIPHER")
|
ciphersKey, _ := s.getEnvWithRetro("OPENVPN_CIPHERS", "OPENVPN_CIPHER")
|
||||||
openVPN.Ciphers = envToCSV(ciphersKey)
|
openVPN.Ciphers = envToCSV(ciphersKey)
|
||||||
|
|
||||||
auth := getCleanedEnv("OPENVPN_AUTH")
|
auth := env.Get("OPENVPN_AUTH")
|
||||||
if auth != "" {
|
if auth != "" {
|
||||||
openVPN.Auth = &auth
|
openVPN.Auth = &auth
|
||||||
}
|
}
|
||||||
@@ -56,7 +57,7 @@ func (s *Source) readOpenVPN() (
|
|||||||
return openVPN, fmt.Errorf("environment variable OPENVPN_VERBOSITY: %w", err)
|
return openVPN, fmt.Errorf("environment variable OPENVPN_VERBOSITY: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
flagsStr := getCleanedEnv("OPENVPN_FLAGS")
|
flagsStr := env.Get("OPENVPN_FLAGS")
|
||||||
if flagsStr != "" {
|
if flagsStr != "" {
|
||||||
openVPN.Flags = strings.Fields(flagsStr)
|
openVPN.Flags = strings.Fields(flagsStr)
|
||||||
}
|
}
|
||||||
@@ -88,7 +89,7 @@ func (s *Source) readOpenVPNPassword() (password *string) {
|
|||||||
|
|
||||||
func (s *Source) readOpenVPNKeyPassphrase() (passphrase *string) {
|
func (s *Source) readOpenVPNKeyPassphrase() (passphrase *string) {
|
||||||
passphrase = new(string)
|
passphrase = new(string)
|
||||||
*passphrase = getCleanedEnv("OPENVPN_KEY_PASSPHRASE")
|
*passphrase = env.Get("OPENVPN_KEY_PASSPHRASE")
|
||||||
if *passphrase == "" {
|
if *passphrase == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ import (
|
|||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
"github.com/qdm12/govalid/port"
|
"github.com/qdm12/govalid/port"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Source) readOpenVPNSelection() (
|
func (s *Source) readOpenVPNSelection() (
|
||||||
selection settings.OpenVPNSelection, err error) {
|
selection settings.OpenVPNSelection, err error) {
|
||||||
confFile := getCleanedEnv("OPENVPN_CUSTOM_CONFIG")
|
confFile := env.Get("OPENVPN_CUSTOM_CONFIG")
|
||||||
if confFile != "" {
|
if confFile != "" {
|
||||||
selection.ConfFile = &confFile
|
selection.ConfFile = &confFile
|
||||||
}
|
}
|
||||||
|
|||||||
3
internal/configuration/sources/env/pprof.go
vendored
3
internal/configuration/sources/env/pprof.go
vendored
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/pprof"
|
"github.com/qdm12/gluetun/internal/pprof"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
func readPprof() (settings pprof.Settings, err error) {
|
func readPprof() (settings pprof.Settings, err error) {
|
||||||
@@ -22,7 +23,7 @@ func readPprof() (settings pprof.Settings, err error) {
|
|||||||
return settings, fmt.Errorf("environment variable PPROF_MUTEX_PROFILE_RATE: %w", err)
|
return settings, fmt.Errorf("environment variable PPROF_MUTEX_PROFILE_RATE: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.HTTPServer.Address = getCleanedEnv("PPROF_HTTP_SERVER_ADDRESS")
|
settings.HTTPServer.Address = env.Get("PPROF_HTTP_SERVER_ADDRESS")
|
||||||
|
|
||||||
return settings, nil
|
return settings, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Source) readProvider(vpnType string) (provider settings.Provider, err error) {
|
func (s *Source) readProvider(vpnType string) (provider settings.Provider, err error) {
|
||||||
@@ -32,7 +33,7 @@ func (s *Source) readProvider(vpnType string) (provider settings.Provider, err e
|
|||||||
func (s *Source) readVPNServiceProvider(vpnType string) (vpnProviderPtr *string) {
|
func (s *Source) readVPNServiceProvider(vpnType string) (vpnProviderPtr *string) {
|
||||||
_, value := s.getEnvWithRetro("VPN_SERVICE_PROVIDER", "VPNSP")
|
_, value := s.getEnvWithRetro("VPN_SERVICE_PROVIDER", "VPNSP")
|
||||||
if value == "" {
|
if value == "" {
|
||||||
if vpnType != vpn.Wireguard && getCleanedEnv("OPENVPN_CUSTOM_CONFIG") != "" {
|
if vpnType != vpn.Wireguard && env.Get("OPENVPN_CUSTOM_CONFIG") != "" {
|
||||||
// retro compatibility
|
// retro compatibility
|
||||||
return stringPtr(providers.Custom)
|
return stringPtr(providers.Custom)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Source) readPublicIP() (publicIP settings.PublicIP, err error) {
|
func (s *Source) readPublicIP() (publicIP settings.PublicIP, err error) {
|
||||||
@@ -19,7 +20,7 @@ func (s *Source) readPublicIP() (publicIP settings.PublicIP, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readPublicIPPeriod() (period *time.Duration, err error) {
|
func readPublicIPPeriod() (period *time.Duration, err error) {
|
||||||
s := getCleanedEnv("PUBLICIP_PERIOD")
|
s := env.Get("PUBLICIP_PERIOD")
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil, nil //nolint:nilnil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
|
|||||||
5
internal/configuration/sources/env/reader.go
vendored
5
internal/configuration/sources/env/reader.go
vendored
@@ -2,6 +2,7 @@ package env
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Source struct {
|
type Source struct {
|
||||||
@@ -106,12 +107,12 @@ func (s *Source) getEnvWithRetro(currentKey string,
|
|||||||
// We check retro-compatibility keys first since
|
// We check retro-compatibility keys first since
|
||||||
// the current key might be set in the Dockerfile.
|
// the current key might be set in the Dockerfile.
|
||||||
for _, key = range retroKeys {
|
for _, key = range retroKeys {
|
||||||
value = getCleanedEnv(key)
|
value = env.Get(key)
|
||||||
if value != "" {
|
if value != "" {
|
||||||
s.onRetroActive(key, currentKey)
|
s.onRetroActive(key, currentKey)
|
||||||
return key, value
|
return key, value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentKey, getCleanedEnv(currentKey)
|
return currentKey, env.Get(currentKey)
|
||||||
}
|
}
|
||||||
|
|||||||
3
internal/configuration/sources/env/server.go
vendored
3
internal/configuration/sources/env/server.go
vendored
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
"github.com/qdm12/govalid/binary"
|
"github.com/qdm12/govalid/binary"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ func (s *Source) readControlServer() (controlServer settings.ControlServer, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readControlServerLog() (enabled *bool, err error) {
|
func readControlServerLog() (enabled *bool, err error) {
|
||||||
s := getCleanedEnv("HTTP_CONTROL_SERVER_LOG")
|
s := env.Get("HTTP_CONTROL_SERVER_LOG")
|
||||||
log, err := binary.Validate(s)
|
log, err := binary.Validate(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("environment variable HTTP_CONTROL_SERVER_LOG: %w", err)
|
return nil, fmt.Errorf("environment variable HTTP_CONTROL_SERVER_LOG: %w", err)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -48,7 +49,7 @@ func (s *Source) readServerSelection(vpnProvider, vpnType string) (
|
|||||||
serverNamesKey, _ := s.getEnvWithRetro("SERVER_NAMES", "SERVER_NAME")
|
serverNamesKey, _ := s.getEnvWithRetro("SERVER_NAMES", "SERVER_NAME")
|
||||||
ss.Names = envToCSV(serverNamesKey)
|
ss.Names = envToCSV(serverNamesKey)
|
||||||
|
|
||||||
if csv := getCleanedEnv("SERVER_NUMBER"); csv != "" {
|
if csv := env.Get("SERVER_NUMBER"); csv != "" {
|
||||||
numbersStrings := strings.Split(csv, ",")
|
numbersStrings := strings.Split(csv, ",")
|
||||||
numbers := make([]uint16, len(numbersStrings))
|
numbers := make([]uint16, len(numbersStrings))
|
||||||
for i, numberString := range numbersStrings {
|
for i, numberString := range numbersStrings {
|
||||||
|
|||||||
3
internal/configuration/sources/env/system.go
vendored
3
internal/configuration/sources/env/system.go
vendored
@@ -6,6 +6,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -25,7 +26,7 @@ func (s *Source) readSystem() (system settings.System, err error) {
|
|||||||
return system, err
|
return system, err
|
||||||
}
|
}
|
||||||
|
|
||||||
system.Timezone = getCleanedEnv("TZ")
|
system.Timezone = env.Get("TZ")
|
||||||
|
|
||||||
return system, nil
|
return system, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
func readUpdater() (updater settings.Updater, err error) {
|
func readUpdater() (updater settings.Updater, err error) {
|
||||||
@@ -29,7 +30,7 @@ func readUpdater() (updater settings.Updater, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readUpdaterPeriod() (period *time.Duration, err error) {
|
func readUpdaterPeriod() (period *time.Duration, err error) {
|
||||||
s := getCleanedEnv("UPDATER_PERIOD")
|
s := env.Get("UPDATER_PERIOD")
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil, nil //nolint:nilnil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
"github.com/qdm12/govalid/binary"
|
"github.com/qdm12/govalid/binary"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ func readVersion() (version settings.Version, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readVersionEnabled() (enabled *bool, err error) {
|
func readVersionEnabled() (enabled *bool, err error) {
|
||||||
s := getCleanedEnv("VERSION_INFORMATION")
|
s := env.Get("VERSION_INFORMATION")
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil, nil //nolint:nilnil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
|
|||||||
3
internal/configuration/sources/env/vpn.go
vendored
3
internal/configuration/sources/env/vpn.go
vendored
@@ -5,10 +5,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Source) readVPN() (vpn settings.VPN, err error) {
|
func (s *Source) readVPN() (vpn settings.VPN, err error) {
|
||||||
vpn.Type = strings.ToLower(getCleanedEnv("VPN_TYPE"))
|
vpn.Type = strings.ToLower(env.Get("VPN_TYPE"))
|
||||||
|
|
||||||
vpn.Provider, err = s.readProvider(vpn.Type)
|
vpn.Provider, err = s.readProvider(vpn.Type)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package env
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Source) readWireguard() (wireguard settings.Wireguard, err error) {
|
func (s *Source) readWireguard() (wireguard settings.Wireguard, err error) {
|
||||||
@@ -16,7 +16,7 @@ func (s *Source) readWireguard() (wireguard settings.Wireguard, err error) {
|
|||||||
wireguard.PrivateKey = envToStringPtr("WIREGUARD_PRIVATE_KEY")
|
wireguard.PrivateKey = envToStringPtr("WIREGUARD_PRIVATE_KEY")
|
||||||
wireguard.PreSharedKey = envToStringPtr("WIREGUARD_PRESHARED_KEY")
|
wireguard.PreSharedKey = envToStringPtr("WIREGUARD_PRESHARED_KEY")
|
||||||
_, wireguard.Interface = s.getEnvWithRetro("VPN_INTERFACE", "WIREGUARD_INTERFACE")
|
_, wireguard.Interface = s.getEnvWithRetro("VPN_INTERFACE", "WIREGUARD_INTERFACE")
|
||||||
wireguard.Implementation = os.Getenv("WIREGUARD_IMPLEMENTATION")
|
wireguard.Implementation = env.Get("WIREGUARD_IMPLEMENTATION")
|
||||||
wireguard.Addresses, err = s.readWireguardAddresses()
|
wireguard.Addresses, err = s.readWireguardAddresses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return wireguard, err // already wrapped
|
return wireguard, err // already wrapped
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"net/netip"
|
"net/netip"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
"github.com/qdm12/govalid/port"
|
"github.com/qdm12/govalid/port"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ func (s *Source) readWireguardSelection() (
|
|||||||
return selection, err
|
return selection, err
|
||||||
}
|
}
|
||||||
|
|
||||||
selection.PublicKey = getCleanedEnv("WIREGUARD_PUBLIC_KEY")
|
selection.PublicKey = env.Get("WIREGUARD_PUBLIC_KEY")
|
||||||
|
|
||||||
return selection, nil
|
return selection, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,26 +2,15 @@ package secrets
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/sources/files"
|
"github.com/qdm12/gluetun/internal/configuration/sources/files"
|
||||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||||
|
"github.com/qdm12/gosettings/sources/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
func readSecretFileAsStringPtr(secretPathEnvKey, defaultSecretPath string) (
|
func readSecretFileAsStringPtr(secretPathEnvKey, defaultSecretPath string) (
|
||||||
stringPtr *string, err error) {
|
stringPtr *string, err error) {
|
||||||
path := getCleanedEnv(secretPathEnvKey)
|
path := env.Get(secretPathEnvKey)
|
||||||
if path == "" {
|
if path == "" {
|
||||||
path = defaultSecretPath
|
path = defaultSecretPath
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user