1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-01-05 20:09:16 +00:00

added errorKernel to accessLists

This commit is contained in:
postmannen 2022-05-19 11:53:25 +02:00
parent 83a7ea5193
commit 62f7fa02d0
4 changed files with 15 additions and 31 deletions

View file

@ -22,7 +22,7 @@ type centralAuth struct {
// newCentralAuth will return a new and prepared *centralAuth // newCentralAuth will return a new and prepared *centralAuth
func newCentralAuth(configuration *Configuration, errorKernel *errorKernel) *centralAuth { func newCentralAuth(configuration *Configuration, errorKernel *errorKernel) *centralAuth {
c := centralAuth{ c := centralAuth{
accessLists: newAccessLists(), accessLists: newAccessLists(errorKernel),
pki: newPKI(configuration, errorKernel), pki: newPKI(configuration, errorKernel),
} }

View file

@ -36,13 +36,15 @@ type accessLists struct {
// Holds the generated based on the editable structures for ACL handling. // Holds the generated based on the editable structures for ACL handling.
schemaGenerated *schemaGenerated schemaGenerated *schemaGenerated
validator *validator.Validate validator *validator.Validate
errorKernel *errorKernel
} }
func newAccessLists() *accessLists { func newAccessLists(errorKernel *errorKernel) *accessLists {
a := accessLists{ a := accessLists{
schemaMain: newSchemaMain(), schemaMain: newSchemaMain(),
schemaGenerated: newSchemaGenerated(), schemaGenerated: newSchemaGenerated(),
validator: validator.New(), validator: validator.New(),
errorKernel: errorKernel,
} }
return &a return &a

View file

@ -16,7 +16,7 @@ func TestACLSingleNode(t *testing.T) {
log.SetOutput(io.Discard) log.SetOutput(io.Discard)
} }
a := newAccessLists() a := newAccessLists(&errorKernel{})
a.aclAddCommand("ship101", "admin", "HORSE") a.aclAddCommand("ship101", "admin", "HORSE")
a.aclAddCommand("ship101", "admin", "PIG") a.aclAddCommand("ship101", "admin", "PIG")
@ -42,7 +42,7 @@ func TestACLWithGroups(t *testing.T) {
log.SetOutput(io.Discard) log.SetOutput(io.Discard)
} }
a := newAccessLists() a := newAccessLists(&errorKernel{})
const ( const (
grp_nodes_operators = "grp_nodes_operators" grp_nodes_operators = "grp_nodes_operators"
@ -101,7 +101,7 @@ func TestACLNodesGroupDeleteNode(t *testing.T) {
log.SetOutput(io.Discard) log.SetOutput(io.Discard)
} }
a := newAccessLists() a := newAccessLists(&errorKernel{})
const ( const (
grp_nodes_operators = "grp_nodes_operators" grp_nodes_operators = "grp_nodes_operators"
@ -158,7 +158,7 @@ func TestGroupNodesDeleteGroup(t *testing.T) {
log.SetOutput(io.Discard) log.SetOutput(io.Discard)
} }
a := newAccessLists() a := newAccessLists(&errorKernel{})
const ( const (
grp_nodes_operators = "grp_nodes_operators" grp_nodes_operators = "grp_nodes_operators"
@ -215,7 +215,7 @@ func TestGroupCommandDeleteGroup(t *testing.T) {
log.SetOutput(io.Discard) log.SetOutput(io.Discard)
} }
a := newAccessLists() a := newAccessLists(&errorKernel{})
const ( const (
grp_nodes_operators = "grp_nodes_operators" grp_nodes_operators = "grp_nodes_operators"
@ -272,7 +272,7 @@ func TestACLGenerated(t *testing.T) {
log.SetOutput(io.Discard) log.SetOutput(io.Discard)
} }
a := newAccessLists() a := newAccessLists(&errorKernel{})
a.aclAddCommand("ship101", "admin", "HORSE") a.aclAddCommand("ship101", "admin", "HORSE")
@ -321,7 +321,7 @@ func TestACLSchemaMainACLMap(t *testing.T) {
log.SetOutput(io.Discard) log.SetOutput(io.Discard)
} }
a := newAccessLists() a := newAccessLists(&errorKernel{})
//a.aclNodeFromnodeCommandAdd("ship101", "admin", "PIG") //a.aclNodeFromnodeCommandAdd("ship101", "admin", "PIG")
// fmt.Printf("---------------ADDING COMMAND-------------\n") // fmt.Printf("---------------ADDING COMMAND-------------\n")
@ -400,7 +400,7 @@ func TestACLHash(t *testing.T) {
log.SetOutput(io.Discard) log.SetOutput(io.Discard)
} }
a := newAccessLists() a := newAccessLists(&errorKernel{})
a.aclAddCommand("ship101", "admin", "HORSE") a.aclAddCommand("ship101", "admin", "HORSE")
@ -417,7 +417,7 @@ func TestACLHash(t *testing.T) {
} }
func TestACLConcurrent(t *testing.T) { func TestACLConcurrent(t *testing.T) {
a := newAccessLists() a := newAccessLists(&errorKernel{})
// -----------General testing and creation of some data---------------- // -----------General testing and creation of some data----------------
@ -466,7 +466,7 @@ func TestExportACLs(t *testing.T) {
grp_commands_commandset1 = "grp_commands_commandset1" grp_commands_commandset1 = "grp_commands_commandset1"
) )
a := newAccessLists() a := newAccessLists(&errorKernel{})
a.groupNodesAddNode(grp_nodes_operators, "operator1") a.groupNodesAddNode(grp_nodes_operators, "operator1")
a.groupNodesAddNode(grp_nodes_operators, "operator2") a.groupNodesAddNode(grp_nodes_operators, "operator2")
@ -501,7 +501,7 @@ func TestImportACLs(t *testing.T) {
want := `map[grp_nodes_ships:map[admin:map[useradd -m kongen:{}] grp_nodes_operators:map[grp_commands_commandset1:{}]] ship101:map[admin:map[HORSE:{}]]]` want := `map[grp_nodes_ships:map[admin:map[useradd -m kongen:{}] grp_nodes_operators:map[grp_commands_commandset1:{}]] ship101:map[admin:map[HORSE:{}]]]`
a := newAccessLists() a := newAccessLists(&errorKernel{})
err := a.importACLs(js) err := a.importACLs(js)
if err != nil { if err != nil {

View file

@ -45,15 +45,6 @@ func (m methodREQAclAddCommand) handler(proc process, message Message, node stri
proc.centralAuth.accessLists.aclAddCommand(Node(host), Node(source), command(cmd)) proc.centralAuth.accessLists.aclAddCommand(Node(host), Node(source), command(cmd))
// Just print out for testing.
proc.centralAuth.accessLists.schemaMain.mu.Lock()
fmt.Printf("\n ########### content of main acl map: %v###########\n", proc.centralAuth.accessLists.schemaMain.ACLMap)
proc.centralAuth.accessLists.schemaMain.mu.Unlock()
proc.centralAuth.accessLists.schemaGenerated.mu.Lock()
fmt.Printf("\n ########### content of generated acl map: %v###########\n", proc.centralAuth.accessLists.schemaGenerated.GeneratedACLsMap)
proc.centralAuth.accessLists.schemaGenerated.mu.Unlock()
outString := fmt.Sprintf("acl added: host=%v, source=%v, command=%v\n", host, source, cmd) outString := fmt.Sprintf("acl added: host=%v, source=%v, command=%v\n", host, source, cmd)
out := []byte(outString) out := []byte(outString)
@ -125,15 +116,6 @@ func (m methodREQAclDeleteCommand) handler(proc process, message Message, node s
proc.centralAuth.accessLists.aclDeleteCommand(Node(host), Node(source), command(cmd)) proc.centralAuth.accessLists.aclDeleteCommand(Node(host), Node(source), command(cmd))
// Just print out for testing.
proc.centralAuth.accessLists.schemaMain.mu.Lock()
fmt.Printf("\n ########### content of main acl map: %v###########\n", proc.centralAuth.accessLists.schemaMain.ACLMap)
proc.centralAuth.accessLists.schemaMain.mu.Unlock()
proc.centralAuth.accessLists.schemaGenerated.mu.Lock()
fmt.Printf("\n ########### content of generated acl map: %v###########\n", proc.centralAuth.accessLists.schemaGenerated.GeneratedACLsMap)
proc.centralAuth.accessLists.schemaGenerated.mu.Unlock()
outString := fmt.Sprintf("acl deleted: host=%v, source=%v, command=%v\n", host, source, cmd) outString := fmt.Sprintf("acl deleted: host=%v, source=%v, command=%v\n", host, source, cmd)
out := []byte(outString) out := []byte(outString)