execute

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: MIT Imports: 23 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

This section is empty.

Types

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, isButtonClickOrigin 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 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 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
}

ConfigPersistenceManager manages persistence of the configuration.

type Conversation added in v0.14.0

type Conversation struct {
	Alias               string
	ID                  string
	ExecutorBindings    []string
	IsAuthenticated     bool
	IsButtonClickOrigin bool
}

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() 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
}

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 Executor

type Executor interface {
	Execute() interactive.Message
}

Executor is an interface for processes to execute commands

type FiltersAction added in v0.8.0

type FiltersAction string

FiltersAction for options in filter commands

const (
	FilterList    FiltersAction = "list"
	FilterEnable  FiltersAction = "enable"
	FilterDisable FiltersAction = "disable"
)

Filter command options

func (FiltersAction) String added in v0.8.0

func (action FiltersAction) String() string

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

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

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

func (e *Kubectl) Execute(bindings []string, command string, isAuthChannel bool) (string, error)

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

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

GetCommandPrefix gets verb command with k8s alias prefix.

func (*Kubectl) GetVerb added in v0.14.0

func (e *Kubectl) GetVerb(args []string) string

GetVerb gets verb command for k8s ignoring k8s alias prefix.

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

func (*OSCommand) RunCombinedOutput(command string, args []string) (string, error)

RunCombinedOutput runs a given command and returns its combined standard output and standard error.

func (*OSCommand) RunSeparateOutput added in v0.13.0

func (*OSCommand) RunSeparateOutput(command string, args []string) (string, string, error)

RunSeparateOutput runs a given command and returns separately its standard output and standard error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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