extclient.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package models
  2. import (
  3. "encoding/json"
  4. "github.com/gravitl/netmaker/database"
  5. )
  6. type ExtClient struct {
  7. ClientID string `json:"clientid" bson:"clientid"`
  8. Description string `json:"description" bson:"description"`
  9. PrivateKey string `json:"privatekey" bson:"privatekey"`
  10. PublicKey string `json:"publickey" bson:"publickey"`
  11. Network string `json:"network" bson:"network"`
  12. Address string `json:"address" bson:"address"`
  13. IngressGatewayID string `json:"ingressgatewayid" bson:"ingressgatewayid"`
  14. IngressGatewayEndpoint string `json:"ingressgatewayendpoint" bson:"ingressgatewayendpoint"`
  15. LastModified int64 `json:"lastmodified" bson:"lastmodified"`
  16. }
  17. /**
  18. * Get the egress gateway ips of a given ExtClient struct
  19. * returns as []string
  20. */
  21. func (client *ExtClient) GetEgressRangesOnNetwork() ([]string, error) {
  22. var result []string
  23. nodesData, err := database.FetchRecords(database.NODES_TABLE_NAME)
  24. if err != nil {
  25. return []string{}, err
  26. }
  27. for _, nodeData := range nodesData {
  28. var currentNode Node
  29. if err = json.Unmarshal([]byte(nodeData), &currentNode); err != nil {
  30. continue
  31. }
  32. if currentNode.Network != client.Network {
  33. continue
  34. }
  35. if currentNode.IsEgressGateway == "yes" { // add the egress gateway range(s) to the result
  36. if len(currentNode.EgressGatewayRanges) > 0 {
  37. result = append(result, currentNode.EgressGatewayRanges...)
  38. }
  39. }
  40. }
  41. return result, nil
  42. }