Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Feature/multiple xmpp support #73

Merged
merged 2 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
api/bin
api/api
/api/tests_results.xml
.env
.env*
27 changes: 26 additions & 1 deletion api/hook/xmpp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package hook

import (
"fmt"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/ovh/tat"
"github.com/spf13/viper"
Expand All @@ -19,5 +22,27 @@ func sendXMPP(hook *tat.HookJSON, path string, topic tat.Topic) error {
}
log.Debugf("sendXMPP: enter for post XMPP via tat2XMPP setted on topic %s", topic.Topic)

return sendWebHook(hook, viper.GetString("tat2xmpp_url")+"/hook", topic, tat.HookTat2XMPPHeaderKey, viper.GetString("tat2xmpp_key"))
// We split the XMPP servers and keys (comma separated lists)
tat2xmppServers := strings.Split(viper.GetString("tat2xmpp_url"), ",")
tat2xmppKeys := strings.Split(viper.GetString("tat2xmpp_key"), ",")

// We must have the same number of servers and keys: one key for one server
if len(tat2xmppServers) != len(tat2xmppKeys) {
return fmt.Errorf("the number of XMPP servers differs from the number of provided keys (%v servers and %v keys)", len(tat2xmppServers), len(tat2xmppKeys))
}

// Go through the servers and send the hook with the right key
// The right key for the right server is determined by the declaration order:
// the first server goes with the first key, the second server goes with the second key...
for index, tat2xmppServer := range tat2xmppServers {
errSendWebHook := sendWebHook(hook, tat2xmppServer+"/hook", topic, tat.HookTat2XMPPHeaderKey, tat2xmppKeys[index])
if errSendWebHook != nil {
// If an error is encountered, abort everything and return the error because we should not encounter any error
// even if we are sending the wrong destination to the wrong server (tat2xmpp will handle that and return no error)
// So an error is not normal and we should return it immediately
return errSendWebHook
}
}

return nil
}