mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-03 02:53:29 +08:00
refactored logic
This commit is contained in:
@@ -1,11 +1,5 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gravitl/netmaker/database"
|
||||
)
|
||||
|
||||
// ExtClient - struct for external clients
|
||||
type ExtClient struct {
|
||||
ClientID string `json:"clientid" bson:"clientid"`
|
||||
@@ -18,29 +12,3 @@ type ExtClient struct {
|
||||
IngressGatewayEndpoint string `json:"ingressgatewayendpoint" bson:"ingressgatewayendpoint"`
|
||||
LastModified int64 `json:"lastmodified" bson:"lastmodified"`
|
||||
}
|
||||
|
||||
// ExtClient.GetEgressRangesOnNetwork - returns the egress ranges on network of ext client
|
||||
func (client *ExtClient) GetEgressRangesOnNetwork() ([]string, error) {
|
||||
|
||||
var result []string
|
||||
nodesData, err := database.FetchRecords(database.NODES_TABLE_NAME)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
for _, nodeData := range nodesData {
|
||||
var currentNode Node
|
||||
if err = json.Unmarshal([]byte(nodeData), ¤tNode); err != nil {
|
||||
continue
|
||||
}
|
||||
if currentNode.Network != client.Network {
|
||||
continue
|
||||
}
|
||||
if currentNode.IsEgressGateway == "yes" { // add the egress gateway range(s) to the result
|
||||
if len(currentNode.EgressGatewayRanges) > 0 {
|
||||
result = append(result, currentNode.EgressGatewayRanges...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user