diff --git a/go.mod b/go.mod index 1104270b..7882ff95 100644 --- a/go.mod +++ b/go.mod @@ -8,11 +8,11 @@ require ( github.com/golang/mock v1.6.0 github.com/qdm12/dns v1.11.0 github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6 - github.com/qdm12/gosettings v0.2.0 + github.com/qdm12/gosettings v0.3.0-rc3 github.com/qdm12/goshutdown v0.3.0 github.com/qdm12/gosplash v0.1.0 github.com/qdm12/gotree v0.2.0 - github.com/qdm12/govalid v0.1.0 + github.com/qdm12/govalid v0.2.0-rc1 github.com/qdm12/log v0.1.0 github.com/qdm12/ss-server v0.4.0 github.com/qdm12/updated v0.0.0-20210603204757-205acfe6937e diff --git a/go.sum b/go.sum index 48ce8853..5668e7bc 100644 --- a/go.sum +++ b/go.sum @@ -93,6 +93,8 @@ github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6 h1:bge5AL7cjHJMPz+5IO github.com/qdm12/golibs v0.0.0-20210822203818-5c568b0777b6/go.mod h1:6aRbg4Z/bTbm9JfxsGXfWKHi7zsOvPfUTK1S5HuAFKg= github.com/qdm12/gosettings v0.2.0 h1:Q/4s0t8k9e3MSKMM5oMUIE3UGrdd+U2+qR8rTgiKRvA= github.com/qdm12/gosettings v0.2.0/go.mod h1:GptXlJVLQxfWznSlgc+pNo3JGnp+f2AKEv0tq/U7igU= +github.com/qdm12/gosettings v0.3.0-rc3 h1:ySstdo7i3h5z6iJ6R96YykC+JuluaVqncHxsFzndyUI= +github.com/qdm12/gosettings v0.3.0-rc3/go.mod h1:+hHzN8lsE63T01t6SruGzc6xkpvfsZFod/ooDs8FWnQ= github.com/qdm12/goshutdown v0.3.0 h1:pqBpJkdwlZlfTEx4QHtS8u8CXx6pG0fVo6S1N0MpSEM= github.com/qdm12/goshutdown v0.3.0/go.mod h1:EqZ46No00kCTZ5qzdd3qIzY6ayhMt24QI8Mh8LVQYmM= github.com/qdm12/gosplash v0.1.0 h1:Sfl+zIjFZFP7b0iqf2l5UkmEY97XBnaKkH3FNY6Gf7g= @@ -101,6 +103,8 @@ github.com/qdm12/gotree v0.2.0 h1:+58ltxkNLUyHtATFereAcOjBVfY6ETqRex8XK90Fb/c= github.com/qdm12/gotree v0.2.0/go.mod h1:1SdFaqKZuI46U1apbXIf25pDMNnrPuYLEqMF/qL4lY4= github.com/qdm12/govalid v0.1.0 h1:UIFVmuaAg0Q+h0GeyfcFEZ5sQ5KJPvRQwycC1/cqDN8= github.com/qdm12/govalid v0.1.0/go.mod h1:CyS/OEQdOvunBgrtIsW93fjd4jBkwZPBjGSpxq3NwA4= +github.com/qdm12/govalid v0.2.0-rc1 h1:4iYQvU4ibrASgzelsEgZX4JyKX3UTB/DcHObzQ7BXtw= +github.com/qdm12/govalid v0.2.0-rc1/go.mod h1:/uWzVWMuS71wmbsVnlUxpQiy6EAXqm8eQ2RbyA72roQ= github.com/qdm12/log v0.1.0 h1:jYBd/xscHYpblzZAd2kjZp2YmuYHjAAfbTViJWxoPTw= github.com/qdm12/log v0.1.0/go.mod h1:Vchi5M8uBvHfPNIblN4mjXn/oSbiWguQIbsgF1zdQPI= github.com/qdm12/ss-server v0.4.0 h1:lMMYfDGc9P86Lyvd3+p8lK4hhgHUKDzjZC91FqJYkDU= diff --git a/internal/configuration/settings/health.go b/internal/configuration/settings/health.go index 6cdc3106..80cdebfc 100644 --- a/internal/configuration/settings/health.go +++ b/internal/configuration/settings/health.go @@ -37,7 +37,7 @@ type Health struct { func (h Health) Validate() (err error) { uid := os.Getuid() - _, err = address.Validate(h.ServerAddress, + err = address.Validate(h.ServerAddress, address.OptionListening(uid)) if err != nil { return fmt.Errorf("server listening address is not valid: %w", err) diff --git a/internal/configuration/settings/httpproxy.go b/internal/configuration/settings/httpproxy.go index 50053eae..3fc56b9d 100644 --- a/internal/configuration/settings/httpproxy.go +++ b/internal/configuration/settings/httpproxy.go @@ -47,7 +47,7 @@ func (h HTTPProxy) validate() (err error) { // Do not validate user and password uid := os.Getuid() - _, err = address.Validate(h.ListeningAddress, address.OptionListening(uid)) + err = address.Validate(h.ListeningAddress, address.OptionListening(uid)) if err != nil { return fmt.Errorf("%w: %s", ErrServerAddressNotValid, h.ListeningAddress) } diff --git a/internal/configuration/sources/env/dnsblacklist.go b/internal/configuration/sources/env/dnsblacklist.go index 480c6f8c..da83d6af 100644 --- a/internal/configuration/sources/env/dnsblacklist.go +++ b/internal/configuration/sources/env/dnsblacklist.go @@ -38,12 +38,7 @@ func (s *Source) readDNSBlacklist() (blacklist settings.DNSBlacklist, err error) func (s *Source) readBlockSurveillance() (blocked *bool, err error) { key, value := s.getEnvWithRetro("BLOCK_SURVEILLANCE", "BLOCK_NSA") - if value == "" { - return nil, nil //nolint:nilnil - } - - blocked = new(bool) - *blocked, err = binary.Validate(value) + blocked, err = binary.Validate(value) if err != nil { return nil, fmt.Errorf("environment variable %s: %w", key, err) } diff --git a/internal/configuration/sources/env/helpers.go b/internal/configuration/sources/env/helpers.go index 006db996..102bc10a 100644 --- a/internal/configuration/sources/env/helpers.go +++ b/internal/configuration/sources/env/helpers.go @@ -48,14 +48,11 @@ func envToStringPtr(envKey string) (stringPtr *string) { func envToBoolPtr(envKey string) (boolPtr *bool, err error) { s := getCleanedEnv(envKey) - if s == "" { - return nil, nil //nolint:nilnil - } value, err := binary.Validate(s) if err != nil { return nil, err } - return &value, nil + return value, nil } func envToIntPtr(envKey string) (intPtr *int, err error) { diff --git a/internal/configuration/sources/env/httproxy.go b/internal/configuration/sources/env/httproxy.go index 2b138e8a..bb6fa8fd 100644 --- a/internal/configuration/sources/env/httproxy.go +++ b/internal/configuration/sources/env/httproxy.go @@ -56,12 +56,7 @@ func (s *Source) readHTTProxyListeningAddress() (listeningAddress string) { func (s *Source) readHTTProxyEnabled() (enabled *bool, err error) { key, value := s.getEnvWithRetro("HTTPPROXY", "PROXY", "TINYPROXY") - if value == "" { - return nil, nil //nolint:nilnil - } - - enabled = new(bool) - *enabled, err = binary.Validate(value) + enabled, err = binary.Validate(value) if err != nil { return nil, fmt.Errorf("environment variable %s: %w", key, err) } @@ -71,9 +66,6 @@ func (s *Source) readHTTProxyEnabled() (enabled *bool, err error) { func (s *Source) readHTTProxyLog() (enabled *bool, err error) { key, value := s.getEnvWithRetro("HTTPPROXY_LOG", "PROXY_LOG_LEVEL", "TINYPROXY_LOG") - if value == "" { - return nil, nil //nolint:nilnil - } var binaryOptions []binary.Option if key != "HTTPROXY_LOG" { @@ -81,8 +73,7 @@ func (s *Source) readHTTProxyLog() (enabled *bool, err error) { binaryOptions = append(binaryOptions, retroOption) } - enabled = new(bool) - *enabled, err = binary.Validate(value, binaryOptions...) + enabled, err = binary.Validate(value, binaryOptions...) if err != nil { return nil, fmt.Errorf("environment variable %s: %w", key, err) } diff --git a/internal/configuration/sources/env/openvpn.go b/internal/configuration/sources/env/openvpn.go index c34ad338..2653cfda 100644 --- a/internal/configuration/sources/env/openvpn.go +++ b/internal/configuration/sources/env/openvpn.go @@ -119,7 +119,7 @@ func (s *Source) readOpenVPNProcessUser() (processUser string, err error) { if err != nil { return "", fmt.Errorf("environment variable %s: %w", key, err) } - if root { + if *root { return "root", nil } const defaultNonRootUser = "nonrootuser" diff --git a/internal/configuration/sources/env/server.go b/internal/configuration/sources/env/server.go index a2fabf0a..680ec726 100644 --- a/internal/configuration/sources/env/server.go +++ b/internal/configuration/sources/env/server.go @@ -20,16 +20,11 @@ func (s *Source) readControlServer() (controlServer settings.ControlServer, err func readControlServerLog() (enabled *bool, err error) { s := getCleanedEnv("HTTP_CONTROL_SERVER_LOG") - if s == "" { - return nil, nil //nolint:nilnil - } - log, err := binary.Validate(s) if err != nil { return nil, fmt.Errorf("environment variable HTTP_CONTROL_SERVER_LOG: %w", err) } - - return &log, nil + return log, nil } func (s *Source) readControlServerAddress() (address *string) { diff --git a/internal/configuration/sources/env/version.go b/internal/configuration/sources/env/version.go index ceff787f..590d2946 100644 --- a/internal/configuration/sources/env/version.go +++ b/internal/configuration/sources/env/version.go @@ -22,8 +22,7 @@ func readVersionEnabled() (enabled *bool, err error) { return nil, nil //nolint:nilnil } - enabled = new(bool) - *enabled, err = binary.Validate(s) + enabled, err = binary.Validate(s) if err != nil { return nil, fmt.Errorf("environment variable VERSION_INFORMATION: %w", err) } diff --git a/internal/httpserver/settings.go b/internal/httpserver/settings.go index c28b444b..90f542f1 100644 --- a/internal/httpserver/settings.go +++ b/internal/httpserver/settings.go @@ -85,7 +85,7 @@ var ( func (s Settings) Validate() (err error) { uid := os.Getuid() - _, err = address.Validate(s.Address, address.OptionListening(uid)) + err = address.Validate(s.Address, address.OptionListening(uid)) if err != nil { return err }