netmaker/logic/pro/proacls/nodes.go

36 lines
1.1 KiB
Go
Raw Normal View History

2022-09-14 03:25:56 +08:00
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 {
2022-09-14 03:25:56 +08:00
networkID := nodeacls.NetworkID(node.Network)
nodeID := nodeacls.NodeID(node.ID.String())
2022-09-14 03:25:56 +08:00
currentACLs, err := nodeacls.FetchAllACLs(networkID)
if err != nil {
return err
}
for i := range networkNodes {
currentNodeID := nodeacls.NodeID(networkNodes[i].ID.String())
2022-09-14 03:25:56 +08:00
if currentNodeID == nodeID {
continue
}
// 2 cases
// both allow - allow
// either 1 denies - deny
2022-09-17 02:09:04 +08:00
if node.DoesACLDeny() || networkNodes[i].DoesACLDeny() {
2022-09-14 03:25:56 +08:00
currentACLs.ChangeAccess(acls.AclID(nodeID), acls.AclID(currentNodeID), acls.NotAllowed)
2022-09-17 02:09:04 +08:00
} else if node.DoesACLAllow() || networkNodes[i].DoesACLAllow() {
currentACLs.ChangeAccess(acls.AclID(nodeID), acls.AclID(currentNodeID), acls.Allowed)
2022-09-14 03:25:56 +08:00
}
}
_, err = currentACLs.Save(acls.ContainerID(node.Network))
return err
}