NM-57: Graphs API Forbidden for Platform User (#3577)

* fix(go): permissions for network graph;

* fix(go): allow platform user to get network graph;

* feat(go): allow read only access to host resource to network users.

* feat(go): remove specific check for hosts resource.
This commit is contained in:
Vishal Dalwadi
2025-08-08 22:14:42 +05:30
committed by GitHub
parent e0e0a76563
commit 996410fc61
7 changed files with 80 additions and 32 deletions

View File

@@ -20,7 +20,6 @@ func MetricHandlers(r *mux.Router) {
r.HandleFunc("/api/metrics/{network}", logic.SecurityCheck(true, http.HandlerFunc(getNetworkNodesMetrics))).Methods(http.MethodGet)
r.HandleFunc("/api/metrics", logic.SecurityCheck(true, http.HandlerFunc(getAllMetrics))).Methods(http.MethodGet)
r.HandleFunc("/api/metrics-ext/{network}", logic.SecurityCheck(true, http.HandlerFunc(getNetworkExtMetrics))).Methods(http.MethodGet)
r.HandleFunc("/api/v1/graph/{network}", logic.SecurityCheck(true, http.HandlerFunc(graph))).Methods(http.MethodGet)
}
// get the metrics of a given node
@@ -166,21 +165,3 @@ func getAllMetrics(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(networkMetrics)
}
func graph(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
var params = mux.Vars(r)
network := params["network"]
networkNodes, err := logic.GetNetworkNodes(network)
if err != nil {
logger.Log(1, r.Header.Get("user"), "failed to get network nodes", err.Error())
return
}
networkNodes = logic.AddStaticNodestoList(networkNodes)
// return all the nodes in JSON/API format
apiNodes := logic.GetAllNodesAPIWithLocation(networkNodes[:])
logic.SortApiNodes(apiNodes[:])
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(apiNodes)
}