phase-b: add node uuid/alias/ip metadata APIs and node list enrichment
This commit is contained in:
@@ -125,7 +125,7 @@ func main() {
|
||||
}
|
||||
if ac.Kind == "session" && ac.Role == "operator" {
|
||||
path := r.URL.Path
|
||||
if path != "/api/v1/nodes" && path != "/api/v1/sdwans" && path != "/api/v1/sdwan/edit" && path != "/api/v1/connect" && path != "/api/v1/nodes/apps" && path != "/api/v1/nodes/kick" && path != "/api/v1/stats" && path != "/api/v1/health" {
|
||||
if path != "/api/v1/nodes" && path != "/api/v1/sdwans" && path != "/api/v1/sdwan/edit" && path != "/api/v1/connect" && path != "/api/v1/nodes/apps" && path != "/api/v1/nodes/kick" && path != "/api/v1/nodes/alias" && path != "/api/v1/nodes/ip" && path != "/api/v1/stats" && path != "/api/v1/health" {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
fmt.Fprintf(w, `{"error":403,"message":"forbidden"}`)
|
||||
@@ -146,6 +146,39 @@ func main() {
|
||||
}
|
||||
return 0
|
||||
}
|
||||
listNodesOut := func(nodes []*server.NodeInfo, tenantID int64) []map[string]any {
|
||||
out := make([]map[string]any, 0, len(nodes))
|
||||
for _, n := range nodes {
|
||||
item := map[string]any{
|
||||
"name": n.Name,
|
||||
"displayName": n.Name,
|
||||
"publicIP": n.PublicIP,
|
||||
"publicPort": n.PublicPort,
|
||||
"natType": n.NATType,
|
||||
"tenantId": n.TenantID,
|
||||
"version": n.Version,
|
||||
"relayEnabled": n.RelayEnabled,
|
||||
"superRelay": n.SuperRelay,
|
||||
"loginTime": n.LoginTime,
|
||||
"lastHeartbeat": n.LastHeartbeat,
|
||||
"nodeUUID": "",
|
||||
"alias": "",
|
||||
"virtualIP": "",
|
||||
}
|
||||
if tenantID > 0 && srv.Store() != nil {
|
||||
if nc, err := srv.Store().GetNodeCredentialByName(tenantID, n.Name); err == nil && nc != nil {
|
||||
item["nodeUUID"] = nc.NodeUUID
|
||||
item["alias"] = nc.Alias
|
||||
item["virtualIP"] = nc.VirtualIP
|
||||
if nc.Alias != "" {
|
||||
item["displayName"] = nc.Alias
|
||||
}
|
||||
}
|
||||
}
|
||||
out = append(out, item)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/ws", srv.HandleWS)
|
||||
@@ -162,6 +195,8 @@ func main() {
|
||||
mux.HandleFunc("/api/v1/tenants/enroll", srv.HandleTenantEnroll)
|
||||
mux.HandleFunc("/api/v1/enroll/consume", srv.HandleEnrollConsume)
|
||||
mux.HandleFunc("/api/v1/enroll/consume/", srv.HandleEnrollConsume)
|
||||
mux.HandleFunc("/api/v1/nodes/alias", tenantMiddleware(srv.HandleNodeMeta))
|
||||
mux.HandleFunc("/api/v1/nodes/ip", tenantMiddleware(srv.HandleNodeMeta))
|
||||
|
||||
mux.HandleFunc("/api/v1/auth/login", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
@@ -276,11 +311,11 @@ func main() {
|
||||
tenantID := getTenantID(r)
|
||||
if tenantID > 0 {
|
||||
nodes := srv.GetOnlineNodesByTenant(tenantID)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"nodes": nodes})
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"nodes": listNodesOut(nodes, tenantID)})
|
||||
return
|
||||
}
|
||||
nodes := srv.GetOnlineNodes()
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"nodes": nodes})
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"nodes": listNodesOut(nodes, 0)})
|
||||
}))
|
||||
|
||||
mux.HandleFunc("/api/v1/sdwans", tenantMiddleware(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user