From 0293073fe81e480698d1a8195b47f787328f6491 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Wed, 20 Jul 2016 14:01:59 -0700 Subject: [PATCH 1/3] add emoji to run success or fail --- run.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/run.go b/run.go index d5f4ad4..d775a96 100644 --- a/run.go +++ b/run.go @@ -92,16 +92,18 @@ func runRun(conn *pmb.Connection, id string, args []string) error { cmdSuccess := true result := "successfully" + resultEmoji := "👍" if err != nil { result = fmt.Sprintf("with error '%s'", err.Error()) + resultEmoji = "👎" cmdSuccess = false } logrus.Infof("Process complete.") if len(message) == 0 { - message = fmt.Sprintf("Command [%s] completed %s.", command, result) + message = fmt.Sprintf("%s Command [%s] completed %s.", resultEmoji, command, result) } else { - message = fmt.Sprintf("%s. Command completed %s.", message, result) + message = fmt.Sprintf("%s. %s Command completed %s.", message, resultEmoji, result) } note := pmb.Notification{Message: message, Level: runCommand.Level} From df9e68302094e76b327063d54f9b8e0e2b4ee4cd Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Mon, 1 Aug 2016 20:07:26 -0700 Subject: [PATCH 2/3] only allow RequestAuth messages to be unencrypted --- api/util.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/util.go b/api/util.go index 86dbaf4..500e18b 100644 --- a/api/util.go +++ b/api/util.go @@ -114,6 +114,7 @@ func prepareMessage(message Message, keys []string, id string) ([][]byte, error) func parseMessage(body []byte, keys []string, ch chan Message, id string) { var message []byte var rawData interface{} + messageWasEncrypted := false if body[0] != '{' { logrus.Debugf("Decrypting message...") if len(keys) > 0 { @@ -146,6 +147,8 @@ func parseMessage(body []byte, keys []string, ch chan Message, id string) { if !decryptedOk { return + } else { + messageWasEncrypted = true } } else { @@ -165,6 +168,12 @@ func parseMessage(body []byte, keys []string, ch chan Message, id string) { senderId := data["id"].(string) + // only RequestAuth messages are allowed to be unencrypted + if !messageWasEncrypted && data["type"].(string) != "RequestAuth" { + logrus.Warningf("Unencrypted message that wasn't RequestAuth detected, discarding...") + return + } + // hide messages from ourselves if senderId != id { logrus.Debugf("Message received: %s", data) From 0db186a5dbf210988ca845342950517b6a62920d Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Tue, 2 Aug 2016 20:04:13 -0700 Subject: [PATCH 3/3] ensure that copy key message is sent add new optional chan to message struct to signify that message was sent --- api/amqp.go | 5 +++++ api/http.go | 5 +++++ api/pmb.go | 10 +++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/api/amqp.go b/api/amqp.go index 046c5f8..37678e4 100644 --- a/api/amqp.go +++ b/api/amqp.go @@ -101,6 +101,11 @@ func sendToAMQP(pmbConn *Connection, done chan error, id string) { } } } + + if message.Done != nil { + logrus.Debugf("Done channel present, sending message") + message.Done <- nil + } } } diff --git a/api/http.go b/api/http.go index 9ed9c21..788b86d 100644 --- a/api/http.go +++ b/api/http.go @@ -83,5 +83,10 @@ func sendToHTTP(pmbConn *Connection, done chan error, id string) { logrus.Warningf("Error sending: %s", err) } } + + if message.Done != nil { + logrus.Debugf("Done channel present, sending message") + message.Done <- nil + } } } diff --git a/api/pmb.go b/api/pmb.go index 8f49988..53538e9 100644 --- a/api/pmb.go +++ b/api/pmb.go @@ -22,6 +22,7 @@ type PMB struct { type Message struct { Contents map[string]interface{} Raw string + Done chan error } type Connection struct { @@ -171,10 +172,13 @@ func copyKey(URI string, id string) (*Connection, error) { data := map[string]interface{}{ "type": "RequestAuth", } - conn.Out <- Message{Contents: data} + mess := Message{ + Contents: data, + Done: make(chan error), + } + conn.Out <- mess - // wait a second for the message to go out - time.Sleep(1 * time.Second) + <-mess.Done return conn, nil }