Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'master' into streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
justone committed Aug 3, 2016
2 parents 6a8b246 + 0db186a commit 78d47ab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions api/amqp.go
Expand Up @@ -106,6 +106,11 @@ func sendToAMQP(pmbConn *Connection, done chan error, id string) {
}
}
}

if message.Done != nil {
logrus.Debugf("Done channel present, sending message")
message.Done <- nil
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions api/http.go
Expand Up @@ -90,5 +90,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
}
}
}
10 changes: 7 additions & 3 deletions api/pmb.go
Expand Up @@ -22,6 +22,7 @@ type PMB struct {
type Message struct {
Contents map[string]interface{}
Raw string
Done chan error
}

type Connection struct {
Expand Down Expand Up @@ -182,10 +183,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
}
Expand Down
9 changes: 9 additions & 0 deletions api/util.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -146,6 +147,8 @@ func parseMessage(body []byte, keys []string, ch chan Message, id string) {

if !decryptedOk {
return
} else {
messageWasEncrypted = true
}

} else {
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions run.go
Expand Up @@ -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}
Expand Down

0 comments on commit 78d47ab

Please sign in to comment.