Documentation ¶
Index ¶
- func EmptyResourceNameDropdown() *api.Select
- func FilterSection() api.LabelInput
- func InternalErrorSection() api.Section
- func KubectlCmdBuilderMessage(dropdownsBlockID string, verbs api.Select, opts ...MesageOption) api.Message
- func PreviewSection(cmd string, input api.LabelInput) []api.Section
- func ResourceNamesSelect(names []string, initialItem string) *api.Select
- func ResourceNamespaceSelect(names []dropdownItem, initialNamespace dropdownItem) *api.Select
- func ResourceTypeSelect(resources []string, initialItem string) *api.Select
- func ShouldHandle(cmd string) bool
- func VerbSelect(verbs []string, initialItem string) *api.Select
- type AllowedResources
- type AuthChecker
- type CommandGuard
- type Config
- type Kubectl
- type KubectlRunner
- type MesageOption
- type MessageOptions
- type NamespaceLister
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmptyResourceNameDropdown ¶
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 InternalErrorSection ¶
InternalErrorSection returns preview command section with Run button.
func KubectlCmdBuilderMessage ¶
func KubectlCmdBuilderMessage(dropdownsBlockID string, verbs api.Select, opts ...MesageOption) api.Message
KubectlCmdBuilderMessage returns message for constructing kubectl command.
func PreviewSection ¶
func PreviewSection(cmd string, input api.LabelInput) []api.Section
PreviewSection returns preview command section with Run button.
func ResourceNamesSelect ¶
ResourceNamesSelect return drop-down select for kubectl resources names.
func ResourceNamespaceSelect ¶
ResourceNamespaceSelect return drop-down select for kubectl allowed namespaces.
func ResourceTypeSelect ¶
ResourceTypeSelect return drop-down select for kubectl resources types.
func ShouldHandle ¶
ShouldHandle returns true if it's a valid command for interactive builder.
Types ¶
type AllowedResources ¶
type AllowedResources struct { // Namespaces if not specified, builder needs to have proper permissions to list all namespaces in the cluster. Namespaces []string `yaml:"namespaces,omitempty"` // Verbs holds allowed verbs, at least one verbs MUST be specified. Verbs []string `yaml:"verbs,omitempty"` // Resources holds allowed resources. Resources []string `yaml:"resources,omitempty"` }
AllowedResources describes interactive builder "building blocks". It's needed to populate dropdowns with proper values.
type AuthChecker ¶
AuthChecker provides an option to check if we can run a kubectl commands with a given permission.
type CommandGuard ¶
type CommandGuard interface { GetAllowedResourcesForVerb(verb string, allConfiguredResources []string) ([]command.Resource, error) GetResourceDetails(verb, resourceType string) (command.Resource, error) FilterSupportedVerbs(allVerbs []string) []string }
CommandGuard is an interface that allows to check if a given command is allowed to be executed.
type Config ¶
type Config struct {
Allowed AllowedResources `yaml:"allowed,omitempty"`
}
Config holds kubectl builder configuration parameters.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns default configuration for command builder.
type Kubectl ¶
type Kubectl struct {
// contains filtered or unexported fields
}
Kubectl provides functionality to handle interactive kubectl command selection.
func NewKubectl ¶
func NewKubectl(kcRunner KubectlRunner, cfg Config, logger logrus.FieldLogger, guard CommandGuard, defaultNamespace string, lister NamespaceLister, authCheck AuthChecker) *Kubectl
NewKubectl returns a new Kubectl instance.
type KubectlRunner ¶
type KubectlRunner interface {
RunKubectlCommand(ctx context.Context, defaultNamespace, cmd string) (string, error)
}
KubectlRunner provides an option to run a given kubectl command.
type MesageOption ¶
type MesageOption func(options *MessageOptions)
MesageOption defines option mutator signature.
func WithAdditionalSections ¶
func WithAdditionalSections(in ...api.Section) MesageOption
WithAdditionalSections adds additional sections to a given kubectl KubectlCmdBuilderMessage message.
func WithAdditionalSelects ¶
func WithAdditionalSelects(in ...*api.Select) MesageOption
WithAdditionalSelects adds additional selects to a given kubectl KubectlCmdBuilderMessage message.
type MessageOptions ¶
type MessageOptions struct {
// contains filtered or unexported fields
}
MessageOptions holds builder message options.
type NamespaceLister ¶
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.