Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add MatterMost remote #508

Merged
merged 8 commits into from
Aug 8, 2024
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
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ SLACK_EVENTS_CALLBACK_PATH=
DISCORD_TOKEN=
DISCORD_SERVER_ID=

TELEGRAM_TOKEN=
TELEGRAM_TOKEN=

MATTERMOST_TOKEN=
MATTERMOST_SERVER=
MATTERMOST_INSECURE=
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ clean: validate
.PHONY: build
build: clean
@echo "Building flottbot binary to './flottbot'"
@go build -a \
-ldflags '$(BUILD_LDFLAGS)' -o $(PWD)/flottbot ./cmd/flottbot
@go build -a -ldflags '$(BUILD_LDFLAGS)' -o $(PWD)/flottbot ./cmd/flottbot

# ┌┬┐┌─┐┌─┐┬┌─┌─┐┬─┐
# │││ ││ ├┴┐├┤ ├┬┘
Expand Down Expand Up @@ -142,6 +141,6 @@ run: build
./flottbot

.PHONY: run-docker
run-docker: docker
run-docker: docker
@echo "Starting flottbot docker image"
@docker run -it --rm --name myflottbot -v "$$PWD"/config:/config --env-file .env $(DOCKER_IMAGE):latest /flottbot
32 changes: 32 additions & 0 deletions core/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func configureChatApplication(bot *models.Bot) {
bot.Name = token

if bot.ChatApplication != "" {
log.Info().Msgf("looking for chat application '%#q'", bot.ChatApplication)

switch strings.ToLower(bot.ChatApplication) {
//nolint:goconst // refactor
case "discord":
Expand Down Expand Up @@ -76,6 +78,36 @@ func configureChatApplication(bot *models.Bot) {
case "slack":
configureSlackBot(bot)

//nolint:goconst // refactor
case "mattermost":
log.Info().Msgf("configuring remote '%#q'", bot.ChatApplication)
token, err := utils.Substitute(bot.MatterMostToken, emptyMap)

if err != nil {
log.Error().Msgf("could not set 'mattermost_token': %v", err.Error())

bot.RunChat = false
}

bot.MatterMostToken = token

server, err := utils.Substitute(bot.MatterMostServer, emptyMap)

if err != nil {
log.Error().Msgf("could not set 'mattermost_server': %v", err.Error())

bot.RunChat = false
}

bot.MatterMostServer = server

insc, err := utils.Substitute(bot.MatterMostInsecureProtocol, emptyMap)
if err != nil {
log.Info().Msgf("could not retrieve insecure flag: '%v'", err.Error())
}

bot.MatterMostInsecureProtocol = insc

//nolint:goconst // refactor
case "telegram":
token, err := utils.Substitute(bot.TelegramToken, emptyMap)
Expand Down
11 changes: 11 additions & 0 deletions core/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/target/flottbot/remote/cli"
"github.com/target/flottbot/remote/discord"
"github.com/target/flottbot/remote/gchat"
"github.com/target/flottbot/remote/mattermost"
"github.com/target/flottbot/remote/slack"
"github.com/target/flottbot/remote/telegram"
)
Expand All @@ -37,6 +38,16 @@ func Outputs(outputMsgs <-chan models.Message, hitRule <-chan models.Rule, bot *
remoteDiscord := &discord.Client{Token: bot.DiscordToken}
remoteDiscord.Reaction(message, rule, bot)
remoteDiscord.Send(message, bot)
case "mattermost":
remoteMM := &mattermost.Client{
Server: bot.MatterMostServer,
Token: bot.MatterMostToken,
}
if strings.ToLower(bot.MatterMostInsecureProtocol) == "1" {
remoteMM.Insecure = true
}

remoteMM.Send(message, bot)
case "slack":
// Create Slack client
remoteSlack := &slack.Client{
Expand Down
17 changes: 17 additions & 0 deletions core/remotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/target/flottbot/remote/cli"
"github.com/target/flottbot/remote/discord"
"github.com/target/flottbot/remote/gchat"
"github.com/target/flottbot/remote/mattermost"
"github.com/target/flottbot/remote/scheduler"
"github.com/target/flottbot/remote/slack"
"github.com/target/flottbot/remote/telegram"
Expand Down Expand Up @@ -62,6 +63,22 @@ func Remotes(inputMsgs chan<- models.Message, rules map[string]models.Rule, bot
}
// Read messages from Slack
go remoteSlack.Read(inputMsgs, rules, bot)
case "mattermost":
remoteMattermost := &mattermost.Client{
Token: bot.MatterMostToken,
Server: bot.MatterMostServer,
Insecure: false,
}

log.Info().Msgf("insecure setting is: %v", bot.MatterMostInsecureProtocol)

if strings.ToLower(bot.MatterMostInsecureProtocol) == "1" {
remoteMattermost.Insecure = true

log.Warn().Msg("using insecure protocols http and ws")
}

go remoteMattermost.Read(inputMsgs, rules, bot)
// Setup remote to use the Telegram client to read from Telegram
case "telegram":
remoteTelegram := &telegram.Client{
Expand Down
40 changes: 36 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/bwmarrin/discordgo v0.28.1
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/gorilla/mux v1.8.1
github.com/mattermost/mattermost-server/v6 v6.7.2
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/prometheus/client_golang v1.19.0
github.com/robfig/cron/v3 v3.0.1
Expand All @@ -27,9 +28,14 @@ require (
cloud.google.com/go/iam v1.1.6 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.3 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -38,28 +44,52 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/graph-gophers/graphql-go v1.3.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d // indirect
github.com/mattermost/logr/v2 v2.0.15 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.24 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/philhofer/fwd v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tinylib/msgp v1.1.6 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/wiggin77/merror v1.0.3 // indirect
github.com/wiggin77/srslog v1.0.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
Expand All @@ -69,7 +99,7 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.19.0 // indirect
golang.org/x/sync v0.7.0 // indirect
Expand All @@ -82,5 +112,7 @@ require (
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading