clients.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package logic
  2. import "github.com/gravitl/netmaker/models"
  3. // functions defined here, handle client ACLs, should be set on ee
  4. var (
  5. // DenyClientNodeAccess - function to handle adding a node to an ext client's denied node set
  6. DenyClientNodeAccess = func(ec *models.ExtClient, clientOrNodeID string) bool { return true }
  7. // IsClientNodeAllowed - function to check if an ext client's denied node set contains a node ID
  8. IsClientNodeAllowed = func(ec *models.ExtClient, clientOrNodeID string) bool { return true }
  9. // AllowClientNodeAccess - function to handle removing a node ID from ext client's denied nodes, thus allowing it
  10. AllowClientNodeAccess = func(ec *models.ExtClient, clientOrNodeID string) bool { return true }
  11. )
  12. // SetClientDefaultACLs - set's a client's default ACLs based on network and nodes in network
  13. func SetClientDefaultACLs(ec *models.ExtClient) error {
  14. if !isEE {
  15. return nil
  16. }
  17. networkNodes, err := GetNetworkNodes(ec.Network)
  18. if err != nil {
  19. return err
  20. }
  21. network, err := GetNetwork(ec.Network)
  22. if err != nil {
  23. return err
  24. }
  25. for i := range networkNodes {
  26. currNode := networkNodes[i]
  27. if network.DefaultACL == "no" || currNode.DefaultACL == "no" {
  28. DenyClientNodeAccess(ec, currNode.ID.String())
  29. }
  30. }
  31. return nil
  32. }
  33. // SetClientACLs - overwrites an ext client's ACL
  34. func SetClientACLs(ec *models.ExtClient, newACLs map[string]struct{}) {
  35. if ec == nil || newACLs == nil || !isEE {
  36. return
  37. }
  38. ec.ACLs = newACLs
  39. }
  40. // IsClientNodeAllowedByID - checks if a given ext client ID + nodeID are allowed
  41. func IsClientNodeAllowedByID(clientID, networkName, clientOrNodeID string) bool {
  42. client, err := GetExtClient(clientID, networkName)
  43. if err != nil {
  44. return false
  45. }
  46. return IsClientNodeAllowed(&client, clientOrNodeID)
  47. }