clients.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package logic
  2. import (
  3. "errors"
  4. "sort"
  5. "github.com/gravitl/netmaker/models"
  6. )
  7. // functions defined here, handle client ACLs, should be set on ee
  8. var (
  9. // DenyClientNodeAccess - function to handle adding a node to an ext client's denied node set
  10. DenyClientNodeAccess = func(ec *models.ExtClient, clientOrNodeID string) bool {
  11. return true
  12. }
  13. // IsClientNodeAllowed - function to check if an ext client's denied node set contains a node ID
  14. IsClientNodeAllowed = func(ec *models.ExtClient, clientOrNodeID string) bool {
  15. return true
  16. }
  17. // AllowClientNodeAccess - function to handle removing a node ID from ext client's denied nodes, thus allowing it
  18. AllowClientNodeAccess = func(ec *models.ExtClient, clientOrNodeID string) bool {
  19. return true
  20. }
  21. SetClientDefaultACLs = func(ec *models.ExtClient) error {
  22. return nil
  23. }
  24. SetClientACLs = func(ec *models.ExtClient, newACLs map[string]struct{}) {
  25. }
  26. UpdateProNodeACLs = func(node *models.Node) error {
  27. return nil
  28. }
  29. )
  30. // SortExtClient - Sorts slice of ExtClients by their ClientID alphabetically with numbers first
  31. func SortExtClient(unsortedExtClient []models.ExtClient) {
  32. sort.Slice(unsortedExtClient, func(i, j int) bool {
  33. return unsortedExtClient[i].ClientID < unsortedExtClient[j].ClientID
  34. })
  35. }
  36. // GetExtClientByName - gets an ext client by name
  37. func GetExtClientByName(ID string) (models.ExtClient, error) {
  38. clients, err := GetAllExtClients()
  39. if err != nil {
  40. return models.ExtClient{}, err
  41. }
  42. for i := range clients {
  43. if clients[i].ClientID == ID {
  44. return clients[i], nil
  45. }
  46. }
  47. return models.ExtClient{}, errors.New("client not found")
  48. }