mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-18 11:04:22 +08:00
add static nodes to api resp
This commit is contained in:
parent
287bcd8abc
commit
b41353b415
5 changed files with 48 additions and 3 deletions
|
@ -362,6 +362,8 @@ func getAllNodes(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if !userPlatformRole.FullAccess {
|
||||
nodes = logic.GetFilteredNodesByUserAccess(*user, nodes)
|
||||
} else {
|
||||
nodes = logic.AddStaticNodestoList(nodes)
|
||||
}
|
||||
}
|
||||
// return all the nodes in JSON/API format
|
||||
|
|
|
@ -529,6 +529,25 @@ func GetExtclientAllowedIPs(client models.ExtClient) (allowedIPs []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetStaticNodesByNetwork(network models.NetworkID) (staticNode []models.Node) {
|
||||
extClients, err := GetAllExtClients()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, extI := range extClients {
|
||||
if extI.Network == network.String() {
|
||||
n := models.Node{
|
||||
IsStatic: true,
|
||||
StaticNode: extI,
|
||||
IsUserNode: extI.RemoteAccessClientID != "",
|
||||
}
|
||||
staticNode = append(staticNode, n)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func GetStaticNodesByGw(gwNode models.Node) (staticNode []models.Node) {
|
||||
extClients, err := GetAllExtClients()
|
||||
if err != nil {
|
||||
|
@ -536,7 +555,12 @@ func GetStaticNodesByGw(gwNode models.Node) (staticNode []models.Node) {
|
|||
}
|
||||
for _, extI := range extClients {
|
||||
if extI.IngressGatewayID == gwNode.ID.String() {
|
||||
staticNode = append(staticNode, models.Node{})
|
||||
n := models.Node{
|
||||
IsStatic: true,
|
||||
StaticNode: extI,
|
||||
IsUserNode: extI.RemoteAccessClientID != "",
|
||||
}
|
||||
staticNode = append(staticNode, n)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
@ -378,6 +378,20 @@ func GetAllNodes() ([]models.Node, error) {
|
|||
return nodes, nil
|
||||
}
|
||||
|
||||
func AddStaticNodestoList(nodes []models.Node) []models.Node {
|
||||
netMap := make(map[string]struct{})
|
||||
for _, node := range nodes {
|
||||
if _, ok := netMap[node.Network]; ok {
|
||||
continue
|
||||
}
|
||||
if node.IsIngressGateway {
|
||||
nodes = append(nodes, GetStaticNodesByNetwork(models.NetworkID(node.Network))...)
|
||||
netMap[node.Network] = struct{}{}
|
||||
}
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// GetNetworkByNode - gets the network model from a node
|
||||
func GetNetworkByNode(node *models.Node) (models.Network, error) {
|
||||
|
||||
|
|
|
@ -98,7 +98,10 @@ type Node struct {
|
|||
IsInternetGateway bool `json:"isinternetgateway" yaml:"isinternetgateway"`
|
||||
InetNodeReq InetNodeReq `json:"inet_node_req" yaml:"inet_node_req"`
|
||||
InternetGwID string `json:"internetgw_node_id" yaml:"internetgw_node_id"`
|
||||
AdditionalRagIps []net.IP `json:"additional_rag_ips" yaml:"additional_rag_ips" swaggertype:"array,number"`
|
||||
AdditionalRagIps []net.IP `json:"additional_rag_ips" yaml:"additional_rag_ips" swaggertype:"array,number"`
|
||||
IsStatic bool `json:"is_static"`
|
||||
IsUserNode bool `json:"is_user_node"`
|
||||
StaticNode ExtClient `json:"static_node"`
|
||||
}
|
||||
|
||||
// LegacyNode - legacy struct for node model
|
||||
|
|
|
@ -687,7 +687,9 @@ func GetFilteredNodesByUserAccess(user models.User, nodes []models.Node) (filter
|
|||
|
||||
nodesMap := make(map[string]struct{})
|
||||
allNetworkRoles := make(map[models.UserRoleID]struct{})
|
||||
|
||||
defer func() {
|
||||
logic.AddStaticNodestoList(nodes)
|
||||
}()
|
||||
if len(user.NetworkRoles) > 0 {
|
||||
for _, netRoles := range user.NetworkRoles {
|
||||
for netRoleI := range netRoles {
|
||||
|
|
Loading…
Add table
Reference in a new issue