From ea143c0c9a75d8b939912e39385795da5e049713 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Fri, 28 Jan 2022 00:10:23 +0000 Subject: [PATCH] feat(vpn): `VPN_ENDPOINT_PORT` - Deprecate `OPENVPN_PORT` - Deprecate `WIREGUARD_ENDPOINT_PORT` --- .../sources/env/openvpnselection.go | 19 +++++++++++++------ .../sources/env/wireguardselection.go | 17 ++++++++++++----- internal/provider/custom/connection.go | 2 +- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/internal/configuration/sources/env/openvpnselection.go b/internal/configuration/sources/env/openvpnselection.go index 07d9196b..788aee1e 100644 --- a/internal/configuration/sources/env/openvpnselection.go +++ b/internal/configuration/sources/env/openvpnselection.go @@ -61,16 +61,23 @@ func (r *Reader) readOpenVPNProtocol() (tcp *bool, err error) { } func (r *Reader) readOpenVPNCustomPort() (customPort *uint16, err error) { - key := "OPENVPN_PORT" - s := os.Getenv(key) + const currentKey = "VPN_ENDPOINT_PORT" + key := "PORT" + s := os.Getenv(key) // Retro-compatibility if s == "" { - // Retro-compatibility - key = "PORT" + key = "OPENVPN_PORT" // Retro-compatibility s = os.Getenv(key) if s == "" { - return nil, nil //nolint:nilnil + key = currentKey + s = os.Getenv(key) + if s == "" { + return nil, nil //nolint:nilnil + } } - r.onRetroActive("PORT", "OPENVPN_PORT") + } + + if key != currentKey { + r.onRetroActive(key, currentKey) } customPort = new(uint16) diff --git a/internal/configuration/sources/env/wireguardselection.go b/internal/configuration/sources/env/wireguardselection.go index f297e3f4..2e9e101f 100644 --- a/internal/configuration/sources/env/wireguardselection.go +++ b/internal/configuration/sources/env/wireguardselection.go @@ -55,16 +55,23 @@ func (r *Reader) readWireguardEndpointIP() (endpointIP net.IP, err error) { } func (r *Reader) readWireguardCustomPort() (customPort *uint16, err error) { - key := "WIREGUARD_ENDPOINT_PORT" + const currentKey = "VPN_ENDPOINT_PORT" + key := "WIREGUARD_PORT" // Retro-compatibility s := os.Getenv(key) if s == "" { - // Retro-compatibility - key = "WIREGUARD_PORT" + key = "WIREGUARD_ENDPOINT_PORT" // Retro-compatibility s = os.Getenv(key) if s == "" { - return nil, nil //nolint:nilnil + key = currentKey + s = os.Getenv(key) + if s == "" { + return nil, nil //nolint:nilnil + } } - r.onRetroActive("WIREGUARD_PORT", "WIREGUARD_ENDPOINT_PORT") + } + + if key != currentKey { + r.onRetroActive(key, currentKey) } customPort = new(uint16) diff --git a/internal/provider/custom/connection.go b/internal/provider/custom/connection.go index 9327c894..d8a61ba3 100644 --- a/internal/provider/custom/connection.go +++ b/internal/provider/custom/connection.go @@ -53,7 +53,7 @@ func getWireguardConnection(selection settings.ServerSelection) ( } } -// Port found is overridden by custom port set with `PORT` or `WIREGUARD_ENDPOINT_PORT`. +// Port found is overridden by custom port set with `VPN_ENDPOINT_PORT`. func getPort(foundPort uint16, selection settings.ServerSelection) (port uint16) { return utils.GetPort(selection, foundPort, foundPort, foundPort) }