diff --git a/controllers/enrollmentkeys.go b/controllers/enrollmentkeys.go index 78b0f6b63..63aca97d4 100644 --- a/controllers/enrollmentkeys.go +++ b/controllers/enrollmentkeys.go @@ -13,6 +13,7 @@ import ( "github.com/gravitl/netmaker/models" "github.com/gravitl/netmaker/mq" "github.com/gravitl/netmaker/servercfg" + "golang.org/x/exp/slog" ) func enrollmentKeyHandlers(r *mux.Router) { @@ -223,6 +224,19 @@ func handleHostRegister(w http.ResponseWriter, r *http.Request) { } } enrollmentKey.Networks = networksToAdd + currHost, err := logic.GetHost(newHost.ID.String()) + if err != nil { + slog.Error("failed registration", "hostID", newHost.ID.String(), "hostName", newHost.Name, "error", err.Error()) + logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal")) + return + } + logic.UpdateHostFromClient(&newHost, currHost) + err = logic.UpsertHost(currHost) + if err != nil { + slog.Error("failed to update host", "id", currHost.ID, "error", err) + logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal")) + return + } } // ready the response server := servercfg.GetServerInfo() diff --git a/logic/hosts.go b/logic/hosts.go index 90e5d588f..e17c6f1e7 100644 --- a/logic/hosts.go +++ b/logic/hosts.go @@ -242,9 +242,9 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool) currHost.Debug = newHost.Debug currHost.Verbosity = newHost.Verbosity currHost.Version = newHost.Version - if newHost.Name != "" { - currHost.Name = newHost.Name - } + currHost.IsStatic = newHost.IsStatic + currHost.MTU = newHost.MTU + currHost.Name = newHost.Name if len(newHost.NatType) > 0 && newHost.NatType != currHost.NatType { currHost.NatType = newHost.NatType sendPeerUpdate = true