From fb6d70a5c6c6eae85a09c0729076bcd5226e2ccb Mon Sep 17 00:00:00 2001 From: postmannen Date: Fri, 20 May 2022 05:18:26 +0200 Subject: [PATCH] added initial REQ acl delete nodeGroup --- processes.go | 8 ++++++ requests.go | 5 ++++ requests_acl.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/processes.go b/processes.go index 6a50e0c..d34220f 100644 --- a/processes.go +++ b/processes.go @@ -178,6 +178,7 @@ func (p *processes) Start(proc process) { proc.startup.subREQAclDeleteSource(proc) proc.startup.subREQAclGroupNodesAddNode(proc) proc.startup.subREQAclGroupNodesDeleteNode(proc) + proc.startup.subREQAclGroupNodesDeleteGroup(proc) } if proc.configuration.StartSubREQPublicKeysToNode { @@ -415,6 +416,13 @@ func (s startup) subREQAclGroupNodesDeleteNode(p process) { go proc.spawnWorker() } +func (s startup) subREQAclGroupNodesDeleteGroup(p process) { + log.Printf("Starting Acl Delete nodeGroup subscriber: %#v\n", p.node) + sub := newSubject(REQAclGroupNodesDeleteGroup, string(p.node)) + proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil) + go proc.spawnWorker() +} + func (s startup) subREQToConsole(p process) { log.Printf("Starting Text To Console subscriber: %#v\n", p.node) sub := newSubject(REQToConsole, string(p.node)) diff --git a/requests.go b/requests.go index 6d4ccd9..ee37412 100644 --- a/requests.go +++ b/requests.go @@ -136,6 +136,8 @@ const ( REQAclGroupNodesAddNode = "REQAclGroupNodesAddNode" // REQAclGroupNodesDeleteNode REQAclGroupNodesDeleteNode = "REQAclGroupNodesDeleteNode" + // REQAclGroupNodesDeleteGroup + REQAclGroupNodesDeleteGroup = "REQAclGroupNodesDeleteGroup" ) // The mapping of all the method constants specified, what type @@ -241,6 +243,9 @@ func (m Method) GetMethodsAvailable() MethodsAvailable { REQAclGroupNodesDeleteNode: methodREQAclGroupNodesDeleteNode{ event: EventACK, }, + REQAclGroupNodesDeleteGroup: methodREQAclGroupNodesDeleteGroup{ + event: EventACK, + }, }, } diff --git a/requests_acl.go b/requests_acl.go index 36ebcc4..3506bcf 100644 --- a/requests_acl.go +++ b/requests_acl.go @@ -357,3 +357,72 @@ func (m methodREQAclGroupNodesDeleteNode) handler(proc process, message Message, } // --- + +type methodREQAclGroupNodesDeleteGroup struct { + event Event +} + +func (m methodREQAclGroupNodesDeleteGroup) getKind() Event { + return m.event +} + +func (m methodREQAclGroupNodesDeleteGroup) handler(proc process, message Message, node string) ([]byte, error) { + inf := fmt.Errorf("<--- methodREQAclGroupNodesDeleteGroup received from: %v, containing: %v", message.FromNode, message.MethodArgs) + proc.errorKernel.logConsoleOnlyIfDebug(inf, proc.configuration) + + proc.processes.wg.Add(1) + go func() { + defer proc.processes.wg.Done() + + switch { + case len(message.MethodArgs) < 1: + er := fmt.Errorf("error: methodREQAclGroupNodesDeleteGroup: got <1 number methodArgs, want 1") + proc.errorKernel.errSend(proc, message, er) + + return + } + + // Get a context with the timeout specified in message.MethodTimeout. + ctx, cancel := getContextForMethodTimeout(proc.ctx, message) + + outCh := make(chan []byte) + + proc.processes.wg.Add(1) + go func() { + defer proc.processes.wg.Done() + + ng := message.MethodArgs[0] + + proc.centralAuth.accessLists.groupNodesDeleteGroup(nodeGroup(ng)) + + outString := fmt.Sprintf("deleted nodeGroup: nodeGroup=%v\n", ng) + out := []byte(outString) + + select { + case outCh <- out: + case <-ctx.Done(): + return + } + }() + + select { + case <-ctx.Done(): + + cancel() + er := fmt.Errorf("error: methodREQAclGroupNodesDeleteGroup: method timed out: %v", message.MethodArgs) + proc.errorKernel.errSend(proc, message, er) + + case out := <-outCh: + + // Prepare and queue for sending a new message with the output + // of the action executed. + newReplyMessage(proc, message, out) + } + + }() + + ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID)) + return ackMsg, nil +} + +// ---