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

Support channel-based group mapping for Cloud Teams #1327

Merged
merged 2 commits into from
Dec 4, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19

go-version-file: 'go.mod'
cache: true
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
4 changes: 3 additions & 1 deletion cmd/cli/cmd/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import "github.com/spf13/cobra"
import (
"github.com/spf13/cobra"
)

// NewCmd returns a new cobra.Command subcommand for config-related operations.
func NewCmd() *cobra.Command {
Expand Down
4 changes: 3 additions & 1 deletion cmd/cli/cmd/telemetry/telemetry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package telemetry

import "github.com/spf13/cobra"
import (
"github.com/spf13/cobra"
)

// NewCmd returns a new cobra.Command subcommand for telemetry-related operations.
func NewCmd() *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/kubeshop/botkube

go 1.21

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/DanielTitkov/go-adaptive-cards v0.2.2
Expand Down Expand Up @@ -280,8 +282,6 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

go 1.19

replace (
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp => go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
go.opentelemetry.io/otel => go.opentelemetry.io/otel v1.16.0
Expand Down
51 changes: 51 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hack/fmt-imports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -E # needs to be set if we want the ERR trap

CURRENT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
REPO_ROOT_DIR=$(cd "${CURRENT_DIR}/.." && pwd)
GOIMPORTS_REVISER_VERSION=3.3.1
GOIMPORTS_REVISER_VERSION=3.6.0

host::os() {
local host_os
Expand Down
4 changes: 3 additions & 1 deletion internal/cli/analytics/cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package analytics

import "github.com/spf13/cobra"
import (
"github.com/spf13/cobra"
)

// InjectAnalyticsReporting injects analytics reporting into the command.
func InjectAnalyticsReporting(in cobra.Command, cmdName string) *cobra.Command {
Expand Down
4 changes: 3 additions & 1 deletion internal/config/flag.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import "github.com/spf13/pflag"
import (
"github.com/spf13/pflag"
)

var configPathsFlag []string

Expand Down
4 changes: 3 additions & 1 deletion internal/config/reloader/noop.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package reloader

import "context"
import (
"context"
)

var _ Reloader = (*NoopReloader)(nil)

Expand Down
4 changes: 3 additions & 1 deletion internal/config/reloader/reloader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package reloader

import "context"
import (
"context"
)

// Reloader is an interface for reloading configuration.
type Reloader interface {
Expand Down
4 changes: 3 additions & 1 deletion internal/config/remote/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package remote

import "os"
import (
"os"
)

const (
// ProviderEndpointEnvKey holds config provider endpoint.
Expand Down
4 changes: 3 additions & 1 deletion internal/executor/kubectl/builder/strings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package builder

import "strings"
import (
"strings"
)

func overflowSentence(in []string) []string {
for idx := range in {
Expand Down
4 changes: 3 additions & 1 deletion internal/executor/kubectl/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kubectl

import "github.com/MakeNowJust/heredoc"
import (
"github.com/MakeNowJust/heredoc"
)

func optionsCommandOutput() string {
return heredoc.Doc(`
Expand Down
4 changes: 3 additions & 1 deletion internal/executor/thread-mate/commands.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package thread_mate

import "strings"
import (
"strings"
)

type (
// Commands represents a collection of subcommands.
Expand Down
4 changes: 3 additions & 1 deletion internal/ptr/ptr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ptr

import "golang.org/x/exp/constraints"
import (
"golang.org/x/exp/constraints"
)

// ToSlice converts a given slice of pointers to slice with non-nil elems.
func ToSlice[T any](in []*T) []T {
Expand Down
39 changes: 25 additions & 14 deletions pkg/api/cloudteams/cloud_teams.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions pkg/bot/teams_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ func (b *CloudTeams) handleStreamMessage(ctx context.Context, data *pb.CloudActi
}
switch act.Type {
case schema.Message, schema.Invoke:
b.log.WithField("message", formatx.StructDumper().Sdump(act)).Debug("Processing Cloud message...")
b.log.WithFields(logrus.Fields{
"message": formatx.StructDumper().Sdump(act),
"conversationDisplayName": data.ConversationDisplayName,
}).Debug("Processing Cloud message...")
channel, exists, err := b.getChannelForActivity(act)
if err != nil {
b.log.WithError(err).Error("cannot extract message channel id, processing with empty...")
}

msg := b.processMessage(ctx, act, channel, exists)
msg := b.processMessage(ctx, act, channel, data.ConversationDisplayName, exists)
if msg.IsEmpty() {
b.log.WithField("activityID", act.ID).Debug("Empty message... Skipping sending response")
return nil, nil
Expand All @@ -287,7 +289,7 @@ func (b *CloudTeams) handleStreamMessage(ctx context.Context, data *pb.CloudActi
}
}

func (b *CloudTeams) processMessage(ctx context.Context, act schema.Activity, channel teamsCloudChannelConfigByID, exists bool) interactive.CoreMessage {
func (b *CloudTeams) processMessage(ctx context.Context, act schema.Activity, channel teamsCloudChannelConfigByID, channelDisplayName string, exists bool) interactive.CoreMessage {
trimmedMsg := b.trimBotMention(act.Text)

e := b.executorFactory.NewDefault(execute.NewDefaultInput{
Expand All @@ -301,6 +303,7 @@ func (b *CloudTeams) processMessage(ctx context.Context, act schema.Activity, ch
ExecutorBindings: channel.Bindings.Executors,
SourceBindings: channel.Bindings.Sources,
CommandOrigin: command.TypedOrigin,
DisplayName: channelDisplayName,
},
Message: trimmedMsg,
User: execute.UserInput{
Expand Down
4 changes: 3 additions & 1 deletion pkg/conversation/normalize.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package conversation

import "strings"
import (
"strings"
)

// NormalizeChannelIdentifier removes leading and trailing spaces and # from the channel name.
// this is platform-agnostic, as different platforms use different rules:
Expand Down
9 changes: 8 additions & 1 deletion pkg/execute/plugin_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,16 @@ func (e *PluginExecutor) Execute(ctx context.Context, bindings []string, slackSt
return interactive.CoreMessage{}, fmt.Errorf("while collecting configs: %w", err)
}

channel := cmdCtx.Conversation.DisplayName
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may be useful to put it in the docs 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, honestly, as we use channel name for all platforms: https://docs.botkube.io/configuration/rbac#mapping-types

image

The fallback I did is for e.g. new platforms if we forget passing display name.

Does it make sense?

if channel == "" {
channel = cmdCtx.Conversation.ID
}

input := plugin.KubeConfigInput{
Channel: cmdCtx.Conversation.DisplayName,
Channel: channel,
}
e.log.WithField("input", input).Debug("Generating Kubeconfig...")

kubeconfig, err := plugin.GenerateKubeConfig(e.restCfg, e.cfg.Settings.ClusterName, plugins[0].Context, input)
if err != nil {
return interactive.CoreMessage{}, fmt.Errorf("while generating kube config: %w", err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/pluginx/command_opts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package pluginx

import "io"
import (
"io"
)

// ExecuteCommandOptions represents the options for executing a command.
type ExecuteCommandOptions struct {
Expand Down
1 change: 1 addition & 0 deletions proto/cloud_teams.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ message Message {

message CloudActivity {
bytes event = 1;
string conversationDisplayName = 2;
}

service CloudTeams {
Expand Down
Loading