execute

package
v1.7.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 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 added in v1.0.0

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

GetInstallHelpForKnownPlugin returns install help for a known plugin.

func IsExecutionCommandError added in v0.15.0

func IsExecutionCommandError(err error) bool

IsExecutionCommandError returns true if a given error is ExecutionCommandError.

Types

type ActionExecutor added in v0.16.0

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

ActionExecutor executes all commands that are related to actions.

func NewActionExecutor added in v0.16.0

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

NewActionExecutor returns a new ActionExecutor instance.

func (*ActionExecutor) ActionsTabularOutput added in v0.16.0

func (e *ActionExecutor) ActionsTabularOutput() string

ActionsTabularOutput sorts actions by key and returns a printable table

func (*ActionExecutor) Commands added in v0.17.0

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

Commands returns slice of commands the executor supports

func (*ActionExecutor) Disable added in v0.17.0

Disable disables given action in the runtime config map

func (*ActionExecutor) Enable added in v0.17.0

Enable enables given action in the runtime config map

func (*ActionExecutor) FeatureName added in v0.17.0

func (e *ActionExecutor) FeatureName() FeatureName

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

func (*ActionExecutor) List added in v0.17.0

List returns a tabular representation of Actions

type ActionsStorage added in v1.0.0

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

type AliasExecutor added in v0.18.0

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

AliasExecutor executes all commands that are related to aliases.

func NewAliasExecutor added in v0.18.0

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

NewAliasExecutor returns a new AliasExecutor instance.

func (*AliasExecutor) Commands added in v0.18.0

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

Commands returns slice of commands the executor supports.

func (*AliasExecutor) FeatureName added in v0.18.0

func (e *AliasExecutor) FeatureName() FeatureName

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

func (*AliasExecutor) List added in v0.18.0

List returns a tabular representation of aliases.

type AnalyticsReporter added in v0.13.0

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 added in v0.14.0

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 added in v0.17.0

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 added in v0.17.0

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 added in v0.17.0

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

CommandExecutor defines command structure for executors

type CommandFn added in v0.17.0

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

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

type CommandGuard added in v0.15.0

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 added in v0.17.0

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

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

func NewCmdsMapping added in v0.17.0

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

NewCmdsMapping registers command and help mappings

func (*CommandMapping) FindFn added in v0.17.0

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

FindFn looks up CommandFn by verb and feature

func (*CommandMapping) HelpMessageForVerb added in v0.17.0

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

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

type ConfigExecutor added in v0.17.0

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

ConfigExecutor executes all commands that are related to config

func NewConfigExecutor added in v0.17.0

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

NewConfigExecutor returns a new ConfigExecutor instance

func (*ConfigExecutor) Commands added in v0.17.0

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

Commands returns slice of commands the executor supports

func (*ConfigExecutor) FeatureName added in v0.17.0

func (e *ConfigExecutor) FeatureName() FeatureName

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

func (*ConfigExecutor) Show added in v0.17.0

Show returns Config in yaml format

type Conversation added in v0.14.0

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
}

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 added in v0.18.0

type DefaultExecutorFactory added in v0.13.0

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

DefaultExecutorFactory facilitates creation of the Executor instances.

func NewExecutorFactory added in v0.13.0

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

NewExecutorFactory creates new DefaultExecutorFactory.

func (*DefaultExecutorFactory) NewDefault added in v0.13.0

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

NewDefault creates new Default Executor.

type DefaultExecutorFactoryParams added in v0.14.0

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 added in v0.17.0

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

ExecExecutor executes all commands that are related to executors.

func NewExecExecutor added in v0.17.0

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

NewExecExecutor returns a new ExecExecutor instance.

func (*ExecExecutor) Commands added in v0.17.0

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

Commands returns slice of commands the executor supports

func (*ExecExecutor) FeatureName added in v0.17.0

func (e *ExecExecutor) FeatureName() FeatureName

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

func (*ExecExecutor) List added in v0.17.0

List returns a tabular representation of Executors

func (*ExecExecutor) TabularOutput added in v0.17.0

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

TabularOutput sorts executor groups by key and returns a printable table

type ExecutionCommandError added in v0.15.0

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 added in v0.15.0

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 added in v0.15.0

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 added in v0.17.0

type FeatureName struct {
	Name    string
	Aliases []string
}

FeatureName defines the name and aliases for a feature

type FeedbackExecutor added in v0.17.0

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

FeedbackExecutor executes all commands that are related to feedback.

func NewFeedbackExecutor added in v0.17.0

func NewFeedbackExecutor(log logrus.FieldLogger) *FeedbackExecutor

NewFeedbackExecutor returns a new FeedbackExecutor instance

func (*FeedbackExecutor) Commands added in v0.17.0

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

