Skip to content

Commit

Permalink
Additional settings validations
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Sep 23, 2023
1 parent e2a167c commit 531d43f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions internal/portforward/service/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/netip"

"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/provider"
"github.com/qdm12/gosettings"
)
Expand Down Expand Up @@ -49,11 +50,27 @@ func (s *Settings) overrideWith(update Settings) {
s.VPNProvider = gosettings.OverrideWithString(s.VPNProvider, update.VPNProvider)
}

var ErrVPNProviderNotSet = errors.New("VPN provider not set")
var (
ErrVPNProviderNotSet = errors.New("VPN provider not set")
ErrServerNameNotSet = errors.New("server name not set")
ErrPortForwarderNotSet = errors.New("port forwarder not set")
ErrGatewayNotSet = errors.New("gateway not set")
ErrInterfaceNotSet = errors.New("interface not set")
)

func (s *Settings) validate() (err error) {
if s.VPNProvider == "" {
switch {
case s.VPNProvider == "":
return fmt.Errorf("%w", ErrVPNProviderNotSet)
case s.VPNProvider == providers.PrivateInternetAccess && s.ServerName == "":
return fmt.Errorf("%w", ErrServerNameNotSet)
case s.PortForwarder == nil:
return fmt.Errorf("%w", ErrPortForwarderNotSet)
case !s.Gateway.IsValid():
return fmt.Errorf("%w", ErrGatewayNotSet)
case s.Interface == "":
return fmt.Errorf("%w", ErrInterfaceNotSet)
}

return s.UserSettings.Validate(s.VPNProvider)
}

0 comments on commit 531d43f

Please sign in to comment.