mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-06 13:14:24 +08:00
Add handler that sends MQ msg to upgrade a host (#2582)
This commit is contained in:
parent
bfc61fa359
commit
23ad85bd8c
2 changed files with 30 additions and 11 deletions
|
@ -23,6 +23,7 @@ func hostHandlers(r *mux.Router) {
|
|||
r.HandleFunc("/api/hosts/{hostid}/sync", logic.SecurityCheck(true, http.HandlerFunc(syncHost))).Methods(http.MethodPost)
|
||||
r.HandleFunc("/api/hosts/{hostid}", logic.SecurityCheck(true, http.HandlerFunc(updateHost))).Methods(http.MethodPut)
|
||||
r.HandleFunc("/api/hosts/{hostid}", Authorize(true, false, "all", http.HandlerFunc(deleteHost))).Methods(http.MethodDelete)
|
||||
r.HandleFunc("/api/hosts/{hostid}/upgrade", logic.SecurityCheck(true, http.HandlerFunc(upgradeHost))).Methods(http.MethodPut)
|
||||
r.HandleFunc("/api/hosts/{hostid}/networks/{network}", logic.SecurityCheck(true, http.HandlerFunc(addHostToNetwork))).Methods(http.MethodPost)
|
||||
r.HandleFunc("/api/hosts/{hostid}/networks/{network}", logic.SecurityCheck(true, http.HandlerFunc(deleteHostFromNetwork))).Methods(http.MethodDelete)
|
||||
r.HandleFunc("/api/hosts/adm/authenticate", authenticateHost).Methods(http.MethodPost)
|
||||
|
@ -31,6 +32,22 @@ func hostHandlers(r *mux.Router) {
|
|||
r.HandleFunc("/api/v1/auth-register/host", socketHandler)
|
||||
}
|
||||
|
||||
// upgrade host is a handler to send upgrade message to a host
|
||||
func upgradeHost(w http.ResponseWriter, r *http.Request) {
|
||||
host, err := logic.GetHost(mux.Vars(r)["hostid"])
|
||||
if err != nil {
|
||||
slog.Error("failed to find host", "error", err)
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "notfound"))
|
||||
return
|
||||
}
|
||||
if err := mq.HostUpdate(&models.HostUpdate{Action: models.Upgrade, Host: *host}); err != nil {
|
||||
slog.Error("failed to upgrade host", "error", err)
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
logic.ReturnSuccessResponse(w, r, "passed message to upgrade host")
|
||||
}
|
||||
|
||||
// swagger:route GET /api/hosts hosts getHosts
|
||||
//
|
||||
// Lists all hosts.
|
||||
|
|
|
@ -89,26 +89,28 @@ func ParseBool(s string) bool {
|
|||
type HostMqAction string
|
||||
|
||||
const (
|
||||
// Upgrade - const to request host to update it's client
|
||||
Upgrade HostMqAction = "UPGRADE"
|
||||
// SignalHost - const for host signal action
|
||||
SignalHost = "SIGNAL_HOST"
|
||||
SignalHost HostMqAction = "SIGNAL_HOST"
|
||||
// UpdateHost - constant for host update action
|
||||
UpdateHost = "UPDATE_HOST"
|
||||
UpdateHost HostMqAction = "UPDATE_HOST"
|
||||
// DeleteHost - constant for host delete action
|
||||
DeleteHost = "DELETE_HOST"
|
||||
DeleteHost HostMqAction = "DELETE_HOST"
|
||||
// JoinHostToNetwork - constant for host network join action
|
||||
JoinHostToNetwork = "JOIN_HOST_TO_NETWORK"
|
||||
JoinHostToNetwork HostMqAction = "JOIN_HOST_TO_NETWORK"
|
||||
// Acknowledgement - ACK response for hosts
|
||||
Acknowledgement = "ACK"
|
||||
Acknowledgement HostMqAction = "ACK"
|
||||
// RequestAck - request an ACK
|
||||
RequestAck = "REQ_ACK"
|
||||
RequestAck HostMqAction = "REQ_ACK"
|
||||
// CheckIn - update last check in times and public address and interfaces
|
||||
CheckIn = "CHECK_IN"
|
||||
// REGISTER_WITH_TURN - registers host with turn server if configured
|
||||
RegisterWithTurn = "REGISTER_WITH_TURN"
|
||||
CheckIn HostMqAction = "CHECK_IN"
|
||||
// RegisterWithTurn - registers host with turn server if configured
|
||||
RegisterWithTurn HostMqAction = "REGISTER_WITH_TURN"
|
||||
// UpdateKeys - update wireguard private/public keys
|
||||
UpdateKeys = "UPDATE_KEYS"
|
||||
UpdateKeys HostMqAction = "UPDATE_KEYS"
|
||||
// RequestPull - request a pull from a host
|
||||
RequestPull = "REQ_PULL"
|
||||
RequestPull HostMqAction = "REQ_PULL"
|
||||
)
|
||||
|
||||
// SignalAction - turn peer signal action
|
||||
|
|
Loading…
Add table
Reference in a new issue