execute

package
v0.0.0-...-18039e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotificationsNotConfigured describes an error when user wants to toggle on/off the notifications for not configured channel.
	ErrNotificationsNotConfigured = errors.New("notifications not configured for this channel")
)

Functions

func GetInstallHelpForKnownPlugin

func GetInstallHelpForKnownPlugin(args []string) (string, bool)

GetInstallHelpForKnownPlugin returns install help for a known plugin.

func IsExecutionCommandError

func IsExecutionCommandError(err error) bool

IsExecutionCommandError returns true if a given error is ExecutionCommandError.

Types

type ActionExecutor

type ActionExecutor struct {
	// contains filtered or unexported fields
}

ActionExecutor executes all commands that are related to actions.

func NewActionExecutor

func NewActionExecutor(log logrus.FieldLogger, cfgManager ActionsStorage, cfg config.Config) *ActionExecutor

NewActionExecutor returns a new ActionExecutor instance.

func (*ActionExecutor) ActionsTabularOutput

func (e *ActionExecutor) ActionsTabularOutput() string

ActionsTabularOutput sorts actions by key and returns a printable table

func (*ActionExecutor) Commands

func (e *ActionExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports

func (*ActionExecutor) Disable

Disable disables given action in the runtime config map

func (*ActionExecutor) Enable

Enable enables given action in the runtime config map

func (*ActionExecutor) FeatureName

func (e *ActionExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor

func (*ActionExecutor) List

List returns a tabular representation of Actions

type ActionsStorage

type ActionsStorage interface {
	PersistActionEnabled(ctx context.Context, name string, enabled bool) error
}

type AliasExecutor

type AliasExecutor struct {
	// contains filtered or unexported fields
}

AliasExecutor executes all commands that are related to aliases.

func NewAliasExecutor

func NewAliasExecutor(log logrus.FieldLogger, cfg config.Config) *AliasExecutor

NewAliasExecutor returns a new AliasExecutor instance.

func (*AliasExecutor) Commands

func (e *AliasExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports.

func (*AliasExecutor) FeatureName

func (e *AliasExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor.

func (*AliasExecutor) List

List returns a tabular representation of aliases.

type AnalyticsReporter

type AnalyticsReporter interface {
	// ReportCommand reports a new executed command. The command should be anonymized before using this method.
	ReportCommand(in analytics.ReportCommandInput) error
}

AnalyticsReporter defines a reporter that collects analytics data.

type BindingsStorage

type BindingsStorage interface {
	PersistSourceBindings(ctx context.Context, commGroupName string, platform config.CommPlatformIntegration, channelAlias string, sourceBindings []string) error
}

BindingsStorage provides functionality to persist source binding for a given channel.

type CommandContext

type CommandContext struct {
	// ExpandedRawCmd is a raw command with expanded aliases.
	ExpandedRawCmd string

	Args                []string
	ClusterName         string
	CommGroupName       string
	CleanCmd            string
	ProvidedClusterName string
	User                UserInput
	Conversation        Conversation
	Platform            config.CommPlatformIntegration
	ExecutorFilter      executorFilter
	NotifierHandler     NotifierHandler
	Mapping             *CommandMapping
	CmdHeader           string
	PluginHealthStats   *plugin.HealthStats
	AuditContext        map[string]interface{}
}

CommandContext contains the context for CommandFn

func (CommandContext) ProvidedClusterNameEqualOrEmpty

func (cmdCtx CommandContext) ProvidedClusterNameEqualOrEmpty() bool

ProvidedClusterNameEqualOrEmpty returns true when provided cluster name is empty or when provided cluster name is equal to cluster name

type CommandExecutor

type CommandExecutor interface {
	Commands() map[command.Verb]CommandFn
	FeatureName() FeatureName
}

CommandExecutor defines command structure for executors

type CommandFn

type CommandFn func(ctx context.Context, cmdCtx CommandContext) (interactive.CoreMessage, error)

CommandFn is a single command (eg. List())

type CommandGuard

type CommandGuard interface {
	GetAllowedResourcesForVerb(verb string, allConfiguredResources []string) ([]guard.Resource, error)
	GetResourceDetails(verb, resourceType string) (guard.Resource, error)
	FilterSupportedVerbs(allVerbs []string) []string
}

CommandGuard is an interface that allows to check if a given command is allowed to be executed.

type CommandMapping

type CommandMapping struct {
	// contains filtered or unexported fields
}

CommandMapping allows to register and lookup commands and dynamically build help messages

func NewCmdsMapping

func NewCmdsMapping(executors []CommandExecutor) (*CommandMapping, error)

NewCmdsMapping registers command and help mappings

func (*CommandMapping) FindFn

func (m *CommandMapping) FindFn(verb command.Verb, feature string) (CommandFn, bool, bool)

FindFn looks up CommandFn by verb and feature

func (*CommandMapping) HelpMessageForVerb

func (m *CommandMapping) HelpMessageForVerb(verb command.Verb) string

HelpMessageForVerb dynamically builds help message for given command.Verb, or empty string

type ConfigExecutor

type ConfigExecutor struct {
	// contains filtered or unexported fields
}

ConfigExecutor executes all commands that are related to config

func NewConfigExecutor

func NewConfigExecutor(log logrus.FieldLogger, config config.Config) *ConfigExecutor

NewConfigExecutor returns a new ConfigExecutor instance

func (*ConfigExecutor) Commands

func (e *ConfigExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports

func (*ConfigExecutor) FeatureName

func (e *ConfigExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor

func (*ConfigExecutor) Show

Show returns Config in yaml format

type Conversation

type Conversation struct {
	Alias            string
	DisplayName      string
	ID               string
	ExecutorBindings []string
	SourceBindings   []string
	IsKnown          bool
	CommandOrigin    command.Origin
	SlackState       *slack.BlockActionStates
	URL              string
	Text             string
	ParentActivityID string
}

Conversation contains details about the conversation.

type DefaultExecutor

type DefaultExecutor struct {
	// contains filtered or unexported fields
}

DefaultExecutor is a default implementations of Executor

func (*DefaultExecutor) Execute

Execute executes commands and returns output

func (*DefaultExecutor) ExecuteHelp

type DefaultExecutorFactory

type DefaultExecutorFactory struct {
	// contains filtered or unexported fields
}

DefaultExecutorFactory facilitates creation of the Executor instances.

func NewExecutorFactory

func NewExecutorFactory(params DefaultExecutorFactoryParams) (*DefaultExecutorFactory, error)

NewExecutorFactory creates new DefaultExecutorFactory.

func (*DefaultExecutorFactory) NewDefault

func (f *DefaultExecutorFactory) NewDefault(cfg NewDefaultInput) Executor

NewDefault creates new Default Executor.

type DefaultExecutorFactoryParams

type DefaultExecutorFactoryParams struct {
	Log               logrus.FieldLogger
	Cfg               config.Config
	CfgManager        config.PersistenceManager
	AnalyticsReporter AnalyticsReporter
	CommandGuard      CommandGuard
	PluginManager     *plugin.Manager
	RestCfg           *rest.Config
	BotKubeVersion    string
	AuditReporter     audit.AuditReporter
	PluginHealthStats *plugin.HealthStats
}

DefaultExecutorFactoryParams contains input parameters for DefaultExecutorFactory.

type ExecExecutor

type ExecExecutor struct {
	// contains filtered or unexported fields
}

ExecExecutor executes all commands that are related to executors.

func NewExecExecutor

func NewExecExecutor(log logrus.FieldLogger, cfg config.Config) *ExecExecutor

NewExecExecutor returns a new ExecExecutor instance.

func (*ExecExecutor) Commands

func (e *ExecExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports

func (*ExecExecutor) FeatureName

func (e *ExecExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor

func (*ExecExecutor) List

List returns a tabular representation of Executors

func (*ExecExecutor) TabularOutput

func (e *ExecExecutor) TabularOutput(bindings []string, stats *plugin.HealthStats) string

TabularOutput sorts executor groups by key and returns a printable table

type ExecutionCommandError

type ExecutionCommandError struct {
	// contains filtered or unexported fields
}

ExecutionCommandError defines error occurred during command execution. Use it only if you want to print the error message details to end-users.

func NewExecutionCommandError

func NewExecutionCommandError(format string, args ...any) *ExecutionCommandError

NewExecutionCommandError creates a new ExecutionCommandError instance. Messages should be suitable to be printed to the end user.

func (*ExecutionCommandError) Error

func (e *ExecutionCommandError) Error() string

Error returns error message

type Executor

type Executor interface {
	Execute(context.Context) interactive.CoreMessage
}

Executor is an interface for processes to execute commands

type FeatureName

type FeatureName struct {
	Name    string
	Aliases []string
}

FeatureName defines the name and aliases for a feature

type FeedbackExecutor

type FeedbackExecutor struct {
	// contains filtered or unexported fields
}

FeedbackExecutor executes all commands that are related to feedback.

func NewFeedbackExecutor

func NewFeedbackExecutor(log logrus.FieldLogger) *FeedbackExecutor

NewFeedbackExecutor returns a new FeedbackExecutor instance

func (*FeedbackExecutor) Commands

func (e *FeedbackExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports

func (*FeedbackExecutor) FeatureName

func (e *FeedbackExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor

func (*FeedbackExecutor) Feedback

Feedback responds with a feedback form URL

type Flags

type Flags struct {
	CleanCmd     string
	Filter       string
	ClusterName  string
	TokenizedCmd []string
	CmdHeader    string
}

Flags contains cmd line arguments for executors.

func ParseFlags

func ParseFlags(cmd string) (Flags, error)

ParseFlags parses raw cmd and removes optional params with flags.

type HelpExecutor

type HelpExecutor struct {
	// contains filtered or unexported fields
}

HelpExecutor executes all commands that are related to help

func NewHelpExecutor

func NewHelpExecutor(log logrus.FieldLogger, cfg config.Config) *HelpExecutor

NewHelpExecutor returns a new HelpExecutor instance

func (*HelpExecutor) Commands

func (e *HelpExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports

func (*HelpExecutor) FeatureName

func (e *HelpExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor

func (*HelpExecutor) Help

Help returns new help message

type NewDefaultInput

type NewDefaultInput struct {
	CommGroupName   string
	Platform        config.CommPlatformIntegration
	NotifierHandler NotifierHandler
	Conversation    Conversation
	Message         string
	User            UserInput
	AuditContext    map[string]interface{}
}

NewDefaultInput an input for NewDefault

type NotificationsStorage

type NotificationsStorage interface {
	PersistNotificationsEnabled(ctx context.Context, commGroupName string, platform config.CommPlatformIntegration, channelAlias string, enabled bool) error
}

NotificationsStorage provides functionality to persist notifications config for a given channel.

type NotifierExecutor

type NotifierExecutor struct {
	// contains filtered or unexported fields
}

NotifierExecutor executes all commands that are related to notifications.

func NewNotifierExecutor

func NewNotifierExecutor(log logrus.FieldLogger, cfgManager NotificationsStorage) *NotifierExecutor

NewNotifierExecutor creates a new instance of NotifierExecutor

func (*NotifierExecutor) Commands

func (e *NotifierExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports

func (*NotifierExecutor) Disable

Disable stops the notifier

func (*NotifierExecutor) Enable

Enable starts the notifier

func (*NotifierExecutor) FeatureName

func (e *NotifierExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor

func (*NotifierExecutor) Status

Status returns the status of a notifier (per channel)

type NotifierHandler

type NotifierHandler interface {
	// NotificationsEnabled returns current notification status for a given conversation ID.
	NotificationsEnabled(conversationID string) bool

	// SetNotificationsEnabled sets a new notification status for a given conversation ID.
	SetNotificationsEnabled(conversationID string, enabled bool) error
}

NotifierHandler handles disabling and enabling notifications for a given communication platform.

type PingExecutor

type PingExecutor struct {
	// contains filtered or unexported fields
}

PingExecutor executes all commands that are related to ping.

func NewPingExecutor

func NewPingExecutor(log logrus.FieldLogger, botkubeVersion string) *PingExecutor

NewPingExecutor returns a new PingExecutor instance.

func (*PingExecutor) Commands

func (e *PingExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports

func (*PingExecutor) FeatureName

func (e *PingExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor

func (*PingExecutor) Ping

Ping responds with "pong" to the ping command

type PluginExecutor

type PluginExecutor struct {
	// contains filtered or unexported fields
}

PluginExecutor provides functionality to run registered Botkube plugins.

func NewPluginExecutor

func NewPluginExecutor(log logrus.FieldLogger, cfg config.Config, manager *plugin.Manager, restCfg *rest.Config) *PluginExecutor

NewPluginExecutor creates a new instance of PluginExecutor.

func (*PluginExecutor) CanHandle

func (e *PluginExecutor) CanHandle(bindings []string, args []string) bool

CanHandle returns true if it's a known plugin executor.

func (*PluginExecutor) Execute

func (e *PluginExecutor) Execute(ctx context.Context, bindings []string, slackState *slack.BlockActionStates, cmdCtx CommandContext) (interactive.CoreMessage, error)

Execute executes plugin executor based on a given command.

func (*PluginExecutor) GetCommandPrefix

func (e *PluginExecutor) GetCommandPrefix(args []string) string

GetCommandPrefix returns plugin name and the verb if present. If the verb is multi-word, it returns a placeholder for it.

func (*PluginExecutor) Help

func (e *PluginExecutor) Help(ctx context.Context, bindings []string, cmdCtx CommandContext) (interactive.CoreMessage, error)

type SourceBindingExecutor

type SourceBindingExecutor struct {
	// contains filtered or unexported fields
}

SourceBindingExecutor provides functionality to run all Botkube SourceBinding related commands.

func NewSourceBindingExecutor

func NewSourceBindingExecutor(log logrus.FieldLogger, cfgManager BindingsStorage, cfg config.Config) *SourceBindingExecutor

NewSourceBindingExecutor returns a new SourceBindingExecutor instance.

func (*SourceBindingExecutor) Commands

func (e *SourceBindingExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports

func (*SourceBindingExecutor) Edit

Edit executes the edit command based on args.

func (*SourceBindingExecutor) FeatureName

func (e *SourceBindingExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor

func (*SourceBindingExecutor) Status

Status returns all sources per given channel

type SourceExecutor

type SourceExecutor struct {
	// contains filtered or unexported fields
}

SourceExecutor executes all commands that are related to sources.

func NewSourceExecutor

func NewSourceExecutor(log logrus.FieldLogger, cfg config.Config) *SourceExecutor

NewSourceExecutor returns a new SourceExecutor instance.

func (*SourceExecutor) Commands

func (e *SourceExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports

func (*SourceExecutor) FeatureName

func (e *SourceExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor

func (*SourceExecutor) List

List returns a tabular representation of Executors

func (*SourceExecutor) TabularOutput

func (e *SourceExecutor) TabularOutput(bindings []string, stats *plugin.HealthStats) string

TabularOutput sorts source groups by key and returns a printable table

type UserInput

type UserInput struct {
	Mention     string
	DisplayName string
}

UserInput contains details about the user.

type VersionExecutor

type VersionExecutor struct {
	// contains filtered or unexported fields
}

VersionExecutor executes all commands that are related to version.

func NewVersionExecutor

func NewVersionExecutor(log logrus.FieldLogger, botkubeVersion string) *VersionExecutor

NewVersionExecutor returns a new VersionExecutor instance

func (*VersionExecutor) Commands

func (e *VersionExecutor) Commands() map[command.Verb]CommandFn

Commands returns slice of commands the executor supports

func (*VersionExecutor) FeatureName

func (e *VersionExecutor) FeatureName() FeatureName

FeatureName returns the name and aliases of the feature provided by this executor

func (*VersionExecutor) Version

Version responds with k8s and botkube version string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL