1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-03-31 01:24:31 +00:00

added debug logging

This commit is contained in:
postmannen 2022-05-19 20:00:25 +02:00
parent 62f7fa02d0
commit 9899485ddc
3 changed files with 22 additions and 17 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(errorKernel), accessLists: newAccessLists(errorKernel, configuration),
pki: newPKI(configuration, errorKernel), pki: newPKI(configuration, errorKernel),
} }

View file

@ -37,14 +37,16 @@ type accessLists struct {
schemaGenerated *schemaGenerated schemaGenerated *schemaGenerated
validator *validator.Validate validator *validator.Validate
errorKernel *errorKernel errorKernel *errorKernel
configuration *Configuration
} }
func newAccessLists(errorKernel *errorKernel) *accessLists { func newAccessLists(errorKernel *errorKernel, configuration *Configuration) *accessLists {
a := accessLists{ a := accessLists{
schemaMain: newSchemaMain(), schemaMain: newSchemaMain(),
schemaGenerated: newSchemaGenerated(), schemaGenerated: newSchemaGenerated(),
validator: validator.New(), validator: validator.New(),
errorKernel: errorKernel, errorKernel: errorKernel,
configuration: configuration,
} }
return &a return &a
@ -257,22 +259,23 @@ func (a *accessLists) generateACLsForAllNodes() error {
ap.parse() ap.parse()
} }
inf := fmt.Errorf("generateACLsFor all nodes, ACLsToConvert contains: %#v", a.schemaGenerated.ACLsToConvert)
a.errorKernel.logConsoleOnlyIfDebug(inf, a.configuration)
// ACLsToConvert got the complete picture of what ACL's that // ACLsToConvert got the complete picture of what ACL's that
// are defined for each individual host node. // are defined for each individual host node.
// Range this map, and generate a JSON representation of all // Range this map, and generate a JSON representation of all
// the ACL's each host. // the ACL's each host.
fmt.Printf("\n --- DEBUG: IN GENERATE ACLsToConvert contains: %#v\n", a.schemaGenerated.ACLsToConvert)
func() { func() {
// If the map to generate from map is empty we want to also set the generatedACLsMap // If the map to generate from map is empty we want to also set the generatedACLsMap
// to empty so we can make sure that no more generated ACL's exists to be distributed. // to empty so we can make sure that no more generated ACL's exists to be distributed.
if len(a.schemaGenerated.ACLsToConvert) == 0 { if len(a.schemaGenerated.ACLsToConvert) == 0 {
fmt.Printf(" ****** MAP IS EMPTY\n")
a.schemaGenerated.GeneratedACLsMap = make(map[Node]HostACLsSerializedWithHash) a.schemaGenerated.GeneratedACLsMap = make(map[Node]HostACLsSerializedWithHash)
} }
for n, m := range a.schemaGenerated.ACLsToConvert { for n, m := range a.schemaGenerated.ACLsToConvert {
fmt.Printf("\n ################ DEBUG: RANGE in generate: n=%v, m=%v\n", n, m) //fmt.Printf("\n ################ DEBUG: RANGE in generate: n=%v, m=%v\n", n, m)
// cbor marshal the data of the ACL map to store for the host node. // cbor marshal the data of the ACL map to store for the host node.
cb, err := cbor.Marshal(m) cb, err := cbor.Marshal(m)
@ -308,7 +311,9 @@ func (a *accessLists) generateACLsForAllNodes() error {
} }
}() }()
fmt.Printf("\n --- DEBUG: IN GENERATE GeneratedACLsMap contains: %v\n", a.schemaGenerated.GeneratedACLsMap)
inf = fmt.Errorf("generateACLsFor all nodes, GeneratedACLsMap contains: %#v", a.schemaGenerated.GeneratedACLsMap)
a.errorKernel.logConsoleOnlyIfDebug(inf, a.configuration)
return nil return nil
} }

View file

@ -16,7 +16,7 @@ func TestACLSingleNode(t *testing.T) {
log.SetOutput(io.Discard) log.SetOutput(io.Discard)
} }
a := newAccessLists(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
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(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
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(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
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(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
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(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
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(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
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(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
//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(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
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(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
// -----------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(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
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(&errorKernel{}) a := newAccessLists(&errorKernel{}, &Configuration{})
err := a.importACLs(js) err := a.importACLs(js)
if err != nil { if err != nil {