Quellcode durchsuchen

Use a default PKA

gabrielseibel1 vor 1 Jahr
Ursprung
Commit
c7d54c59ca
2 geänderte Dateien mit 45 neuen und 36 gelöschten Zeilen
  1. 10 5
      migrate/migrate.go
  2. 35 31
      models/host.go

+ 10 - 5
migrate/migrate.go

@@ -2,13 +2,13 @@ package migrate
 
 import (
 	"encoding/json"
-	"time"
+
+	"golang.org/x/exp/slog"
 
 	"github.com/gravitl/netmaker/database"
 	"github.com/gravitl/netmaker/logger"
 	"github.com/gravitl/netmaker/logic"
 	"github.com/gravitl/netmaker/models"
-	"golang.org/x/exp/slog"
 )
 
 // Run - runs all migrations
@@ -39,7 +39,13 @@ func assignSuperAdmin() {
 			user.IsAdmin = false
 			err = logic.UpsertUser(*user)
 			if err != nil {
-				slog.Error("error updating user to superadmin", "user", user.UserName, "error", err.Error())
+				slog.Error(
+					"error updating user to superadmin",
+					"user",
+					user.UserName,
+					"error",
+					err.Error(),
+				)
 				continue
 			} else {
 				createdSuperAdmin = true
@@ -51,7 +57,6 @@ func assignSuperAdmin() {
 	if !createdSuperAdmin {
 		slog.Error("failed to create superadmin!!")
 	}
-
 }
 
 func updateEnrollmentKeys() {
@@ -102,7 +107,7 @@ func updateHosts() {
 			continue
 		}
 		if host.PersistentKeepalive == 0 {
-			host.PersistentKeepalive = 20 * time.Second
+			host.PersistentKeepalive = models.DefaultPersistentKeepAlive
 			if err := logic.UpsertHost(&host); err != nil {
 				logger.Log(0, "failed to upsert host", host.ID.String())
 				continue

+ 35 - 31
models/host.go

@@ -1,11 +1,12 @@
 package models
 
 import (
-	"github.com/google/uuid"
-	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
 	"net"
 	"net/netip"
 	"time"
+
+	"github.com/google/uuid"
+	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
 )
 
 // OS_Types - list of OS types Netmaker cares about
@@ -33,39 +34,42 @@ var NAT_Types = struct {
 }
 
 // WIREGUARD_INTERFACE name of wireguard interface
-const WIREGUARD_INTERFACE = "netmaker"
+const (
+	WIREGUARD_INTERFACE        = "netmaker"
+	DefaultPersistentKeepAlive = 20 * time.Second
+)
 
 // Host - represents a host on the network
 type Host struct {
-	ID                  uuid.UUID        `json:"id" yaml:"id"`
-	Verbosity           int              `json:"verbosity" yaml:"verbosity"`
-	FirewallInUse       string           `json:"firewallinuse" yaml:"firewallinuse"`
-	Version             string           `json:"version" yaml:"version"`
-	IPForwarding        bool             `json:"ipforwarding" yaml:"ipforwarding"`
-	DaemonInstalled     bool             `json:"daemoninstalled" yaml:"daemoninstalled"`
-	AutoUpdate          bool             `json:"autoupdate" yaml:"autoupdate"`
-	HostPass            string           `json:"hostpass" yaml:"hostpass"`
-	Name                string           `json:"name" yaml:"name"`
-	OS                  string           `json:"os" yaml:"os"`
-	Interface           string           `json:"interface" yaml:"interface"`
-	Debug               bool             `json:"debug" yaml:"debug"`
-	ListenPort          int              `json:"listenport" yaml:"listenport"`
-	WgPublicListenPort  int              `json:"wg_public_listen_port" yaml:"wg_public_listen_port"`
-	MTU                 int              `json:"mtu" yaml:"mtu"`
-	PublicKey           wgtypes.Key      `json:"publickey" yaml:"publickey"`
-	MacAddress          net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
-	TrafficKeyPublic    []byte           `json:"traffickeypublic" yaml:"traffickeypublic"`
-	Nodes               []string         `json:"nodes" yaml:"nodes"`
-	Interfaces          []Iface          `json:"interfaces" yaml:"interfaces"`
-	DefaultInterface    string           `json:"defaultinterface" yaml:"defaultinterface"`
-	EndpointIP          net.IP           `json:"endpointip" yaml:"endpointip"`
-	IsDocker            bool             `json:"isdocker" yaml:"isdocker"`
-	IsK8S               bool             `json:"isk8s" yaml:"isk8s"`
-	IsStatic            bool             `json:"isstatic" yaml:"isstatic"`
-	IsDefault           bool             `json:"isdefault" yaml:"isdefault"`
-	NatType             string           `json:"nat_type,omitempty" yaml:"nat_type,omitempty"`
+	ID                  uuid.UUID        `json:"id"                      yaml:"id"`
+	Verbosity           int              `json:"verbosity"               yaml:"verbosity"`
+	FirewallInUse       string           `json:"firewallinuse"           yaml:"firewallinuse"`
+	Version             string           `json:"version"                 yaml:"version"`
+	IPForwarding        bool             `json:"ipforwarding"            yaml:"ipforwarding"`
+	DaemonInstalled     bool             `json:"daemoninstalled"         yaml:"daemoninstalled"`
+	AutoUpdate          bool             `json:"autoupdate"              yaml:"autoupdate"`
+	HostPass            string           `json:"hostpass"                yaml:"hostpass"`
+	Name                string           `json:"name"                    yaml:"name"`
+	OS                  string           `json:"os"                      yaml:"os"`
+	Interface           string           `json:"interface"               yaml:"interface"`
+	Debug               bool             `json:"debug"                   yaml:"debug"`
+	ListenPort          int              `json:"listenport"              yaml:"listenport"`
+	WgPublicListenPort  int              `json:"wg_public_listen_port"   yaml:"wg_public_listen_port"`
+	MTU                 int              `json:"mtu"                     yaml:"mtu"`
+	PublicKey           wgtypes.Key      `json:"publickey"               yaml:"publickey"`
+	MacAddress          net.HardwareAddr `json:"macaddress"              yaml:"macaddress"`
+	TrafficKeyPublic    []byte           `json:"traffickeypublic"        yaml:"traffickeypublic"`
+	Nodes               []string         `json:"nodes"                   yaml:"nodes"`
+	Interfaces          []Iface          `json:"interfaces"              yaml:"interfaces"`
+	DefaultInterface    string           `json:"defaultinterface"        yaml:"defaultinterface"`
+	EndpointIP          net.IP           `json:"endpointip"              yaml:"endpointip"`
+	IsDocker            bool             `json:"isdocker"                yaml:"isdocker"`
+	IsK8S               bool             `json:"isk8s"                   yaml:"isk8s"`
+	IsStatic            bool             `json:"isstatic"                yaml:"isstatic"`
+	IsDefault           bool             `json:"isdefault"               yaml:"isdefault"`
+	NatType             string           `json:"nat_type,omitempty"      yaml:"nat_type,omitempty"`
 	TurnEndpoint        *netip.AddrPort  `json:"turn_endpoint,omitempty" yaml:"turn_endpoint,omitempty"`
-	PersistentKeepalive time.Duration    `json:"persistentkeepalive" yaml:"persistentkeepalive"`
+	PersistentKeepalive time.Duration    `json:"persistentkeepalive"     yaml:"persistentkeepalive"`
 }
 
 // FormatBool converts a boolean to a [yes|no] string