Skip to content

Commit

Permalink
NET-383: Set Additional Host Fields From Client Side (#2566)
Browse files Browse the repository at this point in the history
* update static,mtu from client side host update

* update host fields if host exists already on registration
  • Loading branch information
abhishek9686 committed Oct 2, 2023
1 parent 23ad85b commit 3f12117
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions controllers/enrollmentkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions logic/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f12117

Please sign in to comment.