Преглед изворни кода

Adapt migration-related code to node->host PKA

gabrielseibel1 пре 2 година
родитељ
комит
10c34168d6
3 измењених фајлова са 24 додато и 5 уклоњено
  1. 1 1
      controllers/migrate.go
  2. 23 0
      migrate/migrate.go
  3. 0 4
      swagger.yml

+ 1 - 1
controllers/migrate.go

@@ -65,6 +65,7 @@ func migrate(w http.ResponseWriter, r *http.Request) {
 			host.Name = data.HostName
 			host.HostPass = data.Password
 			host.OS = data.OS
+			host.PersistentKeepalive = time.Duration(legacy.PersistentKeepalive)
 			if err := logic.CreateHost(&host); err != nil {
 				slog.Error("create host", "error", err)
 				logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
@@ -198,7 +199,6 @@ func convertLegacyNode(legacy models.LegacyNode, hostID uuid.UUID) models.Node {
 	node.IsRelay = false
 	node.RelayedNodes = []string{}
 	node.DNSOn = models.ParseBool(legacy.DNSOn)
-	node.PersistentKeepalive = time.Duration(int64(time.Second) * int64(legacy.PersistentKeepalive))
 	node.LastModified = time.Now()
 	node.ExpirationDateTime = time.Unix(legacy.ExpirationDateTime, 0)
 	node.EgressGatewayNatEnabled = models.ParseBool(legacy.EgressGatewayNatEnabled)

+ 23 - 0
migrate/migrate.go

@@ -2,6 +2,7 @@ package migrate
 
 import (
 	"encoding/json"
+	"time"
 
 	"github.com/gravitl/netmaker/database"
 	"github.com/gravitl/netmaker/logger"
@@ -14,6 +15,7 @@ import (
 func Run() {
 	updateEnrollmentKeys()
 	assignSuperAdmin()
+	updateHosts()
 }
 
 func assignSuperAdmin() {
@@ -87,3 +89,24 @@ func updateEnrollmentKeys() {
 
 	}
 }
+
+func updateHosts() {
+	rows, err := database.FetchRecords(database.HOSTS_TABLE_NAME)
+	if err != nil {
+		logger.Log(0, "failed to fetch database records for hosts")
+	}
+	for _, row := range rows {
+		var host models.Host
+		if err := json.Unmarshal([]byte(row), &host); err != nil {
+			logger.Log(0, "failed to unmarshal database row to host", "row", row)
+			continue
+		}
+		if host.PersistentKeepalive == 0 {
+			host.PersistentKeepalive = 20 * time.Millisecond
+			if err := logic.UpsertHost(&host); err != nil {
+				logger.Log(0, "failed to upsert host", host.ID.String())
+				continue
+			}
+		}
+	}
+}

+ 0 - 4
swagger.yml

@@ -1207,8 +1207,6 @@ components:
                   type: array
                   items:
                     type: string
-                PersistentKeepalive:
-                  type: integer
                 IsHub:
                   type: boolean
                 AccessKey:
@@ -1382,8 +1380,6 @@ components:
                   type: string
                 DNSOn:
                   type: boolean
-                PersistentKeepaliveInterval:
-                  type: integer
         network:
             type: object
             properties: