1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

added initial REQ for AclGroupNodesDeleteNode

This commit is contained in:
postmannen 2022-05-19 22:19:22 +02:00
parent 6a7fe51f60
commit e813642506
3 changed files with 166 additions and 0 deletions

View file

@ -176,6 +176,8 @@ func (p *processes) Start(proc process) {
proc.startup.subREQAclAddCommand(proc)
proc.startup.subREQAclDeleteCommand(proc)
proc.startup.subREQAclDeleteSource(proc)
proc.startup.subREQAclGroupNodesAddNode(proc)
proc.startup.subREQAclGroupNodesDeleteNode(proc)
}
if proc.configuration.StartSubREQPublicKeysToNode {
@ -399,6 +401,20 @@ func (s startup) subREQAclDeleteSource(p process) {
go proc.spawnWorker()
}
func (s startup) subREQAclGroupNodesAddNode(p process) {
log.Printf("Starting Acl Add node to nodeGroup subscriber: %#v\n", p.node)
sub := newSubject(REQAclGroupNodesAddNode, string(p.node))
proc := newProcess(p.ctx, s.server, sub, processKindSubscriber, nil)
go proc.spawnWorker()
}
func (s startup) subREQAclGroupNodesDeleteNode(p process) {
log.Printf("Starting Acl Delete node from nodeGroup subscriber: %#v\n", p.node)
sub := newSubject(REQAclGroupNodesDeleteNode, 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))

View file

@ -132,6 +132,10 @@ const (
REQAclDeleteCommand = "REQAclDeleteCommand"
// REQAclDeleteSource
REQAclDeleteSource = "REQAclDeleteSource"
// REQGroupNodesAddNode
REQAclGroupNodesAddNode = "REQAclGroupNodesAddNode"
// REQAclGroupNodesDeleteNode
REQAclGroupNodesDeleteNode = "REQAclGroupNodesDeleteNode"
)
// The mapping of all the method constants specified, what type
@ -231,6 +235,12 @@ func (m Method) GetMethodsAvailable() MethodsAvailable {
REQAclDeleteSource: methodREQAclDeleteSource{
event: EventACK,
},
REQAclGroupNodesAddNode: methodREQAclGroupNodesAddNode{
event: EventACK,
},
REQAclGroupNodesDeleteNode: methodREQAclGroupNodesDeleteNode{
event: EventACK,
},
},
}

View file

@ -217,3 +217,143 @@ func (m methodREQAclDeleteSource) handler(proc process, message Message, node st
}
// ---
type methodREQAclGroupNodesAddNode struct {
event Event
}
func (m methodREQAclGroupNodesAddNode) getKind() Event {
return m.event
}
func (m methodREQAclGroupNodesAddNode) handler(proc process, message Message, node string) ([]byte, error) {
inf := fmt.Errorf("<--- methodREQAclGroupNodesAddNode 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) < 2:
er := fmt.Errorf("error: methodREQAclGroupNodesAddNode: got <2 number methodArgs, want 2")
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]
n := message.MethodArgs[1]
proc.centralAuth.accessLists.groupNodesAddNode(nodeGroup(ng), Node(n))
outString := fmt.Sprintf("added node to nodeGroup: nodeGroup=%v, node=%v\n", ng, n)
out := []byte(outString)
select {
case outCh <- out:
case <-ctx.Done():
return
}
}()
select {
case <-ctx.Done():
cancel()
er := fmt.Errorf("error: methodREQAclGroupNodesAddNode: 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
}
// ---
type methodREQAclGroupNodesDeleteNode struct {
event Event
}
func (m methodREQAclGroupNodesDeleteNode) getKind() Event {
return m.event
}
func (m methodREQAclGroupNodesDeleteNode) handler(proc process, message Message, node string) ([]byte, error) {
inf := fmt.Errorf("<--- methodREQAclGroupNodesDeleteNode 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) < 2:
er := fmt.Errorf("error: methodREQAclGroupNodesDeleteNode: got <2 number methodArgs, want 2")
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]
n := message.MethodArgs[1]
proc.centralAuth.accessLists.groupNodesDeleteNode(nodeGroup(ng), Node(n))
outString := fmt.Sprintf("deleted node from nodeGroup: nodeGroup=%v, node=%v\n", ng, n)
out := []byte(outString)
select {
case outCh <- out:
case <-ctx.Done():
return
}
}()
select {
case <-ctx.Done():
cancel()
er := fmt.Errorf("error: methodREQAclGroupNodesDeleteNode: 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
}
// ---