1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

added command group iteration for single host

This commit is contained in:
postmannen 2022-05-09 12:06:21 +02:00
parent 8151e62d9d
commit 02c5846c2f
2 changed files with 24 additions and 22 deletions

View file

@ -92,20 +92,22 @@ func (a *authParser) hostIsNotGroup() parseFn {
for source, cmdMap := range a.authSchema.schemaMain.ACLMap[a.currentHost] {
for cmd, emptyStruct := range cmdMap {
cmdSlice := a.authSchema.convertToActualCommandSlice(cmd)
// Expand eventual groups, so we use real fromNode nodenames in ACL for nodes.
sourceNodes := a.authSchema.convToActualNodeSlice(source)
for _, sourceNode := range sourceNodes {
if a.authSchema.schemaGenerated.ACLsToConvert[host] == nil {
a.authSchema.schemaGenerated.ACLsToConvert[host] = make(map[node]map[command]struct{})
}
if a.authSchema.schemaGenerated.ACLsToConvert[host][sourceNode] == nil {
a.authSchema.schemaGenerated.ACLsToConvert[host][sourceNode] = make(map[command]struct{})
}
a.authSchema.schemaGenerated.ACLsToConvert[host][sourceNode][cmd] = emptyStruct
for _, cm := range cmdSlice {
if a.authSchema.schemaGenerated.ACLsToConvert[host] == nil {
a.authSchema.schemaGenerated.ACLsToConvert[host] = make(map[node]map[command]struct{})
}
if a.authSchema.schemaGenerated.ACLsToConvert[host][sourceNode] == nil {
a.authSchema.schemaGenerated.ACLsToConvert[host][sourceNode] = make(map[command]struct{})
}
a.authSchema.schemaGenerated.ACLsToConvert[host][sourceNode][cm] = emptyStruct
}
}
}
}

View file

@ -279,13 +279,13 @@ func (a *authSchema) generateJSONForAllNodes() error {
return nil
}
type fromNodes struct {
Node node
FromNodes []fromNodeCommands
type sourceNodes struct {
Node node
SourceCommands []sourceCommands
}
type fromNodeCommands struct {
FromNode node
type sourceCommands struct {
Source node
Commands []command
}
@ -294,14 +294,14 @@ type fromNodeCommands struct {
// defined for each fromNode are sorted.
// This function is used when creating the hash of the nodeMap since we can not
// guarantee the order of a hash map, but we can with a slice.
func (a *authSchema) nodeMapToSlice(n node) fromNodes {
fns := fromNodes{
func (a *authSchema) nodeMapToSlice(n node) sourceNodes {
srcNodes := sourceNodes{
Node: n,
}
for fn, commandMap := range a.schemaMain.ACLMap[n] {
fnc := fromNodeCommands{
FromNode: fn,
for sn, commandMap := range a.schemaMain.ACLMap[n] {
fnc := sourceCommands{
Source: sn,
}
for cmd := range commandMap {
@ -313,16 +313,16 @@ func (a *authSchema) nodeMapToSlice(n node) fromNodes {
return fnc.Commands[i] < fnc.Commands[j]
})
fns.FromNodes = append(fns.FromNodes, fnc)
srcNodes.SourceCommands = append(srcNodes.SourceCommands, fnc)
}
sort.SliceStable(fns.FromNodes, func(i, j int) bool {
return fns.FromNodes[i].FromNode < fns.FromNodes[j].FromNode
sort.SliceStable(srcNodes.SourceCommands, func(i, j int) bool {
return srcNodes.SourceCommands[i].Source < srcNodes.SourceCommands[j].Source
})
// fmt.Printf(" * nodeMapToSlice: fromNodes: %#v\n", fns)
return fns
return srcNodes
}
// groupNodesAddNode adds a node to a group. If the group does