From d68fe3ba1e9e83c09bddbe96342cda4151839a86 Mon Sep 17 00:00:00 2001 From: postmannen Date: Fri, 20 May 2022 13:56:17 +0200 Subject: [PATCH] Added initital REQ for AclGroupCommandsDeleteGroup --- processes.go | 8 ++++++ requests.go | 10 ++++++++ requests_acl.go | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/processes.go b/processes.go index 6d3365f..fb00d20 100644 --- a/processes.go +++ b/processes.go @@ -181,6 +181,7 @@ func (p *processes) Start(proc process) { proc.startup.subREQAclGroupNodesDeleteGroup(proc) proc.startup.subREQAclGroupCommandsAddCommand(proc) proc.startup.subREQAclGroupCommandsDeleteCommand(proc) + proc.startup.subREQAclGroupCommandsDeleteGroup(proc) } if proc.configuration.StartSubREQPublicKeysToNode { @@ -439,6 +440,13 @@ func (s startup) subREQAclGroupCommandsDeleteCommand(p process) { go proc.spawnWorker() } +func (s startup) subREQAclGroupCommandsDeleteGroup(p process) { + log.Printf("Starting Acl delete command group subscriber: %#v\n", p.node) + sub := newSubject(REQAclGroupCommandsDeleteGroup, 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 cf768f7..e4baf0b 100644 --- a/requests.go +++ b/requests.go @@ -142,6 +142,8 @@ const ( REQAclGroupCommandsAddCommand = "REQAclGroupCommandsAddCommand" // REQAclGroupCommandsDeleteCommand REQAclGroupCommandsDeleteCommand = "REQAclGroupCommandsDeleteCommand" + // REQAclGroupCommandsDeleteGroup + REQAclGroupCommandsDeleteGroup = "REQAclGroupCommandsDeleteGroup" ) // The mapping of all the method constants specified, what type @@ -150,6 +152,11 @@ const ( // Allowed values for the Event field are: // - EventACK // - EventNack +// +// The primary use of this table is that messages are not able to +// pass the actual type of the request since it is sent as a string, +// so we use the below table to find the actual type based on that +// string type. func (m Method) GetMethodsAvailable() MethodsAvailable { ma := MethodsAvailable{ @@ -256,6 +263,9 @@ func (m Method) GetMethodsAvailable() MethodsAvailable { REQAclGroupCommandsDeleteCommand: methodREQAclGroupCommandsDeleteCommand{ event: EventACK, }, + REQAclGroupCommandsDeleteGroup: methodREQAclGroupCommandsDeleteGroup{ + event: EventACK, + }, }, } diff --git a/requests_acl.go b/requests_acl.go index 973dfb3..cfd696f 100644 --- a/requests_acl.go +++ b/requests_acl.go @@ -566,3 +566,70 @@ func (m methodREQAclGroupCommandsDeleteCommand) handler(proc process, message Me } // --- + +type methodREQAclGroupCommandsDeleteGroup struct { + event Event +} + +func (m methodREQAclGroupCommandsDeleteGroup) getKind() Event { + return m.event +} + +func (m methodREQAclGroupCommandsDeleteGroup) handler(proc process, message Message, node string) ([]byte, error) { + inf := fmt.Errorf("<--- methodREQAclGroupCommandsDeleteGroup 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: methodREQAclGroupCommandsDeleteGroup: 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() + + cg := message.MethodArgs[0] + + proc.centralAuth.accessLists.groupCommandDeleteGroup(commandGroup(cg)) + + outString := fmt.Sprintf("deleted commandGroup: commandGroup=%v\n", cg) + out := []byte(outString) + + select { + case outCh <- out: + case <-ctx.Done(): + return + } + }() + + select { + case <-ctx.Done(): + + cancel() + er := fmt.Errorf("error: methodREQAclGroupCommandsDeleteGroup: 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 +}