mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
renamed generete json method to generateACLsForAllNodes
This commit is contained in:
parent
7cc50d4680
commit
56cd575716
2 changed files with 20 additions and 14 deletions
|
@ -166,7 +166,7 @@ func (a *authSchema) aclAdd(host node, source node, cmd command) {
|
|||
|
||||
a.schemaMain.ACLMap[host][source][cmd] = struct{}{}
|
||||
// err := a.generateJSONForHostOrGroup(n)
|
||||
err := a.generateJSONForAllNodes()
|
||||
err := a.generateACLsForAllNodes()
|
||||
if err != nil {
|
||||
er := fmt.Errorf("error: addCommandForFromNode: %v", err)
|
||||
log.Printf("%v\n", er)
|
||||
|
@ -196,7 +196,7 @@ func (a *authSchema) aclDeleteCommand(host node, source node, cmd command) error
|
|||
|
||||
delete(a.schemaMain.ACLMap[host][source], cmd)
|
||||
|
||||
err := a.generateJSONForAllNodes()
|
||||
err := a.generateACLsForAllNodes()
|
||||
if err != nil {
|
||||
er := fmt.Errorf("error: aclNodeFromNodeCommandDelete: %v", err)
|
||||
log.Printf("%v\n", er)
|
||||
|
@ -221,7 +221,7 @@ func (a *authSchema) aclDeleteSource(host node, source node) error {
|
|||
|
||||
delete(a.schemaMain.ACLMap[host], source)
|
||||
|
||||
err := a.generateJSONForAllNodes()
|
||||
err := a.generateACLsForAllNodes()
|
||||
if err != nil {
|
||||
er := fmt.Errorf("error: aclNodeFromnodeDelete: %v", err)
|
||||
log.Printf("%v\n", er)
|
||||
|
@ -230,14 +230,14 @@ func (a *authSchema) aclDeleteSource(host node, source node) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// generateJSONForAllNodes will generate a json encoded representation of the node specific
|
||||
// generateACLsForAllNodes will generate a json encoded representation of the node specific
|
||||
// map values of authSchema, along with a hash of the data.
|
||||
//
|
||||
// Will range over all the host elements defined in the ACL, create a new authParser for each one,
|
||||
// and run a small state machine on each element to create the final ACL result to be used at host
|
||||
// nodes.
|
||||
// The result will be written to the schemaGenerated.ACLsToConvert map.
|
||||
func (a *authSchema) generateJSONForAllNodes() error {
|
||||
func (a *authSchema) generateACLsForAllNodes() error {
|
||||
a.schemaGenerated.ACLsToConvert = make(map[node]map[node]map[command]struct{})
|
||||
|
||||
// Rangle all ACL's. Both for single hosts, and group of hosts.
|
||||
|
@ -297,12 +297,18 @@ func (a *authSchema) generateJSONForAllNodes() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type sourceNodes struct {
|
||||
Node node
|
||||
SourceCommands []sourceCommands
|
||||
// sourceNode is used to convert the ACL map structure of a host into a slice,
|
||||
// and we then use the slice representation of the ACL to create the hash for
|
||||
// a specific host node.
|
||||
type sourceNode struct {
|
||||
HostNode node
|
||||
SourceCommands []sourceNodeCommands
|
||||
}
|
||||
|
||||
type sourceCommands struct {
|
||||
// sourceNodeCommand is used to convert the ACL map structure of a host into a slice,
|
||||
// and we then use the slice representation of the ACL to create the hash for
|
||||
// a specific host node.
|
||||
type sourceNodeCommands struct {
|
||||
Source node
|
||||
Commands []command
|
||||
}
|
||||
|
@ -312,13 +318,13 @@ type sourceCommands 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(host node) sourceNodes {
|
||||
srcNodes := sourceNodes{
|
||||
Node: host,
|
||||
func (a *authSchema) nodeMapToSlice(host node) sourceNode {
|
||||
srcNodes := sourceNode{
|
||||
HostNode: host,
|
||||
}
|
||||
|
||||
for sn, commandMap := range a.schemaGenerated.ACLsToConvert[host] {
|
||||
srcC := sourceCommands{
|
||||
srcC := sourceNodeCommands{
|
||||
Source: sn,
|
||||
}
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ func TestHash(t *testing.T) {
|
|||
c.authorization.authSchema.groupNodesAddNode("grp_nodes_ships", "ship101")
|
||||
c.authorization.authSchema.aclAdd("grp_nodes_ships", "admin", "HEN")
|
||||
|
||||
hash := [32]uint8{0x70, 0xac, 0xe, 0xf5, 0x98, 0x1e, 0x82, 0xe0, 0xb6, 0x5b, 0xc7, 0xd8, 0xa2, 0xf4, 0xa2, 0x30, 0xb2, 0xb8, 0x42, 0x5c, 0x4, 0xc, 0xce, 0x8d, 0xcc, 0x7a, 0xa1, 0xa3, 0xb7, 0xb9, 0x2c, 0xa8}
|
||||
hash := [32]uint8{0xa4, 0x99, 0xbd, 0xa3, 0x18, 0x26, 0x52, 0xc2, 0x92, 0x60, 0x23, 0x19, 0x3c, 0xa, 0x7, 0xa9, 0xb7, 0x77, 0x4f, 0x11, 0x34, 0xd5, 0x2d, 0xd1, 0x8d, 0xab, 0x6c, 0x4b, 0x2, 0xfa, 0x5c, 0x7a}
|
||||
value := c.authorization.authSchema.schemaGenerated.NodeMap["ship101"].Hash
|
||||
fmt.Printf("%#v\n", c.authorization.authSchema.schemaGenerated.NodeMap["ship101"].Hash)
|
||||
|
||||
|
|
Loading…
Reference in a new issue