|
@@ -48,38 +48,8 @@ func getHosts(w http.ResponseWriter, r *http.Request) {
|
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
|
|
return
|
|
|
}
|
|
|
- //isMasterAdmin := r.Header.Get("ismaster") == "yes"
|
|
|
- //user, err := logic.GetUser(r.Header.Get("user"))
|
|
|
- //if err != nil && !isMasterAdmin {
|
|
|
- // logger.Log(0, r.Header.Get("user"), "failed to fetch user: ", err.Error())
|
|
|
- // logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
|
|
- // return
|
|
|
- //}
|
|
|
- // return JSON/API formatted hosts
|
|
|
- //ret := []models.ApiHost{}
|
|
|
apiHosts := logic.GetAllHostsAPI(currentHosts[:])
|
|
|
logger.Log(2, r.Header.Get("user"), "fetched all hosts")
|
|
|
- //for _, host := range apiHosts {
|
|
|
- // nodes := host.Nodes
|
|
|
- // // work on the copy
|
|
|
- // host.Nodes = []string{}
|
|
|
- // for _, nid := range nodes {
|
|
|
- // node, err := logic.GetNodeByID(nid)
|
|
|
- // if err != nil {
|
|
|
- // logger.Log(0, r.Header.Get("user"), "failed to fetch node: ", err.Error())
|
|
|
- // // TODO find the reason for the DB error, skip this node for now
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // if !isMasterAdmin && !logic.UserHasNetworksAccess([]string{node.Network}, user) {
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // host.Nodes = append(host.Nodes, nid)
|
|
|
- // }
|
|
|
- // // add to the response only if has perms to some nodes / networks
|
|
|
- // if len(host.Nodes) > 0 {
|
|
|
- // ret = append(ret, host)
|
|
|
- // }
|
|
|
- //}
|
|
|
logic.SortApiHosts(apiHosts[:])
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
json.NewEncoder(w).Encode(apiHosts)
|
|
@@ -130,14 +100,16 @@ func pull(w http.ResponseWriter, r *http.Request) {
|
|
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
|
|
return
|
|
|
}
|
|
|
- fw, _ := logic.GetFwUpdate(host)
|
|
|
+
|
|
|
serverConf.TrafficKey = key
|
|
|
response := models.HostPull{
|
|
|
Host: *host,
|
|
|
Nodes: logic.GetHostNodes(host),
|
|
|
ServerConfig: serverConf,
|
|
|
Peers: hPU.Peers,
|
|
|
- FwUpdate: fw,
|
|
|
+ }
|
|
|
+ if logic.IsHostActingAsGw(host) {
|
|
|
+ response.FwUpdate, _ = logic.GetFwUpdate(host)
|
|
|
}
|
|
|
|
|
|
logger.Log(1, hostID, "completed a pull")
|