From 8a49afa9ad180ee081dcb5b3d7b60250d5397e55 Mon Sep 17 00:00:00 2001 From: postmannen Date: Wed, 8 Sep 2021 04:29:11 +0200 Subject: [PATCH] disabled the allow receivers functionality --- README.md | 2 ++ process.go | 88 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 073155e..74fdc39 100644 --- a/README.md +++ b/README.md @@ -650,6 +650,8 @@ For CliCommand message to a node named "ship1" of type Command and it wants an A ## TODO +### Make the actual output errors of CMD's executed be put in the error message + ### Fix bug when new flags are added to an existing config and the value is always set to 0 and not it's default Add a set flag to the configuration so we can know if a value have been set or is a default value. We can then loop over the whole struct to check if new fields have been added and give it the appropriate default value. diff --git a/process.go b/process.go index 1b49524..611fb3a 100644 --- a/process.go +++ b/process.go @@ -337,28 +337,34 @@ func (p process) subscriberHandler(natsConn *nats.Conn, thisNode string, msg *na sendErrorLogMessage(p.configuration, p.processes.metrics, p.toRingbufferCh, Node(thisNode), er) } - out := []byte("not allowed from " + message.FromNode) - //var err error + var out []byte - // Check if we are allowed to receive from that host - _, arOK1 := p.allowedReceivers[message.FromNode] - _, arOK2 := p.allowedReceivers["*"] + // NB: + // The commented out code below is for the allowed recievers functionality + // for the REQ type specified at startup. Keeping the code for now, but it + // is probably redundant since the same information can be specified in + // the broker config + // + // // out := []byte("not allowed from " + message.FromNode) + // // Check if we are allowed to receive from that host + // _, arOK1 := p.allowedReceivers[message.FromNode] + // _, arOK2 := p.allowedReceivers["*"] + // + // if arOK1 || arOK2 { + // // Start the method handler for that specific subject type. + // // The handler started here is what actually doing the action + // // that executed a CLI command, or writes to a log file on + // // the node who received the message. + out, err = mh.handler(p, message, thisNode) - if arOK1 || arOK2 { - // Start the method handler for that specific subject type. - // The handler started here is what actually doing the action - // that executed a CLI command, or writes to a log file on - // the node who received the message. - out, err = mh.handler(p, message, thisNode) - - if err != nil { - er := fmt.Errorf("error: subscriberHandler: handler method failed: %v", err) - sendErrorLogMessage(p.configuration, p.processes.metrics, p.toRingbufferCh, Node(thisNode), er) - } - } else { - er := fmt.Errorf("info: we don't allow receiving from: %v, %v", message.FromNode, p.subject) + if err != nil { + er := fmt.Errorf("error: subscriberHandler: handler method failed: %v", err) sendErrorLogMessage(p.configuration, p.processes.metrics, p.toRingbufferCh, Node(thisNode), er) } + // } else { + // er := fmt.Errorf("info: we don't allow receiving from: %v, %v", message.FromNode, p.subject) + // sendErrorLogMessage(p.configuration, p.processes.metrics, p.toRingbufferCh, Node(thisNode), er) + // } // Send a confirmation message back to the publisher natsConn.Publish(msg.Reply, out) @@ -371,29 +377,35 @@ func (p process) subscriberHandler(natsConn *nats.Conn, thisNode string, msg *na sendErrorLogMessage(p.configuration, p.processes.metrics, p.toRingbufferCh, Node(thisNode), er) } - // Check if we are allowed to receive from that host - _, arOK1 := p.allowedReceivers[message.FromNode] - _, arOK2 := p.allowedReceivers["*"] + // NB: + // The commented out code below is for the allowed recievers functionality + // for the REQ type specified at startup. Keeping the code for now, but it + // is probably redundant since the same information can be specified in + // the broker config + // + // // Check if we are allowed to receive from that host + // _, arOK1 := p.allowedReceivers[message.FromNode] + // _, arOK2 := p.allowedReceivers["*"] + // + // if arOK1 || arOK2 { + // + // // Start the method handler for that specific subject type. + // // The handler started here is what actually doing the action + // // that executed a CLI command, or writes to a log file on + // // the node who received the message. + // // + // // since we don't send a reply for a NACK message, we don't care about the + // // out return when calling mf.handler + _, err := mf.handler(p, message, thisNode) - if arOK1 || arOK2 { - - // Start the method handler for that specific subject type. - // The handler started here is what actually doing the action - // that executed a CLI command, or writes to a log file on - // the node who received the message. - // - // since we don't send a reply for a NACK message, we don't care about the - // out return when calling mf.handler - _, err := mf.handler(p, message, thisNode) - - if err != nil { - er := fmt.Errorf("error: subscriberHandler: handler method failed: %v", err) - sendErrorLogMessage(p.configuration, p.processes.metrics, p.toRingbufferCh, Node(thisNode), er) - } - } else { - er := fmt.Errorf("info: we don't allow receiving from: %v, %v", message.FromNode, p.subject) + if err != nil { + er := fmt.Errorf("error: subscriberHandler: handler method failed: %v", err) sendErrorLogMessage(p.configuration, p.processes.metrics, p.toRingbufferCh, Node(thisNode), er) } + // } else { + // er := fmt.Errorf("info: we don't allow receiving from: %v, %v", message.FromNode, p.subject) + // sendErrorLogMessage(p.configuration, p.processes.metrics, p.toRingbufferCh, Node(thisNode), er) + // } default: er := fmt.Errorf("info: did not find that specific type of command: %#v", p.subject.CommandOrEvent)