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

Add logging when executing a command in not configured channel #1061

Merged
merged 3 commits into from
May 12, 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
386 changes: 193 additions & 193 deletions helm/botkube/README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion helm/botkube/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ sources:
# @default -- See the `values.yaml` file for full object.
botkube/kubernetes:
context: &default-plugin-context
defaultNamespace: "default"
# -- RBAC configuration for this plugin.
rbac:
group:
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (p *Provider) ExecuteAction(ctx context.Context, action Action) interactive
userName := fmt.Sprintf("Automation %q", action.DisplayName)
e := p.executorFactory.NewDefault(execute.NewDefaultInput{
Conversation: execute.Conversation{
IsAuthenticated: true,
IsKnown: true,
ExecutorBindings: action.ExecutorBindings,
CommandOrigin: command.AutomationOrigin,
Alias: unknownValue,
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestProvider_ExecuteEventAction(t *testing.T) {
Alias: "n/a",
ID: "n/a",
ExecutorBindings: executorBindings,
IsAuthenticated: true,
IsKnown: true,
CommandOrigin: command.AutomationOrigin,
},
Message: "kubectl get po foo",
Expand Down
3 changes: 1 addition & 2 deletions pkg/bot/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ func (b *Discord) handleMessage(ctx context.Context, dm discordMessage) error {
},
}
}
isAuthChannel := exists

e := b.executorFactory.NewDefault(execute.NewDefaultInput{
CommGroupName: b.commGroupName,
Expand All @@ -240,7 +239,7 @@ func (b *Discord) handleMessage(ctx context.Context, dm discordMessage) error {
ID: channel.Identifier(),
ExecutorBindings: channel.Bindings.Executors,
SourceBindings: channel.Bindings.Sources,
IsAuthenticated: isAuthChannel,
IsKnown: exists,
CommandOrigin: command.TypedOrigin,
},
Message: req,
Expand Down
9 changes: 3 additions & 6 deletions pkg/bot/mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ type Mattermost struct {

// mattermostMessage contains message details to execute command and send back the result
type mattermostMessage struct {
Event *model.WebSocketEvent
IsAuthChannel bool
Event *model.WebSocketEvent
}

// NewMattermost creates a new Mattermost instance.
Expand Down Expand Up @@ -238,7 +237,6 @@ func (b *Mattermost) handleMessage(ctx context.Context, mm *mattermostMessage) e
},
}
}
mm.IsAuthChannel = exists

userName, err := b.getUserName(post.UserId)
if err != nil {
Expand All @@ -258,7 +256,7 @@ func (b *Mattermost) handleMessage(ctx context.Context, mm *mattermostMessage) e
ID: channel.Identifier(),
ExecutorBindings: channel.Bindings.Executors,
SourceBindings: channel.Bindings.Sources,
IsAuthenticated: mm.IsAuthChannel,
IsKnown: exists,
CommandOrigin: command.TypedOrigin,
},
User: execute.UserInput{
Expand Down Expand Up @@ -384,8 +382,7 @@ func (b *Mattermost) listen(ctx context.Context) {
}

mm := &mattermostMessage{
Event: event,
IsAuthChannel: false,
Event: event,
}
err := b.handleMessage(ctx, mm)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/bot/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (b *Slack) handleMessage(ctx context.Context, msg slackMessage) error {
return fmt.Errorf("while getting conversation info: %w", err)
}

channel, isAuthChannel := b.getChannels()[info.Name]
channel, exists := b.getChannels()[info.Name]

e := b.executorFactory.NewDefault(execute.NewDefaultInput{
CommGroupName: b.commGroupName,
Expand All @@ -235,7 +235,7 @@ func (b *Slack) handleMessage(ctx context.Context, msg slackMessage) error {
ID: channel.Identifier(),
DisplayName: channel.Name,
ExecutorBindings: channel.Bindings.Executors,
IsAuthenticated: isAuthChannel,
IsKnown: exists,
CommandOrigin: command.TypedOrigin,
},
Message: request,
Expand Down
4 changes: 2 additions & 2 deletions pkg/bot/socketslack.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (b *SocketSlack) handleMessage(ctx context.Context, event socketSlackMessag
return fmt.Errorf("while getting conversation info: %w", err)
}

channel, isAuthChannel := b.getChannels()[info.Name]
channel, exists := b.getChannels()[info.Name]

e := b.executorFactory.NewDefault(execute.NewDefaultInput{
CommGroupName: b.commGroupName,
Expand All @@ -352,7 +352,7 @@ func (b *SocketSlack) handleMessage(ctx context.Context, event socketSlackMessag
DisplayName: info.Name,
ExecutorBindings: channel.Bindings.Executors,
SourceBindings: channel.Bindings.Sources,
IsAuthenticated: isAuthChannel,
IsKnown: exists,
CommandOrigin: event.CommandOrigin,
SlackState: event.State,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/bot/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (b *Teams) processMessage(ctx context.Context, activity schema.Activity) (i
NotifierHandler: newTeamsNotifMgrForActivity(b, ref),
Conversation: execute.Conversation{
Alias: "",
IsAuthenticated: true,
IsKnown: true,
ID: ref.ChannelID,
ExecutorBindings: b.bindings.Executors,
SourceBindings: b.bindings.Sources,
Expand Down
7 changes: 4 additions & 3 deletions pkg/execute/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (e *DefaultExecutor) Execute(ctx context.Context) interactive.CoreMessage {
cmdCtx.ExecutorFilter = newExecutorTextFilter(flags.Filter)

if len(cmdCtx.Args) == 0 {
if e.conversation.IsAuthenticated {
if e.conversation.IsKnown {
msg, err := e.helpExecutor.Help(ctx, cmdCtx)
if err != nil {
e.log.Errorf("while getting help message: %s", err.Error())
Expand All @@ -118,8 +118,9 @@ func (e *DefaultExecutor) Execute(ctx context.Context) interactive.CoreMessage {
return empty // user specified different target cluster
}

// commands below are executed only if the channel is authorized
if !e.conversation.IsAuthenticated {
// commands below are executed only if the channel is configured
if !e.conversation.IsKnown {
e.log.Info("Unknown conversation. Returning empty message...")
return empty
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/execute/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ type Conversation struct {
ID string
ExecutorBindings []string
SourceBindings []string
IsAuthenticated bool
IsKnown bool
CommandOrigin command.Origin
SlackState *slack.BlockActionStates
}
Expand Down