mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
Added initial REQ AclExport
This commit is contained in:
parent
d68fe3ba1e
commit
c3e442d497
3 changed files with 86 additions and 0 deletions
|
@ -182,6 +182,7 @@ func (p *processes) Start(proc process) {
|
|||
proc.startup.subREQAclGroupCommandsAddCommand(proc)
|
||||
proc.startup.subREQAclGroupCommandsDeleteCommand(proc)
|
||||
proc.startup.subREQAclGroupCommandsDeleteGroup(proc)
|
||||
proc.startup.subREQAclExport(proc)
|
||||
}
|
||||
|
||||
if proc.configuration.StartSubREQPublicKeysToNode {
|
||||
|
@ -447,6 +448,13 @@ func (s startup) subREQAclGroupCommandsDeleteGroup(p process) {
|
|||
go proc.spawnWorker()
|
||||
}
|
||||
|
||||
func (s startup) subREQAclExport(p process) {
|
||||
log.Printf("Starting Acl export subscriber: %#v\n", p.node)
|
||||
sub := newSubject(REQAclExport, 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))
|
||||
|
|
|
@ -144,6 +144,8 @@ const (
|
|||
REQAclGroupCommandsDeleteCommand = "REQAclGroupCommandsDeleteCommand"
|
||||
// REQAclGroupCommandsDeleteGroup
|
||||
REQAclGroupCommandsDeleteGroup = "REQAclGroupCommandsDeleteGroup"
|
||||
// REQAclExport
|
||||
REQAclExport = "REQAclExport"
|
||||
)
|
||||
|
||||
// The mapping of all the method constants specified, what type
|
||||
|
@ -266,6 +268,9 @@ func (m Method) GetMethodsAvailable() MethodsAvailable {
|
|||
REQAclGroupCommandsDeleteGroup: methodREQAclGroupCommandsDeleteGroup{
|
||||
event: EventACK,
|
||||
},
|
||||
REQAclExport: methodREQAclExport{
|
||||
event: EventACK,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -633,3 +633,76 @@ func (m methodREQAclGroupCommandsDeleteGroup) handler(proc process, message Mess
|
|||
ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID))
|
||||
return ackMsg, nil
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
type methodREQAclExport struct {
|
||||
event Event
|
||||
}
|
||||
|
||||
func (m methodREQAclExport) getKind() Event {
|
||||
return m.event
|
||||
}
|
||||
|
||||
func (m methodREQAclExport) handler(proc process, message Message, node string) ([]byte, error) {
|
||||
inf := fmt.Errorf("<--- methodREQAclExport 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: methodREQAclImport: 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)
|
||||
errCh := make(chan error)
|
||||
|
||||
proc.processes.wg.Add(1)
|
||||
go func() {
|
||||
defer proc.processes.wg.Done()
|
||||
|
||||
out, err := proc.centralAuth.accessLists.exportACLs()
|
||||
if err != nil {
|
||||
errCh <- fmt.Errorf("error: methodREQAclExport failed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// outString := fmt.Sprintf("Exported acls sent from: %v\n", message.FromNode)
|
||||
// out := []byte(outString)
|
||||
|
||||
select {
|
||||
case outCh <- out:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-errCh:
|
||||
proc.errorKernel.errSend(proc, message, err)
|
||||
|
||||
case <-ctx.Done():
|
||||
cancel()
|
||||
er := fmt.Errorf("error: methodREQAclExport: 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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue