mirror of
https://github.com/qdm12/gluetun.git
synced 2026-06-12 07:12:52 +02:00
PR feedback
This commit is contained in:
@@ -26,9 +26,6 @@ func (p *Provider) OpenVPNConfig(connection models.Connection,
|
||||
},
|
||||
TLSAuth: "81782767e4d59c4464cc5d1896f1cf6015017d53ac62e2e3b94b889e00b2c69ddc01944fe1c6d895b4d80540502eb71910b8d785c9efa9e3182343532adffe1cfbb7bb6eae39c502da2748edf0fb89b8a20b0a1085cc1f06135037881bc0c4ad8f2c0f4f72d2ab466fb54af3d8264c5fddeb0f21aa0ca41863678f5fc4c44de4ca0926b36dfddc42c6f2fabd1694bdc8215b2d223b9c21dc6734c2c778093187afb8c33403b228b9af68b540c284f6d183bcc88bd41d47bd717996e499ce1cbbfa768a9723c19c58314c4d19cfed82e543ee92e73d38ad26d4fbec231c0f9f3b30773a5c87792e9bc7c34e8d7611002ebedd044e48a0f1f96527bfdcc940aa09", //nolint:lll
|
||||
KeyDirection: "1",
|
||||
ExtraLines: []string{
|
||||
"replay-window 256",
|
||||
},
|
||||
}
|
||||
|
||||
if strings.HasSuffix(connection.Hostname, "singapore.ovpn.com") {
|
||||
|
||||
@@ -67,17 +67,11 @@ func fetchAPI(ctx context.Context, client *http.Client) (
|
||||
return data, nil
|
||||
}
|
||||
|
||||
var (
|
||||
ErrCityNotSet = errors.New("city is not set")
|
||||
ErrCountryNameNotSet = errors.New("country name is not set")
|
||||
ErrServersNotSet = errors.New("servers array is not set")
|
||||
)
|
||||
|
||||
func (a *apiDataCenter) validate() (err error) {
|
||||
conditionalErrors := []conditionalError{
|
||||
{err: ErrCityNotSet, condition: a.City == ""},
|
||||
{err: ErrCountryNameNotSet, condition: a.CountryName == ""},
|
||||
{err: ErrServersNotSet, condition: len(a.Servers) == 0},
|
||||
{err: "city is not set", condition: a.City == ""},
|
||||
{err: "country name is not set", condition: a.CountryName == ""},
|
||||
{err: "servers array is not set", condition: len(a.Servers) == 0},
|
||||
}
|
||||
err = collectErrors(conditionalErrors)
|
||||
if err != nil {
|
||||
@@ -106,29 +100,19 @@ func (a *apiDataCenter) validate() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
ErrIPFieldNotValid = errors.New("ip address is not set")
|
||||
ErrHostnameFieldNotSet = errors.New("hostname field is not set")
|
||||
ErrPublicKeyFieldNotSet = errors.New("public key field is not set")
|
||||
ErrWireguardPortsNotSet = errors.New("wireguard ports array is not set")
|
||||
ErrWireguardPortNotDefault = errors.New("wireguard port is not the default 9929")
|
||||
ErrMultiHopOpenVPNPortNotSet = errors.New("multihop OpenVPN port is not set")
|
||||
ErrMultiHopWireguardPortNotSet = errors.New("multihop WireGuard port is not set")
|
||||
)
|
||||
|
||||
func (a *apiServer) validate() (err error) {
|
||||
const defaultWireguardPort = 9929
|
||||
conditionalErrors := []conditionalError{
|
||||
{err: ErrIPFieldNotValid, condition: !a.IP.IsValid()},
|
||||
{err: ErrHostnameFieldNotSet, condition: a.Ptr == ""},
|
||||
{err: ErrPublicKeyFieldNotSet, condition: a.PublicKey == ""},
|
||||
{err: ErrWireguardPortsNotSet, condition: len(a.WireguardPorts) == 0},
|
||||
{err: "ip address is not set", condition: !a.IP.IsValid()},
|
||||
{err: "hostname field is not set", condition: a.Ptr == ""},
|
||||
{err: "public key field is not set", condition: a.PublicKey == ""},
|
||||
{err: "wireguard ports array is not set", condition: len(a.WireguardPorts) == 0},
|
||||
{
|
||||
err: ErrWireguardPortNotDefault,
|
||||
err: "wireguard port is not the default 9929",
|
||||
condition: len(a.WireguardPorts) != 1 || a.WireguardPorts[0] != defaultWireguardPort,
|
||||
},
|
||||
{err: ErrMultiHopOpenVPNPortNotSet, condition: a.MultiHopOpenvpnPort == 0},
|
||||
{err: ErrMultiHopWireguardPortNotSet, condition: a.MultiHopWireguardPort == 0},
|
||||
{err: "multihop OpenVPN port is not set", condition: a.MultiHopOpenvpnPort == 0},
|
||||
{err: "multihop WireGuard port is not set", condition: a.MultiHopWireguardPort == 0},
|
||||
}
|
||||
err = collectErrors(conditionalErrors)
|
||||
switch {
|
||||
@@ -144,28 +128,12 @@ func (a *apiServer) validate() (err error) {
|
||||
}
|
||||
|
||||
type conditionalError struct {
|
||||
err error
|
||||
err string
|
||||
condition bool
|
||||
}
|
||||
|
||||
type joinedError struct {
|
||||
errs []error
|
||||
}
|
||||
|
||||
func (e *joinedError) Unwrap() []error {
|
||||
return e.errs
|
||||
}
|
||||
|
||||
func (e *joinedError) Error() string {
|
||||
errStrings := make([]string, len(e.errs))
|
||||
for i, err := range e.errs {
|
||||
errStrings[i] = err.Error()
|
||||
}
|
||||
return strings.Join(errStrings, "; ")
|
||||
}
|
||||
|
||||
func collectErrors(conditionalErrors []conditionalError) (err error) {
|
||||
errs := make([]error, 0, len(conditionalErrors))
|
||||
errs := make([]string, 0, len(conditionalErrors))
|
||||
for _, conditionalError := range conditionalErrors {
|
||||
if !conditionalError.condition {
|
||||
continue
|
||||
@@ -177,7 +145,5 @@ func collectErrors(conditionalErrors []conditionalError) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &joinedError{
|
||||
errs: errs,
|
||||
}
|
||||
return errors.New(strings.Join(errs, "; "))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user