mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
wildcard matching hosts initially implemented, and seems to work
This commit is contained in:
parent
fefa3087a9
commit
49b558f371
4 changed files with 26 additions and 9 deletions
|
@ -156,13 +156,26 @@ func (a *accessLists) nodeAsSlice(n Node) []Node {
|
|||
|
||||
// Check if we are given a nodeGroup variable, and if we are, get all the
|
||||
// nodes for that group.
|
||||
if strings.HasPrefix(string(n), "grp_nodes_") {
|
||||
switch {
|
||||
case strings.HasPrefix(string(n), "grp_nodes_"):
|
||||
for nd := range a.schemaMain.NodeGroupMap[nodeGroup(n)] {
|
||||
nodes = append(nodes, nd)
|
||||
}
|
||||
} else {
|
||||
|
||||
case string(n) == "*":
|
||||
func() {
|
||||
a.pki.nodesAcked.mu.Lock()
|
||||
defer a.pki.nodesAcked.mu.Unlock()
|
||||
|
||||
for nd := range a.pki.nodesAcked.keysAndHash.Keys {
|
||||
nodes = append(nodes, nd)
|
||||
}
|
||||
}()
|
||||
|
||||
default:
|
||||
// No group found meaning a single node was given as an argument.
|
||||
nodes = []Node{n}
|
||||
|
||||
}
|
||||
|
||||
return nodes
|
||||
|
|
|
@ -37,7 +37,7 @@ func (a *authParser) parse() {
|
|||
// hostGroupOrSingle checks if host grp or single node.
|
||||
func (a *authParser) hostGroupOrSingle() parseFn {
|
||||
switch {
|
||||
case strings.HasPrefix(string(a.currentHost), "grp_nodes_"):
|
||||
case strings.HasPrefix(string(a.currentHost), "grp_nodes_") || a.currentHost == "*":
|
||||
// Is group
|
||||
return a.hostIsGroup
|
||||
default:
|
||||
|
|
|
@ -88,7 +88,7 @@ type nodeAcl struct {
|
|||
func newNodeAcl(c *Configuration) *nodeAcl {
|
||||
n := nodeAcl{
|
||||
aclAndHash: newAclAndHash(),
|
||||
filePath: filepath.Join(c.DatabaseFolder, "acl.txt"),
|
||||
filePath: filepath.Join(c.DatabaseFolder, "node_aclmap.txt"),
|
||||
}
|
||||
|
||||
err := n.loadFromFile()
|
||||
|
@ -136,6 +136,7 @@ func (n *nodeAcl) loadFromFile() error {
|
|||
|
||||
// saveToFile will save the acl to file for persistent storage.
|
||||
// An error is returned if it fails.
|
||||
// TODO: HERE: not saving deleted wildcard map entry for some reason!
|
||||
func (n *nodeAcl) saveToFile() error {
|
||||
fh, err := os.OpenFile(n.filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
if err != nil {
|
||||
|
|
|
@ -157,12 +157,15 @@ func (m methodREQAclDeliverUpdate) handler(proc process, message Message, node s
|
|||
}
|
||||
|
||||
mapOfFromNodeCommands := make(map[Node]map[command]struct{})
|
||||
err = cbor.Unmarshal(hdh.Data, &mapOfFromNodeCommands)
|
||||
if err != nil {
|
||||
er := fmt.Errorf("error: subscriber REQAclDeliverUpdate : json unmarshal failed: %v, message: %v", err, message)
|
||||
proc.errorKernel.errSend(proc, message, er)
|
||||
log.Fatalf("\n * DEBUG: ER: %v\n", er)
|
||||
|
||||
if len(hdh.Data) != 0 {
|
||||
err = cbor.Unmarshal(hdh.Data, &mapOfFromNodeCommands)
|
||||
if err != nil {
|
||||
er := fmt.Errorf("error: subscriber REQAclDeliverUpdate : cbor unmarshal failed: %v, message: %v", err, message)
|
||||
proc.errorKernel.errSend(proc, message, er)
|
||||
log.Fatalf("\n * DEBUG: ER: %v\n", er)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
proc.nodeAuth.nodeAcl.aclAndHash.Hash = hdh.Hash
|
||||
|
|
Loading…
Reference in a new issue