mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +08:00
merge conflicts resolved
This commit is contained in:
@@ -20,6 +20,8 @@ import (
|
||||
|
||||
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}", logic.SecurityCheck(true, http.HandlerFunc(updateHost))).Methods(http.MethodPut)
|
||||
r.HandleFunc("/api/hosts/{hostid}", logic.SecurityCheck(true, http.HandlerFunc(deleteHost))).Methods(http.MethodDelete)
|
||||
r.HandleFunc("/api/hosts/{hostid}/networks/{network}", logic.SecurityCheck(true, http.HandlerFunc(addHostToNetwork))).Methods(http.MethodPost)
|
||||
@@ -53,6 +55,7 @@ func getHosts(w http.ResponseWriter, r *http.Request) {
|
||||
// return JSON/API formatted hosts
|
||||
apiHosts := logic.GetAllHostsAPI(currentHosts[:])
|
||||
logger.Log(2, r.Header.Get("user"), "fetched all hosts")
|
||||
logic.SortApiHosts(apiHosts[:])
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(apiHosts)
|
||||
}
|
||||
@@ -448,9 +451,15 @@ func authenticateHost(response http.ResponseWriter, request *http.Request) {
|
||||
response.Write(successJSONResponse)
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// swagger:route POST /api/hosts/{hostid}/signalpeer signalPeer
|
||||
//
|
||||
// send signal to peer.
|
||||
=======
|
||||
// swagger:route POST /api/hosts/keys host updateAllKeys
|
||||
//
|
||||
// Update keys for a network.
|
||||
>>>>>>> 6abbf075e061ffe58c35b3e75493ba5ffa175022
|
||||
//
|
||||
// Schemes: https
|
||||
//
|
||||
@@ -458,6 +467,7 @@ func authenticateHost(response http.ResponseWriter, request *http.Request) {
|
||||
// oauth
|
||||
//
|
||||
// Responses:
|
||||
<<<<<<< HEAD
|
||||
// 200: nodeResponse
|
||||
func signalPeer(w http.ResponseWriter, r *http.Request) {
|
||||
var params = mux.Vars(r)
|
||||
@@ -512,4 +522,71 @@ func signalPeer(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(signal)
|
||||
=======
|
||||
// 200: networkBodyResponse
|
||||
func updateAllKeys(w http.ResponseWriter, r *http.Request) {
|
||||
var errorResponse = models.ErrorResponse{}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
hosts, err := logic.GetAllHosts()
|
||||
if err != nil {
|
||||
errorResponse.Code = http.StatusBadRequest
|
||||
errorResponse.Message = err.Error()
|
||||
logger.Log(0, r.Header.Get("user"),
|
||||
"error retrieving hosts ", err.Error())
|
||||
logic.ReturnErrorResponse(w, r, errorResponse)
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
hostUpdate := models.HostUpdate{}
|
||||
hostUpdate.Action = models.UpdateKeys
|
||||
for _, host := range hosts {
|
||||
hostUpdate.Host = host
|
||||
logger.Log(2, "updating host", host.ID.String(), " for a key update")
|
||||
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(2, r.Header.Get("user"), "updated keys for all hosts")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
// swagger:route POST /api/hosts/{hostid}keys host updateKeys
|
||||
//
|
||||
// Update keys for a network.
|
||||
//
|
||||
// Schemes: https
|
||||
//
|
||||
// Security:
|
||||
// oauth
|
||||
//
|
||||
// Responses:
|
||||
// 200: networkBodyResponse
|
||||
func updateKeys(w http.ResponseWriter, r *http.Request) {
|
||||
var errorResponse = models.ErrorResponse{}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
var params = mux.Vars(r)
|
||||
hostid := params["hostid"]
|
||||
host, err := logic.GetHost(hostid)
|
||||
if err != nil {
|
||||
logger.Log(0, "failed to retrieve host", hostid, err.Error())
|
||||
errorResponse.Code = http.StatusBadRequest
|
||||
errorResponse.Message = err.Error()
|
||||
logger.Log(0, r.Header.Get("user"),
|
||||
"error retrieving hosts ", err.Error())
|
||||
logic.ReturnErrorResponse(w, r, errorResponse)
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
hostUpdate := models.HostUpdate{
|
||||
Action: models.UpdateKeys,
|
||||
Host: *host,
|
||||
}
|
||||
if err = mq.HostUpdate(&hostUpdate); err != nil {
|
||||
logger.Log(0, "failed to send host key update", host.ID.String(), err.Error())
|
||||
}
|
||||
}()
|
||||
logger.Log(2, r.Header.Get("user"), "updated key on host", host.Name)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
>>>>>>> 6abbf075e061ffe58c35b3e75493ba5ffa175022
|
||||
}
|
||||
|
Reference in New Issue
Block a user