diff --git a/processes.go b/processes.go index d34220f..f96a99e 100644 --- a/processes.go +++ b/processes.go @@ -179,6 +179,7 @@ func (p *processes) Start(proc process) { proc.startup.subREQAclGroupNodesAddNode(proc) proc.startup.subREQAclGroupNodesDeleteNode(proc) proc.startup.subREQAclGroupNodesDeleteGroup(proc) + proc.startup.subREQAclGroupCommandsAddCommand(proc) } if proc.configuration.StartSubREQPublicKeysToNode { @@ -423,6 +424,13 @@ func (s startup) subREQAclGroupNodesDeleteGroup(p process) { go proc.spawnWorker() } +func (s startup) subREQAclGroupCommandsAddCommand(p process) { + log.Printf("Starting Acl add command to command group subscriber: %#v\n", p.node) + sub := newSubject(REQAclGroupCommandsAddCommand, 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 ee37412..cbaabfd 100644 --- a/requests.go +++ b/requests.go @@ -138,6 +138,8 @@ const ( REQAclGroupNodesDeleteNode = "REQAclGroupNodesDeleteNode" // REQAclGroupNodesDeleteGroup REQAclGroupNodesDeleteGroup = "REQAclGroupNodesDeleteGroup" + // REQAclGroupCommandsAddCommand + REQAclGroupCommandsAddCommand = "REQAclGroupCommandsAddCommand" ) // The mapping of all the method constants specified, what type @@ -246,6 +248,9 @@ func (m Method) GetMethodsAvailable() MethodsAvailable { REQAclGroupNodesDeleteGroup: methodREQAclGroupNodesDeleteGroup{ event: EventACK, }, + REQAclGroupCommandsAddCommand: methodREQAclGroupCommandsAddCommand{ + event: EventACK, + }, }, } diff --git a/requests_acl.go b/requests_acl.go index 3506bcf..dcbc98f 100644 --- a/requests_acl.go +++ b/requests_acl.go @@ -426,3 +426,73 @@ func (m methodREQAclGroupNodesDeleteGroup) handler(proc process, message Message } // --- + +type methodREQAclGroupCommandsAddCommand struct { + event Event +} + +func (m methodREQAclGroupCommandsAddCommand) getKind() Event { + return m.event +} + +func (m methodREQAclGroupCommandsAddCommand) handler(proc process, message Message, node string) ([]byte, error) { + inf := fmt.Errorf("<--- methodREQAclGroupCommandsAddCommand 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: methodREQAclGroupCommandsAddCommand: 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] + c := message.MethodArgs[1] + + proc.centralAuth.accessLists.groupCommandsAddCommand(commandGroup(cg), command(c)) + + outString := fmt.Sprintf("added command to commandGroup: commandGroup=%v, command=%v\n", cg, c) + out := []byte(outString) + + select { + case outCh <- out: + case <-ctx.Done(): + return + } + }() + + select { + case <-ctx.Done(): + + cancel() + er := fmt.Errorf("error: methodREQAclGroupCommandsAddCommand: 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 +} + +// ---