Skip to content
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: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@1b549b9259bda1cb5ddde3b41741a82a2d15a841 # v3.28.13
uses: github/codeql-action/init@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -64,7 +64,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@1b549b9259bda1cb5ddde3b41741a82a2d15a841 # v3.28.13
uses: github/codeql-action/autobuild@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -78,4 +78,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@1b549b9259bda1cb5ddde3b41741a82a2d15a841 # v3.28.13
uses: github/codeql-action/analyze@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)
BUILD_LDFLAGS := -s -w
BUILD_LDFLAGS += -X github.com/target/flottbot/version.Version=${VERSION}
GOLANGCI_LINT_VERSION := "v2.0.2"
GOLANGCI_LINT_VERSION := "v2.1.2"
PACKAGES := $(shell go list ./... | grep -v /config-example/)
PLATFORM := "linux/amd64,linux/arm64"

Expand Down
10 changes: 5 additions & 5 deletions core/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func configureChatApplication(bot *models.Bot) {

switch strings.ToLower(bot.ChatApplication) {
//nolint:goconst // refactor
case "discord":
case models.ChatAppDiscord:
// Discord bot token
token, err := utils.Substitute(bot.DiscordToken, emptyMap)
if err != nil {
Expand Down Expand Up @@ -75,11 +75,11 @@ func configureChatApplication(bot *models.Bot) {
}

//nolint:goconst // refactor
case "slack":
case models.ChatAppSlack:
configureSlackBot(bot)

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

Expand Down Expand Up @@ -109,7 +109,7 @@ func configureChatApplication(bot *models.Bot) {
bot.MatterMostInsecureProtocol = insc

//nolint:goconst // refactor
case "telegram":
case models.ChatAppTelegram:
token, err := utils.Substitute(bot.TelegramToken, emptyMap)
if err != nil {
log.Error().Msgf("could not set 'telegram_token': %s", err.Error())
Expand All @@ -126,7 +126,7 @@ func configureChatApplication(bot *models.Bot) {
bot.TelegramToken = token

//nolint:goconst // refactor
case "google_chat":
case models.ChatAppGoogleChat:
gchat.Configure(bot)

default:
Expand Down
36 changes: 18 additions & 18 deletions core/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ func Test_configureChatApplication(t *testing.T) {

testBotSlackNoToken := new(models.Bot)
testBotSlackNoToken.CLI = true
testBotSlackNoToken.ChatApplication = "slack"
testBotSlackNoToken.ChatApplication = models.ChatAppSlack
validateRemoteSetup(testBotSlackNoToken)

testBotBadName := new(models.Bot)
testBotBadName.CLI = true
testBotBadName.ChatApplication = "slack"
testBotBadName.ChatApplication = models.ChatAppSlack
testBotBadName.Name = "${BOT_NAME}"
validateRemoteSetup(testBotBadName)

testBotSlackBadToken := new(models.Bot)
testBotSlackBadToken.CLI = true
testBotSlackBadToken.ChatApplication = "slack"
testBotSlackBadToken.ChatApplication = models.ChatAppSlack
testBotSlackBadToken.SlackToken = "${TOKEN}"
validateRemoteSetup(testBotSlackBadToken)

testBotSlackBadSigningSecret := new(models.Bot)
testBotSlackBadSigningSecret.CLI = true
testBotSlackBadSigningSecret.ChatApplication = "slack"
testBotSlackBadSigningSecret.ChatApplication = models.ChatAppSlack
testBotSlackBadSigningSecret.SlackToken = "${TOKEN}"
testBotSlackBadSigningSecret.SlackSigningSecret = "${TEST_BAD_SIGNING_SECRET}"
validateRemoteSetup(testBotSlackBadSigningSecret)

testBotSlack := new(models.Bot)
testBotSlack.CLI = true
testBotSlack.ChatApplication = "slack"
testBotSlack.ChatApplication = models.ChatAppSlack
testBotSlack.SlackToken = "${TEST_SLACK_TOKEN}"
testBotSlack.SlackAppToken = "${TEST_SLACK_APP_TOKEN}"

Expand All @@ -64,18 +64,18 @@ func Test_configureChatApplication(t *testing.T) {

testBotDiscordNoToken := new(models.Bot)
testBotDiscordNoToken.CLI = true
testBotDiscordNoToken.ChatApplication = "discord"
testBotDiscordNoToken.ChatApplication = models.ChatAppDiscord
validateRemoteSetup(testBotDiscordNoToken)

testBotDiscordBadToken := new(models.Bot)
testBotDiscordBadToken.CLI = true
testBotDiscordBadToken.ChatApplication = "discord"
testBotDiscordBadToken.ChatApplication = models.ChatAppDiscord
testBotDiscordBadToken.DiscordToken = "${TOKEN}"
validateRemoteSetup(testBotDiscordBadToken)

testBotDiscordServerID := new(models.Bot)
testBotDiscordServerID.CLI = true
testBotDiscordServerID.ChatApplication = "discord"
testBotDiscordServerID.ChatApplication = models.ChatAppDiscord
testBotDiscordServerID.DiscordToken = "${TEST_DISCORD_TOKEN}"
testBotDiscordServerID.DiscordServerID = "${TEST_DISCORD_SERVER_ID}"

Expand All @@ -86,15 +86,15 @@ func Test_configureChatApplication(t *testing.T) {

testBotDiscordBadServerID := new(models.Bot)
testBotDiscordBadServerID.CLI = true
testBotDiscordBadServerID.ChatApplication = "discord"
testBotDiscordBadServerID.ChatApplication = models.ChatAppDiscord
testBotDiscordBadServerID.DiscordToken = "${TEST_DISCORD_TOKEN}"
testBotDiscordBadServerID.DiscordServerID = "${TOKEN}"

validateRemoteSetup(testBotDiscordServerID)

testBotTelegram := new(models.Bot)
testBotTelegram.CLI = true
testBotTelegram.ChatApplication = "telegram"
testBotTelegram.ChatApplication = models.ChatAppTelegram
testBotTelegram.TelegramToken = "${TEST_TELEGRAM_TOKEN}"

t.Setenv("TEST_TELEGRAM_TOKEN", "TESTTOKEN")
Expand All @@ -103,12 +103,12 @@ func Test_configureChatApplication(t *testing.T) {

testBotTelegramNoToken := new(models.Bot)
testBotTelegramNoToken.CLI = true
testBotTelegramNoToken.ChatApplication = "telegram"
testBotTelegramNoToken.ChatApplication = models.ChatAppTelegram
validateRemoteSetup(testBotTelegramNoToken)

testBotTelegramBadToken := new(models.Bot)
testBotTelegramBadToken.CLI = true
testBotTelegramBadToken.ChatApplication = "telegram"
testBotTelegramBadToken.ChatApplication = models.ChatAppTelegram
testBotTelegramBadToken.TelegramToken = "${TOKEN}"
validateRemoteSetup(testBotTelegramBadToken)

Expand All @@ -124,12 +124,12 @@ func Test_configureChatApplication(t *testing.T) {
{"Slack - no token", args{bot: testBotSlackNoToken}, false},
{"Slack - bad token", args{bot: testBotSlackBadToken}, false},
{"Slack - bad signing secret", args{bot: testBotSlackBadSigningSecret}, false},
{"Slack", args{bot: testBotSlack}, true},
{models.ChatAppSlack, args{bot: testBotSlack}, true},
{"Discord - no token", args{bot: testBotDiscordNoToken}, false},
{"Discord - bad token", args{bot: testBotDiscordBadToken}, false},
{"Discord w/ server id", args{bot: testBotDiscordServerID}, true},
{"Discord w/ bad server id", args{bot: testBotDiscordBadServerID}, false},
{"Telegram", args{bot: testBotTelegram}, true},
{models.ChatAppTelegram, args{bot: testBotTelegram}, true},
{"Telegram - no token", args{bot: testBotTelegramNoToken}, false},
{"Telegram - bad token", args{bot: testBotTelegramBadToken}, false},
}
Expand All @@ -151,7 +151,7 @@ func Test_setSlackListenerPort(t *testing.T) {
baseBot := func() *models.Bot {
bot := new(models.Bot)
bot.CLI = true
bot.ChatApplication = "slack"
bot.ChatApplication = models.ChatAppSlack
bot.SlackToken = "${TEST_SLACK_TOKEN}"
bot.SlackInteractionsCallbackPath = "${TEST_SLACK_INTERACTIONS_CALLBACK_PATH}"

Expand Down Expand Up @@ -215,15 +215,15 @@ func Test_validateRemoteSetup(t *testing.T) {

testBotCLIChat := new(models.Bot)
testBotCLIChat.CLI = true
testBotCLIChat.ChatApplication = "slack"
testBotCLIChat.ChatApplication = models.ChatAppSlack

testBotCLIChatScheduler := new(models.Bot)
testBotCLIChatScheduler.CLI = true
testBotCLIChatScheduler.ChatApplication = "slack"
testBotCLIChatScheduler.ChatApplication = models.ChatAppSlack
testBotCLIChatScheduler.Scheduler = true

testBotChatScheduler := new(models.Bot)
testBotChatScheduler.ChatApplication = "slack"
testBotChatScheduler.ChatApplication = models.ChatAppSlack
testBotChatScheduler.Scheduler = true

testBotCLIChatSchedulerFail := new(models.Bot)
Expand Down
10 changes: 5 additions & 5 deletions core/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Outputs(outputMsgs <-chan models.Message, hitRule <-chan models.Rule, bot *
chatApp := strings.ToLower(bot.ChatApplication)

switch chatApp {
case "discord":
case models.ChatAppDiscord:
if service == models.MsgServiceScheduler {
log.Warn().Msg("scheduler does not currently support discord")
break
Expand All @@ -38,7 +38,7 @@ 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":
case models.ChatAppMattermost:
remoteMM := &mattermost.Client{
Server: bot.MatterMostServer,
Token: bot.MatterMostToken,
Expand All @@ -48,7 +48,7 @@ func Outputs(outputMsgs <-chan models.Message, hitRule <-chan models.Rule, bot *
}

remoteMM.Send(message, bot)
case "slack":
case models.ChatAppSlack:
// Create Slack client
remoteSlack := &slack.Client{
ListenerPort: bot.SlackListenerPort,
Expand All @@ -62,12 +62,12 @@ func Outputs(outputMsgs <-chan models.Message, hitRule <-chan models.Rule, bot *
}

remoteSlack.Send(message, bot)
case "telegram":
case models.ChatAppTelegram:
remoteTelegram := &telegram.Client{
Token: bot.TelegramToken,
}
remoteTelegram.Send(message, bot)
case "google_chat":
case models.ChatAppGoogleChat:
gchat.HandleRemoteOutput(message, bot)
default:
log.Error().Msgf("chat application %#q is not supported", chatApp)
Expand Down
10 changes: 5 additions & 5 deletions core/remotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func Remotes(inputMsgs chan<- models.Message, rules map[string]models.Rule, bot

switch chatApp {
// Setup remote to use the Discord client to read from Discord
case "discord":
case models.ChatAppDiscord:
// Create Discord client
remoteDiscord := &discord.Client{
Token: bot.DiscordToken,
}
// Read messages from Discord
go remoteDiscord.Read(inputMsgs, rules, bot)
// Setup remote to use the Slack client to read from Slack
case "slack":
case models.ChatAppSlack:
// Create Slack client
remoteSlack := &slack.Client{
Token: bot.SlackToken,
Expand All @@ -63,7 +63,7 @@ func Remotes(inputMsgs chan<- models.Message, rules map[string]models.Rule, bot
}
// Read messages from Slack
go remoteSlack.Read(inputMsgs, rules, bot)
case "mattermost":
case models.ChatAppMattermost:
remoteMattermost := &mattermost.Client{
Token: bot.MatterMostToken,
Server: bot.MatterMostServer,
Expand All @@ -80,13 +80,13 @@ func Remotes(inputMsgs chan<- models.Message, rules map[string]models.Rule, bot

go remoteMattermost.Read(inputMsgs, rules, bot)
// Setup remote to use the Telegram client to read from Telegram
case "telegram":
case models.ChatAppTelegram:
remoteTelegram := &telegram.Client{
Token: bot.TelegramToken,
}
// Read messages from Telegram
go remoteTelegram.Read(inputMsgs, rules, bot)
case "google_chat":
case models.ChatAppGoogleChat:
gchat.HandleRemoteInput(inputMsgs, rules, bot)
default:
log.Error().Msgf("chat application %#q is not supported", chatApp)
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.python
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -a -ldflags "-s -w -X github.com/target/flottbot/version.Version=${VERSION}" \
-o flottbot ./cmd/flottbot

FROM docker.io/python:3.13.2-alpine@sha256:323a717dc4a010fee21e3f1aac738ee10bb485de4e7593ce242b36ee48d6b352
FROM docker.io/python:3.13.3-alpine@sha256:18159b2be11db91f84b8f8f655cd860f805dbd9e49a583ddaac8ab39bf4fe1a7

ENV USERNAME=flottbot
ENV GROUP=flottbot
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.ruby
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -a -ldflags "-s -w -X github.com/target/flottbot/version.Version=${VERSION}" \
-o flottbot ./cmd/flottbot

FROM docker.io/ruby:3.4.2-alpine@sha256:cb6a5cb7303314946b75fa64c96d8116f838b8495ffa161610bd6aaaf9a70121
FROM docker.io/ruby:3.4.3-alpine@sha256:c9956b1836f8c3f4fc4724e435baa037e55d32b302406742dfd5dcaadf7a4bb1

ENV USERNAME=flottbot
ENV GROUP=flottbot
Expand Down
29 changes: 14 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ module github.com/target/flottbot
go 1.23.6

require (
cloud.google.com/go/pubsub v1.48.1
cloud.google.com/go/pubsub v1.49.0
github.com/Masterminds/semver/v3 v3.3.1
github.com/Masterminds/sprig/v3 v3.3.0
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/public v0.1.11
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/prometheus/client_golang v1.21.1
github.com/prometheus/client_golang v1.22.0
github.com/robfig/cron/v3 v3.0.1
github.com/rs/xid v1.6.0
github.com/rs/zerolog v1.34.0
github.com/slack-go/slack v0.16.0
github.com/spf13/viper v1.20.1
google.golang.org/api v0.228.0
google.golang.org/api v0.229.0
)

require (
cloud.google.com/go v0.120.0 // indirect
cloud.google.com/go/auth v0.15.0 // indirect
cloud.google.com/go/auth v0.16.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
cloud.google.com/go/compute/metadata v0.6.0 // indirect
cloud.google.com/go/iam v1.4.2 // indirect
Expand Down Expand Up @@ -52,7 +52,6 @@ require (
github.com/hashicorp/go-plugin v1.6.3 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect
github.com/mattermost/ldap v0.0.0-20231116144001-0f480c025956 // indirect
github.com/mattermost/logr/v2 v2.0.21 // indirect
Expand Down Expand Up @@ -84,25 +83,25 @@ require (
github.com/wiggin77/srslog v1.0.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.37.0 // indirect
golang.org/x/oauth2 v0.28.0 // indirect
golang.org/x/sync v0.12.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/net v0.39.0 // indirect
golang.org/x/oauth2 v0.29.0 // indirect
golang.org/x/sync v0.13.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
golang.org/x/time v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20250303144028-a0af3efb3deb // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250313205543-e70fdf4c4cb4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirect
google.golang.org/grpc v1.71.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250414145226-207652e42e2e // indirect
google.golang.org/grpc v1.71.1 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading