Skip to content

Commit

Permalink
update host fields if host exists already on registration
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek9686 committed Sep 10, 2023
1 parent 2cf4f48 commit b44cf23
Showing 1 changed file with 14 additions and 0 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

0 comments on commit b44cf23

Please sign in to comment.