chore(updater): check servers have minimal information
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
@@ -31,6 +34,31 @@ type Server struct {
|
||||
IPs []net.IP `json:"ips,omitempty"`
|
||||
}
|
||||
|
||||
var (
|
||||
ErrVPNFieldEmpty = errors.New("vpn field is empty")
|
||||
ErrHostnameFieldEmpty = errors.New("hostname field is empty")
|
||||
ErrIPsFieldEmpty = errors.New("ips field is empty")
|
||||
ErrNoNetworkProtocol = errors.New("both TCP and UDP fields are false")
|
||||
ErrWireguardPublicKeyEmpty = errors.New("wireguard public key field is empty")
|
||||
)
|
||||
|
||||
func (s *Server) HasMinimumInformation() (err error) {
|
||||
switch {
|
||||
case s.VPN == "":
|
||||
return ErrVPNFieldEmpty
|
||||
case s.Hostname == "":
|
||||
return ErrHostnameFieldEmpty
|
||||
case len(s.IPs) == 0:
|
||||
return ErrIPsFieldEmpty
|
||||
case !s.TCP && !s.UDP:
|
||||
return ErrNoNetworkProtocol
|
||||
case s.VPN == vpn.Wireguard && s.WgPubKey == "":
|
||||
return ErrWireguardPublicKeyEmpty
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) Equal(other Server) (equal bool) {
|
||||
if !ipsAreEqual(s.IPs, other.IPs) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user