mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-15 14:20:25 +08:00
38cd4d7700
also removes server node suspect there may be issues with proxy and UI interactions with nodes
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package proacls
|
|
|
|
import (
|
|
"github.com/gravitl/netmaker/logic/acls"
|
|
"github.com/gravitl/netmaker/logic/acls/nodeacls"
|
|
"github.com/gravitl/netmaker/models"
|
|
)
|
|
|
|
// AdjustNodeAcls - adjusts ACLs based on a node's default value
|
|
func AdjustNodeAcls(node *models.Node, networkNodes []models.Node) error {
|
|
networkID := nodeacls.NetworkID(node.Network)
|
|
nodeID := nodeacls.NodeID(node.ID.String())
|
|
currentACLs, err := nodeacls.FetchAllACLs(networkID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for i := range networkNodes {
|
|
currentNodeID := nodeacls.NodeID(networkNodes[i].ID.String())
|
|
if currentNodeID == nodeID {
|
|
continue
|
|
}
|
|
// 2 cases
|
|
// both allow - allow
|
|
// either 1 denies - deny
|
|
if node.DoesACLDeny() || networkNodes[i].DoesACLDeny() {
|
|
currentACLs.ChangeAccess(acls.AclID(nodeID), acls.AclID(currentNodeID), acls.NotAllowed)
|
|
} else if node.DoesACLAllow() || networkNodes[i].DoesACLAllow() {
|
|
currentACLs.ChangeAccess(acls.AclID(nodeID), acls.AclID(currentNodeID), acls.Allowed)
|
|
}
|
|
}
|
|
|
|
_, err = currentACLs.Save(acls.ContainerID(node.Network))
|
|
return err
|
|
}
|