Commands returns slice of commands the executor supports

func (*FeedbackExecutor) FeatureName added in v0.17.0

func (e *FeedbackExecutor) FeatureName() FeatureName

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

func (*FeedbackExecutor) Feedback added in v0.17.0

Feedback responds with a feedback form URL

type Flags added in v0.17.0

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

Flags contains cmd line arguments for executors.

func ParseFlags added in v0.17.0

func ParseFlags(cmd string) (Flags, error)

ParseFlags parses raw cmd and removes optional params with flags.

type HelpExecutor added in v0.17.0

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

HelpExecutor executes all commands that are related to help

func NewHelpExecutor added in v0.17.0

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

NewHelpExecutor returns a new HelpExecutor instance

func (*HelpExecutor) Commands added in v0.17.0

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

Commands returns slice of commands the executor supports

func (*HelpExecutor) FeatureName added in v0.17.0

func (e *HelpExecutor) FeatureName() FeatureName

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

func (*HelpExecutor) Help added in v0.17.0

Help returns new help message

type NewDefaultInput added in v0.14.0

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 added in v1.0.0

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 added in v0.13.0

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

NotifierExecutor executes all commands that are related to notifications.

func NewNotifierExecutor added in v0.13.0

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

NewNotifierExecutor creates a new instance of NotifierExecutor

func (*NotifierExecutor) Commands added in v0.17.0

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

Commands returns slice of commands the executor supports

func (*NotifierExecutor) Disable added in v0.17.0

Disable stops the notifier

func (*NotifierExecutor) Enable added in v0.17.0

Enable starts the notifier

func (*NotifierExecutor) FeatureName added in v0.17.0

func (e *NotifierExecutor) FeatureName() FeatureName

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

func (*NotifierExecutor) Status added in v0.17.0

Status returns the status of a notifier (per channel)

type NotifierHandler added in v0.13.0

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 added in v0.17.0

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

PingExecutor executes all commands that are related to ping.

func NewPingExecutor added in v0.17.0

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

NewPingExecutor returns a new PingExecutor instance.

func (*PingExecutor) Commands added in v0.17.0

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

Commands returns slice of commands the executor supports

func (*PingExecutor) FeatureName added in v0.17.0

func (e *PingExecutor) FeatureName() FeatureName

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

func (*PingExecutor) Ping added in v0.17.0

Ping responds with "pong" to the ping command

type PluginExecutor added in v0.17.0

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

PluginExecutor provides functionality to run registered Botkube plugins.

func NewPluginExecutor added in v0.17.0

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 added in v0.17.0

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

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

func (*PluginExecutor) Execute added in v0.17.0

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 added in v0.17.0

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 added in v0.18.0

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

type SourceBindingExecutor added in v0.17.0

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

SourceBindingExecutor provides functionality to run all Botkube SourceBinding related commands.

func NewSourceBindingExecutor added in v0.17.0

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

NewSourceBindingExecutor returns a new SourceBindingExecutor instance.

func (*SourceBindingExecutor) Commands added in v0.17.0

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

Commands returns slice of commands the executor supports

func (*SourceBindingExecutor) Edit added in v0.17.0

Edit executes the edit command based on args.

func (*SourceBindingExecutor) FeatureName added in v0.17.0

func (e *SourceBindingExecutor) FeatureName() FeatureName

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

func (*SourceBindingExecutor) Status added in v0.17.0

Status returns all sources per given channel

type SourceExecutor added in v0.17.0

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

SourceExecutor executes all commands that are related to sources.

func NewSourceExecutor added in v0.17.0

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

NewSourceExecutor returns a new SourceExecutor instance.

func (*SourceExecutor) Commands added in v0.17.0

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

Commands returns slice of commands the executor supports

func (*SourceExecutor) FeatureName added in v0.17.0

func (e *SourceExecutor) FeatureName() FeatureName

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

func (*SourceExecutor) List added in v0.17.0

List returns a tabular representation of Executors

func (*SourceExecutor) TabularOutput added in v0.17.0

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

TabularOutput sorts source groups by key and returns a printable table

type UserInput added in v1.0.0

type UserInput struct {
	Mention     string
	DisplayName string
}

UserInput contains details about the user.

type VersionExecutor added in v0.17.0

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

VersionExecutor executes all commands that are related to version.

func NewVersionExecutor added in v0.17.0

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

NewVersionExecutor returns a new VersionExecutor instance

func (*VersionExecutor) Commands added in v0.17.0

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

Commands returns slice of commands the executor supports

func (*VersionExecutor) FeatureName added in v0.17.0

func (e *VersionExecutor) FeatureName() FeatureName

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

func (*VersionExecutor) Version added in v0.17.0

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