Documentation ¶
Index ¶
- Variables
- func EmptyResourceNameDropdown() *interactive.Select
- func FilterSection(botName string) interactive.LabelInput
- func InternalErrorSection() interactive.Section
- func IsExecutionCommandError(err error) bool
- func KubectlCmdBuilderMessage(dropdownsBlockID string, verbs interactive.Select, ...) interactive.Message
- func PreviewSection(botName, cmd string, input interactive.LabelInput) []interactive.Section
- func ResourceNamesSelect(botName string, names []string, initialItem string) *interactive.Select
- func ResourceNamespaceSelect(botName string, names []dropdownItem, initialNamespace dropdownItem) *interactive.Select
- func ResourceTypeSelect(botName string, resources []string, initialItem string) *interactive.Select
- func VerbSelect(botName string, verbs []string, initialItem string) *interactive.Select
- type ActionExecutor
- type AnalyticsReporter
- type BindingsStorage
- type CommandCombinedOutputRunner
- type CommandFlags
- type CommandGuard
- type CommandRunner
- type CommandSeparateOutputRunner
- type CommandVerb
- type ConfigPersistenceManager
- type Conversation
- type DefaultExecutor
- type DefaultExecutorFactory
- type DefaultExecutorFactoryParams
- type EditExecutor
- type EditResource
- type ExecutionCommandError
- type Executor
- type Kubectl
- type KubectlCmdBuilder
- type KubectlCmdBuilderOption
- type KubectlCmdBuilderOptions
- type NamespaceLister
- type NewDefaultInput
- type NotifierAction
- type NotifierExecutor
- type NotifierHandler
- type OSCommand
Constants ¶
This section is empty.
Variables ¶
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 EmptyResourceNameDropdown ¶ added in v0.15.0
func EmptyResourceNameDropdown() *interactive.Select
EmptyResourceNameDropdown returns a select that simulates an empty one. Normally, Slack doesn't allow to return a static select with no options. This is a workaround to send a dropdown that it's rendered even if empty. We use that to preserve a proper order in displayed dropdowns.
How it works under the hood:
- This select is converted to external data source (https://api.slack.com/reference/block-kit/block-elements#external_select)
- We change the `min_query_length` to 0 to remove th "Type minimum of 3 characters to see options" message.
- Our backend doesn't return any options, so you see "No result".
- We don't set the command, so the ID of this select is always randomized by Slack server. As a result, the dropdown value is not cached, and we avoid problem with showing the outdated value.
func FilterSection ¶ added in v0.15.0
func FilterSection(botName string) interactive.LabelInput
FilterSection returns filter input block.
func InternalErrorSection ¶ added in v0.15.0
func InternalErrorSection() interactive.Section
InternalErrorSection returns preview command section with Run button.
func IsExecutionCommandError ¶ added in v0.15.0
IsExecutionCommandError returns true if a given error is ExecutionCommandError.
func KubectlCmdBuilderMessage ¶ added in v0.15.0
func KubectlCmdBuilderMessage(dropdownsBlockID string, verbs interactive.Select, opts ...KubectlCmdBuilderOption) interactive.Message
KubectlCmdBuilderMessage returns message for constructing kubectl command.
func PreviewSection ¶ added in v0.15.0
func PreviewSection(botName, cmd string, input interactive.LabelInput) []interactive.Section
PreviewSection returns preview command section with Run button.
func ResourceNamesSelect ¶ added in v0.15.0
func ResourceNamesSelect(botName string, names []string, initialItem string) *interactive.Select
ResourceNamesSelect return drop-down select for kubectl resources names.
func ResourceNamespaceSelect ¶ added in v0.15.0
func ResourceNamespaceSelect(botName string, names []dropdownItem, initialNamespace dropdownItem) *interactive.Select
ResourceNamespaceSelect return drop-down select for kubectl allowed namespaces.
func ResourceTypeSelect ¶ added in v0.15.0
func ResourceTypeSelect(botName string, resources []string, initialItem string) *interactive.Select
ResourceTypeSelect return drop-down select for kubectl resources types.
func VerbSelect ¶ added in v0.15.0
func VerbSelect(botName string, verbs []string, initialItem string) *interactive.Select
VerbSelect return drop-down select for kubectl verbs.
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, analyticsReporter AnalyticsReporter, cfgManager ConfigPersistenceManager, cfg config.Config) *ActionExecutor
NewActionExecutor returns a new ActionExecutor instance.
func (*ActionExecutor) ActionsTabularOutput ¶ added in v0.16.0
func (a *ActionExecutor) ActionsTabularOutput() string
ActionsTabularOutput sorts actions by key and returns a printable table
func (*ActionExecutor) Do ¶ added in v0.16.0
func (a *ActionExecutor) Do(ctx context.Context, args []string, clusterName string, conversation Conversation, platform config.CommPlatformIntegration) (string, error)
Do executes a given action command based on args
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(platform config.CommPlatformIntegration, command string, origin command.Origin, withFilter bool) 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 CommandCombinedOutputRunner ¶ added in v0.13.0
type CommandCombinedOutputRunner interface {
RunCombinedOutput(command string, args []string) (string, error)
}
CommandCombinedOutputRunner provides functionality to run arbitrary commands.
type CommandFlags ¶ added in v0.5.0
type CommandFlags string
CommandFlags creates custom type for flags in botkube
const ( ClusterFlag CommandFlags = "--cluster-name" FollowFlag CommandFlags = "--follow" AbbrFollowFlag CommandFlags = "-f" WatchFlag CommandFlags = "--watch" AbbrWatchFlag CommandFlags = "-w" )
Defines botkube flags
func (CommandFlags) String ¶ added in v0.5.0
func (flag CommandFlags) String() string
type CommandGuard ¶ added in v0.15.0
type CommandGuard interface { GetAllowedResourcesForVerb(verb string, allConfiguredResources []string) ([]kubectl.Resource, error) GetResourceDetails(verb, resourceType string) (kubectl.Resource, error) FilterSupportedVerbs(allVerbs []string) []string }
CommandGuard is an interface that allows to check if a given command is allowed to be executed.
type CommandRunner ¶ added in v0.13.0
type CommandRunner interface { CommandCombinedOutputRunner CommandSeparateOutputRunner }
CommandRunner provides functionality to run arbitrary commands.
type CommandSeparateOutputRunner ¶ added in v0.13.0
type CommandSeparateOutputRunner interface {
RunSeparateOutput(command string, args []string) (string, string, error)
}
CommandSeparateOutputRunner provides functionality to run arbitrary commands.
type CommandVerb ¶ added in v0.16.0
type CommandVerb string
CommandVerb are commands supported by the bot
const ( CommandList CommandVerb = "list" CommandEnable CommandVerb = "enable" CommandDisable CommandVerb = "disable" )
CommandVerb command options
type ConfigPersistenceManager ¶ added in v0.14.0
type ConfigPersistenceManager interface { PersistSourceBindings(ctx context.Context, commGroupName string, platform config.CommPlatformIntegration, channelAlias string, sourceBindings []string) error PersistNotificationsEnabled(ctx context.Context, commGroupName string, platform config.CommPlatformIntegration, channelAlias string, enabled bool) error PersistFilterEnabled(ctx context.Context, name string, enabled bool) error PersistActionEnabled(ctx context.Context, name string, enabled bool) error }
ConfigPersistenceManager manages persistence of the configuration.
type Conversation ¶ added in v0.14.0
type Conversation struct { Alias string ID string ExecutorBindings []string IsAuthenticated bool CommandOrigin command.Origin State *slack.BlockActionStates }
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 ¶
func (e *DefaultExecutor) Execute(ctx context.Context) interactive.Message
Execute executes commands and returns output
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
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 CmdRunner CommandRunner Cfg config.Config FilterEngine filterengine.FilterEngine KcChecker *kubectl.Checker Merger *kubectl.Merger CfgManager ConfigPersistenceManager AnalyticsReporter AnalyticsReporter NamespaceLister NamespaceLister CommandGuard CommandGuard }
DefaultExecutorFactoryParams contains input parameters for DefaultExecutorFactory.
type EditExecutor ¶ added in v0.14.0
type EditExecutor struct {
// contains filtered or unexported fields
}
EditExecutor provides functionality to run all Botkube edit related commands.
func NewEditExecutor ¶ added in v0.14.0
func NewEditExecutor(log logrus.FieldLogger, analyticsReporter AnalyticsReporter, cfgManager BindingsStorage, cfg config.Config) *EditExecutor
NewEditExecutor returns a new EditExecutor instance.
func (*EditExecutor) Do ¶ added in v0.14.0
func (e *EditExecutor) Do(args []string, commGroupName string, platform config.CommPlatformIntegration, conversation Conversation, userID, botName string) (interactive.Message, error)
Do executes a given edit command based on args.
type EditResource ¶ added in v0.14.0
type EditResource string
EditResource defines the name of editable resource
const ( // SourceBindings define name of source binding resource SourceBindings EditResource = "SourceBindings" )
func (EditResource) Key ¶ added in v0.14.0
func (e EditResource) Key() string
Key returns normalized edit resource name.
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.Message
}
Executor is an interface for processes to execute commands
type Kubectl ¶ added in v0.13.0
type Kubectl struct {
// contains filtered or unexported fields
}
Kubectl executes kubectl commands using local binary.
func NewKubectl ¶ added in v0.13.0
func NewKubectl(log logrus.FieldLogger, cfg config.Config, merger *kubectl.Merger, kcChecker *kubectl.Checker, fn CommandCombinedOutputRunner) *Kubectl
NewKubectl creates a new instance of Kubectl.
func (*Kubectl) CanHandle ¶ added in v0.13.0
CanHandle returns true if it's allowed kubectl command that can be handled by this executor.
TODO: we should just introduce a command name explicitly. In this case `@Botkube kubectl get po` instead of `@Botkube get po` As a result, we are able to detect kubectl command but say that you're simply not authorized to use it instead of "Command not supported. (..)"
func (*Kubectl) Execute ¶ added in v0.13.0
Execute executes kubectl command based on a given args.
This method should be called ONLY if: - we are a target cluster, - and Kubectl.CanHandle returned true.
func (*Kubectl) GetCommandPrefix ¶ added in v0.14.0
GetCommandPrefix gets verb command with k8s alias prefix.
type KubectlCmdBuilder ¶ added in v0.15.0
type KubectlCmdBuilder struct {
// contains filtered or unexported fields
}
KubectlCmdBuilder provides functionality to handle interactive kubectl command selection.
func NewKubectlCmdBuilder ¶ added in v0.15.0
func NewKubectlCmdBuilder(log logrus.FieldLogger, merger kcMerger, executor kcExecutor, namespaceLister NamespaceLister, guard CommandGuard) *KubectlCmdBuilder
NewKubectlCmdBuilder returns a new KubectlCmdBuilder instance.
func (*KubectlCmdBuilder) CanHandle ¶ added in v0.15.0
func (e *KubectlCmdBuilder) CanHandle(args []string) bool
CanHandle returns true if it's allowed kubectl command that can be handled by this executor.
func (*KubectlCmdBuilder) Do ¶ added in v0.15.0
func (e *KubectlCmdBuilder) Do(ctx context.Context, args []string, platform config.CommPlatformIntegration, bindings []string, state *slack.BlockActionStates, botName string, header string) (interactive.Message, error)
Do executes a given kc-cmd-builder command based on args.
TODO: once we will have a real use-case, we should abstract the Slack state and introduce our own model.
func (*KubectlCmdBuilder) GetCommandPrefix ¶ added in v0.15.0
func (e *KubectlCmdBuilder) GetCommandPrefix(args []string) string
GetCommandPrefix returns the command prefix only if it's known.
type KubectlCmdBuilderOption ¶ added in v0.15.0
type KubectlCmdBuilderOption func(options *KubectlCmdBuilderOptions)
KubectlCmdBuilderOption defines option mutator signature.
func WithAdditionalSections ¶ added in v0.15.0
func WithAdditionalSections(in ...interactive.Section) KubectlCmdBuilderOption
WithAdditionalSections adds additional sections to a given kubectl KubectlCmdBuilderMessage message.
func WithAdditionalSelects ¶ added in v0.15.0
func WithAdditionalSelects(in ...*interactive.Select) KubectlCmdBuilderOption
WithAdditionalSelects adds additional selects to a given kubectl KubectlCmdBuilderMessage message.
type KubectlCmdBuilderOptions ¶ added in v0.15.0
type KubectlCmdBuilderOptions struct {
// contains filtered or unexported fields
}
KubectlCmdBuilderOptions holds builder message options.
type NamespaceLister ¶ added in v0.15.0
type NamespaceLister interface {
List(ctx context.Context, opts metav1.ListOptions) (*corev1.NamespaceList, error)
}
NamespaceLister provides an option to list all namespaces in a given cluster.
type NewDefaultInput ¶ added in v0.14.0
type NewDefaultInput struct { CommGroupName string Platform config.CommPlatformIntegration NotifierHandler NotifierHandler Conversation Conversation Message string User string }
NewDefaultInput an input for NewDefault
type NotifierAction ¶ added in v0.5.0
type NotifierAction string
NotifierAction creates custom type for notifier actions
const ( Start NotifierAction = "start" Stop NotifierAction = "stop" Status NotifierAction = "status" ShowConfig NotifierAction = "showconfig" )
Defines constants for notifier actions
func (NotifierAction) String ¶ added in v0.5.0
func (action NotifierAction) String() string
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, cfg config.Config, cfgManager ConfigPersistenceManager, analyticsReporter AnalyticsReporter) *NotifierExecutor
NewNotifierExecutor creates a new instance of NotifierExecutor.
func (*NotifierExecutor) Do ¶ added in v0.13.0
func (e *NotifierExecutor) Do(ctx context.Context, args []string, commGroupName string, platform config.CommPlatformIntegration, conversation Conversation, clusterName string, handler NotifierHandler) (string, error)
Do executes a given Notifier command based on args.
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 BotName() string }
NotifierHandler handles disabling and enabling notifications for a given communication platform.
type OSCommand ¶ added in v0.13.0
type OSCommand struct{}
OSCommand provides syntax sugar for working with exec.Command
func (*OSCommand) RunCombinedOutput ¶ added in v0.13.0
RunCombinedOutput runs a given command and returns its combined standard output and standard error.