|
@@ -19,23 +19,43 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func hostHandlers(r *mux.Router) {
|
|
func hostHandlers(r *mux.Router) {
|
|
|
- r.HandleFunc("/api/hosts", logic.SecurityCheck(true, http.HandlerFunc(getHosts))).Methods(http.MethodGet)
|
|
|
|
|
- r.HandleFunc("/api/hosts/keys", logic.SecurityCheck(true, http.HandlerFunc(updateAllKeys))).Methods(http.MethodPut)
|
|
|
|
|
- r.HandleFunc("/api/hosts/{hostid}/keys", logic.SecurityCheck(true, http.HandlerFunc(updateKeys))).Methods(http.MethodPut)
|
|
|
|
|
- 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", logic.SecurityCheck(true, http.HandlerFunc(getHosts))).
|
|
|
|
|
+ Methods(http.MethodGet)
|
|
|
|
|
+ r.HandleFunc("/api/hosts/keys", logic.SecurityCheck(true, http.HandlerFunc(updateAllKeys))).
|
|
|
|
|
+ Methods(http.MethodPut)
|
|
|
|
|
+ r.HandleFunc("/api/hosts/{hostid}/keys", logic.SecurityCheck(true, http.HandlerFunc(updateKeys))).
|
|
|
|
|
+ Methods(http.MethodPut)
|
|
|
|
|
+ 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)
|
|
r.HandleFunc("/api/hosts/adm/authenticate", authenticateHost).Methods(http.MethodPost)
|
|
|
- r.HandleFunc("/api/v1/host", Authorize(true, false, "host", http.HandlerFunc(pull))).Methods(http.MethodGet)
|
|
|
|
|
- r.HandleFunc("/api/v1/host/{hostid}/signalpeer", Authorize(true, false, "host", http.HandlerFunc(signalPeer))).Methods(http.MethodPost)
|
|
|
|
|
- r.HandleFunc("/api/v1/fallback/host/{hostid}", Authorize(true, false, "host", http.HandlerFunc(hostUpdateFallback))).Methods(http.MethodPut)
|
|
|
|
|
- r.HandleFunc("/api/emqx/hosts", logic.SecurityCheck(true, http.HandlerFunc(delEmqxHosts))).Methods(http.MethodDelete)
|
|
|
|
|
|
|
+ r.HandleFunc("/api/v1/host", Authorize(true, false, "host", http.HandlerFunc(pull))).
|
|
|
|
|
+ Methods(http.MethodGet)
|
|
|
|
|
+ r.HandleFunc("/api/v1/host/{hostid}/signalpeer", Authorize(true, false, "host", http.HandlerFunc(signalPeer))).
|
|
|
|
|
+ Methods(http.MethodPost)
|
|
|
|
|
+ r.HandleFunc("/api/v1/fallback/host/{hostid}", Authorize(true, false, "host", http.HandlerFunc(hostUpdateFallback))).
|
|
|
|
|
+ Methods(http.MethodPut)
|
|
|
|
|
+ r.HandleFunc("/api/emqx/hosts", logic.SecurityCheck(true, http.HandlerFunc(delEmqxHosts))).
|
|
|
|
|
+ Methods(http.MethodDelete)
|
|
|
r.HandleFunc("/api/v1/auth-register/host", socketHandler)
|
|
r.HandleFunc("/api/v1/auth-register/host", socketHandler)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// @Summary Upgrade a host
|
|
|
|
|
+// @Router /api/hosts/{hostid}/upgrade [put]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Param hostid path string true "Host ID"
|
|
|
|
|
+// @Success 200 {string} string "passed message to upgrade host"
|
|
|
|
|
+// @Failure 500 {object} models.ErrorResponse
|
|
|
// upgrade host is a handler to send upgrade message to a host
|
|
// upgrade host is a handler to send upgrade message to a host
|
|
|
func upgradeHost(w http.ResponseWriter, r *http.Request) {
|
|
func upgradeHost(w http.ResponseWriter, r *http.Request) {
|
|
|
host, err := logic.GetHost(mux.Vars(r)["hostid"])
|
|
host, err := logic.GetHost(mux.Vars(r)["hostid"])
|
|
@@ -52,17 +72,12 @@ func upgradeHost(w http.ResponseWriter, r *http.Request) {
|
|
|
logic.ReturnSuccessResponse(w, r, "passed message to upgrade host")
|
|
logic.ReturnSuccessResponse(w, r, "passed message to upgrade host")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route GET /api/hosts hosts getHosts
|
|
|
|
|
-//
|
|
|
|
|
-// Lists all hosts.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: apiHostSliceResponse
|
|
|
|
|
|
|
+// @Summary List all hosts
|
|
|
|
|
+// @Router /api/hosts [get]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Success 200 {array} models.ApiHost
|
|
|
|
|
+// @Failure 500 {object} models.ErrorResponse
|
|
|
func getHosts(w http.ResponseWriter, r *http.Request) {
|
|
func getHosts(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
currentHosts := []models.Host{}
|
|
currentHosts := []models.Host{}
|
|
@@ -115,23 +130,22 @@ func getHosts(w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(apiHosts)
|
|
json.NewEncoder(w).Encode(apiHosts)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route GET /api/v1/host hosts pullHost
|
|
|
|
|
-//
|
|
|
|
|
-// Used by clients for "pull" command
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: hostPull
|
|
|
|
|
|
|
+// @Summary Used by clients for "pull" command
|
|
|
|
|
+// @Router /api/v1/host [get]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Success 200 {object} models.HostPull
|
|
|
|
|
+// @Failure 500 {object} models.ErrorResponse
|
|
|
func pull(w http.ResponseWriter, r *http.Request) {
|
|
func pull(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
hostID := r.Header.Get(hostIDHeader) // return JSON/API formatted keys
|
|
hostID := r.Header.Get(hostIDHeader) // return JSON/API formatted keys
|
|
|
if len(hostID) == 0 {
|
|
if len(hostID) == 0 {
|
|
|
logger.Log(0, "no host authorized to pull")
|
|
logger.Log(0, "no host authorized to pull")
|
|
|
- logic.ReturnErrorResponse(w, r, logic.FormatError(fmt.Errorf("no host authorized to pull"), "internal"))
|
|
|
|
|
|
|
+ logic.ReturnErrorResponse(
|
|
|
|
|
+ w,
|
|
|
|
|
+ r,
|
|
|
|
|
+ logic.FormatError(fmt.Errorf("no host authorized to pull"), "internal"),
|
|
|
|
|
+ )
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
host, err := logic.GetHost(hostID)
|
|
host, err := logic.GetHost(hostID)
|
|
@@ -191,17 +205,14 @@ func pull(w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(&response)
|
|
json.NewEncoder(w).Encode(&response)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route PUT /api/hosts/{hostid} hosts updateHost
|
|
|
|
|
-//
|
|
|
|
|
-// Updates a Netclient host on Netmaker server.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: apiHostResponse
|
|
|
|
|
|
|
+// @Summary Updates a Netclient host on Netmaker server
|
|
|
|
|
+// @Router /api/hosts/{hostid} [put]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Param hostid path string true "Host ID"
|
|
|
|
|
+// @Param body body models.ApiHost true "New host data"
|
|
|
|
|
+// @Success 200 {object} models.ApiHost
|
|
|
|
|
+// @Failure 500 {object} models.ErrorResponse
|
|
|
func updateHost(w http.ResponseWriter, r *http.Request) {
|
|
func updateHost(w http.ResponseWriter, r *http.Request) {
|
|
|
var newHostData models.ApiHost
|
|
var newHostData models.ApiHost
|
|
|
err := json.NewDecoder(r.Body).Decode(&newHostData)
|
|
err := json.NewDecoder(r.Body).Decode(&newHostData)
|
|
@@ -245,7 +256,13 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
|
|
|
Action: models.UpdateHost,
|
|
Action: models.UpdateHost,
|
|
|
Host: *newHost,
|
|
Host: *newHost,
|
|
|
}); err != nil {
|
|
}); err != nil {
|
|
|
- logger.Log(0, r.Header.Get("user"), "failed to send host update: ", currHost.ID.String(), err.Error())
|
|
|
|
|
|
|
+ logger.Log(
|
|
|
|
|
+ 0,
|
|
|
|
|
+ r.Header.Get("user"),
|
|
|
|
|
+ "failed to send host update: ",
|
|
|
|
|
+ currHost.ID.String(),
|
|
|
|
|
+ err.Error(),
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
go func() {
|
|
go func() {
|
|
|
if err := mq.PublishPeerUpdate(false); err != nil {
|
|
if err := mq.PublishPeerUpdate(false); err != nil {
|
|
@@ -264,17 +281,14 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(apiHostData)
|
|
json.NewEncoder(w).Encode(apiHostData)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route PUT /api/v1/fallback/host/{hostid} hosts hostUpdateFallback
|
|
|
|
|
-//
|
|
|
|
|
-// Updates a Netclient host on Netmaker server.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: apiHostResponse
|
|
|
|
|
|
|
+// @Summary Updates a Netclient host on Netmaker server
|
|
|
|
|
+// @Router /api/v1/fallback/host/{hostid} [put]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Param hostid path string true "Host ID"
|
|
|
|
|
+// @Param body body models.HostUpdate true "Host update data"
|
|
|
|
|
+// @Success 200 {string} string "updated host data"
|
|
|
|
|
+// @Failure 500 {object} models.ErrorResponse
|
|
|
func hostUpdateFallback(w http.ResponseWriter, r *http.Request) {
|
|
func hostUpdateFallback(w http.ResponseWriter, r *http.Request) {
|
|
|
var params = mux.Vars(r)
|
|
var params = mux.Vars(r)
|
|
|
hostid := params["hostid"]
|
|
hostid := params["hostid"]
|
|
@@ -284,7 +298,8 @@ func hostUpdateFallback(w http.ResponseWriter, r *http.Request) {
|
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ var sendPeerUpdate bool
|
|
|
|
|
+ var replacePeers bool
|
|
|
var hostUpdate models.HostUpdate
|
|
var hostUpdate models.HostUpdate
|
|
|
err = json.NewDecoder(r.Body).Decode(&hostUpdate)
|
|
err = json.NewDecoder(r.Body).Decode(&hostUpdate)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -295,35 +310,42 @@ func hostUpdateFallback(w http.ResponseWriter, r *http.Request) {
|
|
|
slog.Info("recieved host update", "name", hostUpdate.Host.Name, "id", hostUpdate.Host.ID)
|
|
slog.Info("recieved host update", "name", hostUpdate.Host.Name, "id", hostUpdate.Host.ID)
|
|
|
switch hostUpdate.Action {
|
|
switch hostUpdate.Action {
|
|
|
case models.CheckIn:
|
|
case models.CheckIn:
|
|
|
- _ = mq.HandleHostCheckin(&hostUpdate.Host, currentHost)
|
|
|
|
|
|
|
+ sendPeerUpdate = mq.HandleHostCheckin(&hostUpdate.Host, currentHost)
|
|
|
|
|
|
|
|
case models.UpdateHost:
|
|
case models.UpdateHost:
|
|
|
-
|
|
|
|
|
- _ = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
|
|
|
|
|
|
|
+ if hostUpdate.Host.PublicKey != currentHost.PublicKey {
|
|
|
|
|
+ //remove old peer entry
|
|
|
|
|
+ replacePeers = true
|
|
|
|
|
+ }
|
|
|
|
|
+ sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
|
|
|
err := logic.UpsertHost(currentHost)
|
|
err := logic.UpsertHost(currentHost)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
slog.Error("failed to update host", "id", currentHost.ID, "error", err)
|
|
slog.Error("failed to update host", "id", currentHost.ID, "error", err)
|
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
case models.UpdateMetrics:
|
|
case models.UpdateMetrics:
|
|
|
mq.UpdateMetricsFallBack(hostUpdate.Node.ID.String(), hostUpdate.NewMetrics)
|
|
mq.UpdateMetricsFallBack(hostUpdate.Node.ID.String(), hostUpdate.NewMetrics)
|
|
|
}
|
|
}
|
|
|
- logic.ReturnSuccessResponse(w, r, "updated host data")
|
|
|
|
|
|
|
|
|
|
|
|
+ if sendPeerUpdate {
|
|
|
|
|
+ err := mq.PublishPeerUpdate(replacePeers)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ slog.Error("failed to publish peer update", "error", err)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ logic.ReturnSuccessResponse(w, r, "updated host data")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route DELETE /api/hosts/{hostid} hosts deleteHost
|
|
|
|
|
-//
|
|
|
|
|
-// Deletes a Netclient host from Netmaker server.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: apiHostResponse
|
|
|
|
|
|
|
+// @Summary Deletes a Netclient host from Netmaker server
|
|
|
|
|
+// @Router /api/hosts/{hostid} [delete]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Param hostid path string true "Host ID"
|
|
|
|
|
+// @Param force query bool false "Force delete"
|
|
|
|
|
+// @Success 200 {object} models.ApiHost
|
|
|
|
|
+// @Failure 500 {object} models.ErrorResponse
|
|
|
func deleteHost(w http.ResponseWriter, r *http.Request) {
|
|
func deleteHost(w http.ResponseWriter, r *http.Request) {
|
|
|
var params = mux.Vars(r)
|
|
var params = mux.Vars(r)
|
|
|
hostid := params["hostid"]
|
|
hostid := params["hostid"]
|
|
@@ -352,14 +374,26 @@ func deleteHost(w http.ResponseWriter, r *http.Request) {
|
|
|
if servercfg.GetBrokerType() == servercfg.EmqxBrokerType {
|
|
if servercfg.GetBrokerType() == servercfg.EmqxBrokerType {
|
|
|
// delete EMQX credentials for host
|
|
// delete EMQX credentials for host
|
|
|
if err := mq.GetEmqxHandler().DeleteEmqxUser(currHost.ID.String()); err != nil {
|
|
if err := mq.GetEmqxHandler().DeleteEmqxUser(currHost.ID.String()); err != nil {
|
|
|
- slog.Error("failed to remove host credentials from EMQX", "id", currHost.ID, "error", err)
|
|
|
|
|
|
|
+ slog.Error(
|
|
|
|
|
+ "failed to remove host credentials from EMQX",
|
|
|
|
|
+ "id",
|
|
|
|
|
+ currHost.ID,
|
|
|
|
|
+ "error",
|
|
|
|
|
+ err,
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if err = mq.HostUpdate(&models.HostUpdate{
|
|
if err = mq.HostUpdate(&models.HostUpdate{
|
|
|
Action: models.DeleteHost,
|
|
Action: models.DeleteHost,
|
|
|
Host: *currHost,
|
|
Host: *currHost,
|
|
|
}); err != nil {
|
|
}); err != nil {
|
|
|
- logger.Log(0, r.Header.Get("user"), "failed to send delete host update: ", currHost.ID.String(), err.Error())
|
|
|
|
|
|
|
+ logger.Log(
|
|
|
|
|
+ 0,
|
|
|
|
|
+ r.Header.Get("user"),
|
|
|
|
|
+ "failed to send delete host update: ",
|
|
|
|
|
+ currHost.ID.String(),
|
|
|
|
|
+ err.Error(),
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
if err = logic.RemoveHost(currHost, forceDelete); err != nil {
|
|
if err = logic.RemoveHost(currHost, forceDelete); err != nil {
|
|
|
logger.Log(0, r.Header.Get("user"), "failed to delete a host:", err.Error())
|
|
logger.Log(0, r.Header.Get("user"), "failed to delete a host:", err.Error())
|
|
@@ -373,23 +407,25 @@ func deleteHost(w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(apiHostData)
|
|
json.NewEncoder(w).Encode(apiHostData)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route POST /api/hosts/{hostid}/networks/{network} hosts addHostToNetwork
|
|
|
|
|
-//
|
|
|
|
|
-// Given a network, a host is added to the network.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: okResponse
|
|
|
|
|
|
|
+// @Summary To Add Host To Network
|
|
|
|
|
+// @Router /api/hosts/{hostid}/networks/{network} [post]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Param hostid path string true "Host ID"
|
|
|
|
|
+// @Param network path string true "Network name"
|
|
|
|
|
+// @Success 200 {string} string "OK"
|
|
|
|
|
+// @Failure 500 {object} models.ErrorResponse
|
|
|
func addHostToNetwork(w http.ResponseWriter, r *http.Request) {
|
|
func addHostToNetwork(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
var params = mux.Vars(r)
|
|
var params = mux.Vars(r)
|
|
|
hostid := params["hostid"]
|
|
hostid := params["hostid"]
|
|
|
network := params["network"]
|
|
network := params["network"]
|
|
|
if hostid == "" || network == "" {
|
|
if hostid == "" || network == "" {
|
|
|
- logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("hostid or network cannot be empty"), "badrequest"))
|
|
|
|
|
|
|
+ logic.ReturnErrorResponse(
|
|
|
|
|
+ w,
|
|
|
|
|
+ r,
|
|
|
|
|
+ logic.FormatError(errors.New("hostid or network cannot be empty"), "badrequest"),
|
|
|
|
|
+ )
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
// confirm host exists
|
|
// confirm host exists
|
|
@@ -402,7 +438,14 @@ func addHostToNetwork(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
newNode, err := logic.UpdateHostNetwork(currHost, network, true)
|
|
newNode, err := logic.UpdateHostNetwork(currHost, network, true)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- logger.Log(0, r.Header.Get("user"), "failed to add host to network:", hostid, network, err.Error())
|
|
|
|
|
|
|
+ logger.Log(
|
|
|
|
|
+ 0,
|
|
|
|
|
+ r.Header.Get("user"),
|
|
|
|
|
+ "failed to add host to network:",
|
|
|
|
|
+ hostid,
|
|
|
|
|
+ network,
|
|
|
|
|
+ err.Error(),
|
|
|
|
|
+ )
|
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -424,21 +467,23 @@ func addHostToNetwork(w http.ResponseWriter, r *http.Request) {
|
|
|
logic.SetDNS()
|
|
logic.SetDNS()
|
|
|
}
|
|
}
|
|
|
}()
|
|
}()
|
|
|
- logger.Log(2, r.Header.Get("user"), fmt.Sprintf("added host %s to network %s", currHost.Name, network))
|
|
|
|
|
|
|
+ logger.Log(
|
|
|
|
|
+ 2,
|
|
|
|
|
+ r.Header.Get("user"),
|
|
|
|
|
+ fmt.Sprintf("added host %s to network %s", currHost.Name, network),
|
|
|
|
|
+ )
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route DELETE /api/hosts/{hostid}/networks/{network} hosts deleteHostFromNetwork
|
|
|
|
|
-//
|
|
|
|
|
-// Given a network, a host is removed from the network.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: okResponse
|
|
|
|
|
|
|
+// @Summary To Remove Host from Network
|
|
|
|
|
+// @Router /api/hosts/{hostid}/networks/{network} [delete]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Param hostid path string true "Host ID"
|
|
|
|
|
+// @Param network path string true "Network name"
|
|
|
|
|
+// @Param force query bool false "Force delete"
|
|
|
|
|
+// @Success 200 {string} string "OK"
|
|
|
|
|
+// @Failure 500 {object} models.ErrorResponse
|
|
|
func deleteHostFromNetwork(w http.ResponseWriter, r *http.Request) {
|
|
func deleteHostFromNetwork(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
var params = mux.Vars(r)
|
|
var params = mux.Vars(r)
|
|
@@ -446,7 +491,11 @@ func deleteHostFromNetwork(w http.ResponseWriter, r *http.Request) {
|
|
|
network := params["network"]
|
|
network := params["network"]
|
|
|
forceDelete := r.URL.Query().Get("force") == "true"
|
|
forceDelete := r.URL.Query().Get("force") == "true"
|
|
|
if hostid == "" || network == "" {
|
|
if hostid == "" || network == "" {
|
|
|
- logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("hostid or network cannot be empty"), "badrequest"))
|
|
|
|
|
|
|
+ logic.ReturnErrorResponse(
|
|
|
|
|
+ w,
|
|
|
|
|
+ r,
|
|
|
|
|
+ logic.FormatError(errors.New("hostid or network cannot be empty"), "badrequest"),
|
|
|
|
|
+ )
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
// confirm host exists
|
|
// confirm host exists
|
|
@@ -456,14 +505,29 @@ func deleteHostFromNetwork(w http.ResponseWriter, r *http.Request) {
|
|
|
// check if there is any daemon nodes that needs to be deleted
|
|
// check if there is any daemon nodes that needs to be deleted
|
|
|
node, err := logic.GetNodeByHostRef(hostid, network)
|
|
node, err := logic.GetNodeByHostRef(hostid, network)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- slog.Error("couldn't get node for host", "hostid", hostid, "network", network, "error", err)
|
|
|
|
|
|
|
+ slog.Error(
|
|
|
|
|
+ "couldn't get node for host",
|
|
|
|
|
+ "hostid",
|
|
|
|
|
+ hostid,
|
|
|
|
|
+ "network",
|
|
|
|
|
+ network,
|
|
|
|
|
+ "error",
|
|
|
|
|
+ err,
|
|
|
|
|
+ )
|
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
if err = logic.DeleteNodeByID(&node); err != nil {
|
|
if err = logic.DeleteNodeByID(&node); err != nil {
|
|
|
slog.Error("failed to force delete daemon node",
|
|
slog.Error("failed to force delete daemon node",
|
|
|
"nodeid", node.ID.String(), "hostid", hostid, "network", network, "error", err)
|
|
"nodeid", node.ID.String(), "hostid", hostid, "network", network, "error", err)
|
|
|
- logic.ReturnErrorResponse(w, r, logic.FormatError(fmt.Errorf("failed to force delete daemon node: "+err.Error()), "internal"))
|
|
|
|
|
|
|
+ logic.ReturnErrorResponse(
|
|
|
|
|
+ w,
|
|
|
|
|
+ r,
|
|
|
|
|
+ logic.FormatError(
|
|
|
|
|
+ fmt.Errorf("failed to force delete daemon node: "+err.Error()),
|
|
|
|
|
+ "internal",
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
logic.ReturnSuccessResponse(w, r, "force deleted daemon node successfully")
|
|
logic.ReturnSuccessResponse(w, r, "force deleted daemon node successfully")
|
|
@@ -481,20 +545,42 @@ func deleteHostFromNetwork(w http.ResponseWriter, r *http.Request) {
|
|
|
// force cleanup the node
|
|
// force cleanup the node
|
|
|
node, err := logic.GetNodeByHostRef(hostid, network)
|
|
node, err := logic.GetNodeByHostRef(hostid, network)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- slog.Error("couldn't get node for host", "hostid", hostid, "network", network, "error", err)
|
|
|
|
|
|
|
+ slog.Error(
|
|
|
|
|
+ "couldn't get node for host",
|
|
|
|
|
+ "hostid",
|
|
|
|
|
+ hostid,
|
|
|
|
|
+ "network",
|
|
|
|
|
+ network,
|
|
|
|
|
+ "error",
|
|
|
|
|
+ err,
|
|
|
|
|
+ )
|
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
if err = logic.DeleteNodeByID(&node); err != nil {
|
|
if err = logic.DeleteNodeByID(&node); err != nil {
|
|
|
slog.Error("failed to force delete daemon node",
|
|
slog.Error("failed to force delete daemon node",
|
|
|
"nodeid", node.ID.String(), "hostid", hostid, "network", network, "error", err)
|
|
"nodeid", node.ID.String(), "hostid", hostid, "network", network, "error", err)
|
|
|
- logic.ReturnErrorResponse(w, r, logic.FormatError(fmt.Errorf("failed to force delete daemon node: "+err.Error()), "internal"))
|
|
|
|
|
|
|
+ logic.ReturnErrorResponse(
|
|
|
|
|
+ w,
|
|
|
|
|
+ r,
|
|
|
|
|
+ logic.FormatError(
|
|
|
|
|
+ fmt.Errorf("failed to force delete daemon node: "+err.Error()),
|
|
|
|
|
+ "internal",
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
logic.ReturnSuccessResponse(w, r, "force deleted daemon node successfully")
|
|
logic.ReturnSuccessResponse(w, r, "force deleted daemon node successfully")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- logger.Log(0, r.Header.Get("user"), "failed to remove host from network:", hostid, network, err.Error())
|
|
|
|
|
|
|
+ logger.Log(
|
|
|
|
|
+ 0,
|
|
|
|
|
+ r.Header.Get("user"),
|
|
|
|
|
+ "failed to remove host from network:",
|
|
|
|
|
+ hostid,
|
|
|
|
|
+ network,
|
|
|
|
|
+ err.Error(),
|
|
|
|
|
+ )
|
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -504,7 +590,11 @@ func deleteHostFromNetwork(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
}
|
|
|
logger.Log(1, "deleting node", node.ID.String(), "from host", currHost.Name)
|
|
logger.Log(1, "deleting node", node.ID.String(), "from host", currHost.Name)
|
|
|
if err := logic.DeleteNode(node, forceDelete); err != nil {
|
|
if err := logic.DeleteNode(node, forceDelete); err != nil {
|
|
|
- logic.ReturnErrorResponse(w, r, logic.FormatError(fmt.Errorf("failed to delete node"), "internal"))
|
|
|
|
|
|
|
+ logic.ReturnErrorResponse(
|
|
|
|
|
+ w,
|
|
|
|
|
+ r,
|
|
|
|
|
+ logic.FormatError(fmt.Errorf("failed to delete node"), "internal"),
|
|
|
|
|
+ )
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
go func() {
|
|
go func() {
|
|
@@ -513,21 +603,23 @@ func deleteHostFromNetwork(w http.ResponseWriter, r *http.Request) {
|
|
|
logic.SetDNS()
|
|
logic.SetDNS()
|
|
|
}
|
|
}
|
|
|
}()
|
|
}()
|
|
|
- logger.Log(2, r.Header.Get("user"), fmt.Sprintf("removed host %s from network %s", currHost.Name, network))
|
|
|
|
|
|
|
+ logger.Log(
|
|
|
|
|
+ 2,
|
|
|
|
|
+ r.Header.Get("user"),
|
|
|
|
|
+ fmt.Sprintf("removed host %s from network %s", currHost.Name, network),
|
|
|
|
|
+ )
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route POST /api/hosts/adm/authenticate authenticate authenticateHost
|
|
|
|
|
-//
|
|
|
|
|
-// Host based authentication for making further API calls.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: successResponse
|
|
|
|
|
|
|
+// @Summary To Fetch Auth Token for a Host
|
|
|
|
|
+// @Router /api/hosts/adm/authenticate [post]
|
|
|
|
|
+// @Tags Auth
|
|
|
|
|
+// @Accept json
|
|
|
|
|
+// @Param body body models.AuthParams true "Authentication parameters"
|
|
|
|
|
+// @Success 200 {object} models.SuccessResponse
|
|
|
|
|
+// @Failure 400 {object} models.ErrorResponse
|
|
|
|
|
+// @Failure 401 {object} models.ErrorResponse
|
|
|
|
|
+// @Failure 500 {object} models.ErrorResponse
|
|
|
func authenticateHost(response http.ResponseWriter, request *http.Request) {
|
|
func authenticateHost(response http.ResponseWriter, request *http.Request) {
|
|
|
var authRequest models.AuthParams
|
|
var authRequest models.AuthParams
|
|
|
var errorResponse = models.ErrorResponse{
|
|
var errorResponse = models.ErrorResponse{
|
|
@@ -563,7 +655,7 @@ func authenticateHost(response http.ResponseWriter, request *http.Request) {
|
|
|
errorResponse.Code = http.StatusBadRequest
|
|
errorResponse.Code = http.StatusBadRequest
|
|
|
errorResponse.Message = err.Error()
|
|
errorResponse.Message = err.Error()
|
|
|
logger.Log(0, request.Header.Get("user"),
|
|
logger.Log(0, request.Header.Get("user"),
|
|
|
- "error retrieving host: ", err.Error())
|
|
|
|
|
|
|
+ "error retrieving host: ", authRequest.ID, err.Error())
|
|
|
logic.ReturnErrorResponse(response, request, errorResponse)
|
|
logic.ReturnErrorResponse(response, request, errorResponse)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -619,17 +711,14 @@ func authenticateHost(response http.ResponseWriter, request *http.Request) {
|
|
|
response.Write(successJSONResponse)
|
|
response.Write(successJSONResponse)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route POST /api/hosts/{hostid}/signalpeer hosts signalPeer
|
|
|
|
|
-//
|
|
|
|
|
-// send signal to peer.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: signal
|
|
|
|
|
|
|
+// @Summary Send signal to peer
|
|
|
|
|
+// @Router /api/v1/host/{hostid}/signalpeer [post]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Param hostid path string true "Host ID"
|
|
|
|
|
+// @Param body body models.Signal true "Signal data"
|
|
|
|
|
+// @Success 200 {object} models.Signal
|
|
|
|
|
+// @Failure 400 {object} models.ErrorResponse
|
|
|
func signalPeer(w http.ResponseWriter, r *http.Request) {
|
|
func signalPeer(w http.ResponseWriter, r *http.Request) {
|
|
|
var params = mux.Vars(r)
|
|
var params = mux.Vars(r)
|
|
|
hostid := params["hostid"]
|
|
hostid := params["hostid"]
|
|
@@ -657,7 +746,11 @@ func signalPeer(w http.ResponseWriter, r *http.Request) {
|
|
|
signal.IsPro = servercfg.IsPro
|
|
signal.IsPro = servercfg.IsPro
|
|
|
peerHost, err := logic.GetHost(signal.ToHostID)
|
|
peerHost, err := logic.GetHost(signal.ToHostID)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("failed to signal, peer not found"), "badrequest"))
|
|
|
|
|
|
|
+ logic.ReturnErrorResponse(
|
|
|
|
|
+ w,
|
|
|
|
|
+ r,
|
|
|
|
|
+ logic.FormatError(errors.New("failed to signal, peer not found"), "badrequest"),
|
|
|
|
|
+ )
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
err = mq.HostUpdate(&models.HostUpdate{
|
|
err = mq.HostUpdate(&models.HostUpdate{
|
|
@@ -666,7 +759,14 @@ func signalPeer(w http.ResponseWriter, r *http.Request) {
|
|
|
Signal: signal,
|
|
Signal: signal,
|
|
|
})
|
|
})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("failed to publish signal to peer: "+err.Error()), "badrequest"))
|
|
|
|
|
|
|
+ logic.ReturnErrorResponse(
|
|
|
|
|
+ w,
|
|
|
|
|
+ r,
|
|
|
|
|
+ logic.FormatError(
|
|
|
|
|
+ errors.New("failed to publish signal to peer: "+err.Error()),
|
|
|
|
|
+ "badrequest",
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -674,17 +774,12 @@ func signalPeer(w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(signal)
|
|
json.NewEncoder(w).Encode(signal)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route POST /api/hosts/keys hosts updateAllKeys
|
|
|
|
|
-//
|
|
|
|
|
-// Update keys for a network.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: networkBodyResponse
|
|
|
|
|
|
|
+// @Summary Update keys for all hosts
|
|
|
|
|
+// @Router /api/hosts/keys [put]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Success 200 {string} string "OK"
|
|
|
|
|
+// @Failure 400 {object} models.ErrorResponse
|
|
|
func updateAllKeys(w http.ResponseWriter, r *http.Request) {
|
|
func updateAllKeys(w http.ResponseWriter, r *http.Request) {
|
|
|
var errorResponse = models.ErrorResponse{}
|
|
var errorResponse = models.ErrorResponse{}
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
@@ -704,7 +799,12 @@ func updateAllKeys(w http.ResponseWriter, r *http.Request) {
|
|
|
hostUpdate.Host = host
|
|
hostUpdate.Host = host
|
|
|
logger.Log(2, "updating host", host.ID.String(), " for a key update")
|
|
logger.Log(2, "updating host", host.ID.String(), " for a key update")
|
|
|
if err = mq.HostUpdate(&hostUpdate); err != nil {
|
|
if err = mq.HostUpdate(&hostUpdate); err != nil {
|
|
|
- logger.Log(0, "failed to send update to node during a network wide key update", host.ID.String(), err.Error())
|
|
|
|
|
|
|
+ logger.Log(
|
|
|
|
|
+ 0,
|
|
|
|
|
+ "failed to send update to node during a network wide key update",
|
|
|
|
|
+ host.ID.String(),
|
|
|
|
|
+ err.Error(),
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}()
|
|
}()
|
|
@@ -712,17 +812,13 @@ func updateAllKeys(w http.ResponseWriter, r *http.Request) {
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route POST /api/hosts/{hostid}keys hosts updateKeys
|
|
|
|
|
-//
|
|
|
|
|
-// Update keys for a network.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: networkBodyResponse
|
|
|
|
|
|
|
+// @Summary Update keys for a host
|
|
|
|
|
+// @Router /api/hosts/{hostid}/keys [put]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Param hostid path string true "Host ID"
|
|
|
|
|
+// @Success 200 {string} string "OK"
|
|
|
|
|
+// @Failure 400 {object} models.ErrorResponse
|
|
|
func updateKeys(w http.ResponseWriter, r *http.Request) {
|
|
func updateKeys(w http.ResponseWriter, r *http.Request) {
|
|
|
var errorResponse = models.ErrorResponse{}
|
|
var errorResponse = models.ErrorResponse{}
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
@@ -751,17 +847,13 @@ func updateKeys(w http.ResponseWriter, r *http.Request) {
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route POST /api/hosts/{hostid}/sync hosts synchost
|
|
|
|
|
-//
|
|
|
|
|
-// Requests a host to pull.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: networkBodyResponse
|
|
|
|
|
|
|
+// @Summary Requests a host to pull
|
|
|
|
|
+// @Router /api/hosts/{hostid}/sync [post]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Param hostid path string true "Host ID"
|
|
|
|
|
+// @Success 200 {string} string "OK"
|
|
|
|
|
+// @Failure 400 {object} models.ErrorResponse
|
|
|
func syncHost(w http.ResponseWriter, r *http.Request) {
|
|
func syncHost(w http.ResponseWriter, r *http.Request) {
|
|
|
hostId := mux.Vars(r)["hostid"]
|
|
hostId := mux.Vars(r)["hostid"]
|
|
|
|
|
|
|
@@ -791,17 +883,12 @@ func syncHost(w http.ResponseWriter, r *http.Request) {
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// swagger:route DELETE /api/emqx/hosts hosts delEmqxHosts
|
|
|
|
|
-//
|
|
|
|
|
-// Lists all hosts.
|
|
|
|
|
-//
|
|
|
|
|
-// Schemes: https
|
|
|
|
|
-//
|
|
|
|
|
-// Security:
|
|
|
|
|
-// oauth
|
|
|
|
|
-//
|
|
|
|
|
-// Responses:
|
|
|
|
|
-// 200: apiHostResponse
|
|
|
|
|
|
|
+// @Summary Deletes all EMQX hosts
|
|
|
|
|
+// @Router /api/emqx/hosts [delete]
|
|
|
|
|
+// @Tags Hosts
|
|
|
|
|
+// @Security oauth
|
|
|
|
|
+// @Success 200 {string} string "deleted hosts data on emqx"
|
|
|
|
|
+// @Failure 500 {object} models.ErrorResponse
|
|
|
func delEmqxHosts(w http.ResponseWriter, r *http.Request) {
|
|
func delEmqxHosts(w http.ResponseWriter, r *http.Request) {
|
|
|
currentHosts, err := logic.GetAllHosts()
|
|
currentHosts, err := logic.GetAllHosts()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -817,7 +904,13 @@ func delEmqxHosts(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
}
|
|
|
err = mq.GetEmqxHandler().DeleteEmqxUser(servercfg.GetMqUserName())
|
|
err = mq.GetEmqxHandler().DeleteEmqxUser(servercfg.GetMqUserName())
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- slog.Error("failed to remove server credentials from EMQX", "user", servercfg.GetMqUserName(), "error", err)
|
|
|
|
|
|
|
+ slog.Error(
|
|
|
|
|
+ "failed to remove server credentials from EMQX",
|
|
|
|
|
+ "user",
|
|
|
|
|
+ servercfg.GetMqUserName(),
|
|
|
|
|
+ "error",
|
|
|
|
|
+ err,
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
logic.ReturnSuccessResponse(w, r, "deleted hosts data on emqx")
|
|
logic.ReturnSuccessResponse(w, r, "deleted hosts data on emqx")
|
|
|
}
|
|
}
|