builder

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyResourceNameDropdown

func EmptyResourceNameDropdown() *api.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:

  1. This select is converted to external data source (https://api.slack.com/reference/block-kit/block-elements#external_select)
  2. We change the `min_query_length` to 0 to remove th "Type minimum of 3 characters to see options" message.
  3. Our backend doesn't return any options, so you see "No result".
  4. 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

func FilterSection() api.LabelInput

FilterSection returns filter input block.

func InternalErrorSection

func InternalErrorSection() api.Section

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

func ResourceNamesSelect(names []string, initialItem string) *api.Select

ResourceNamesSelect return drop-down select for kubectl resources names.

func ResourceNamespaceSelect

func ResourceNamespaceSelect(names []dropdownItem, initialNamespace dropdownItem) *api.Select

ResourceNamespaceSelect return drop-down select for kubectl allowed namespaces.

func ResourceTypeSelect

func ResourceTypeSelect(resources []string, initialItem string) *api.Select

ResourceTypeSelect return drop-down select for kubectl resources types.

func ShouldHandle

func ShouldHandle(cmd string) bool

ShouldHandle returns true if it's a valid command for interactive builder.

func VerbSelect

func VerbSelect(verbs []string, initialItem string) *api.Select

VerbSelect return drop-down select for kubectl verbs.

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

type AuthChecker interface {
	ValidateUserAccess(ns, verb, resource, name string) (bool, *api.Section)
}

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

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

K8sAuth provides functionality to check if we have enough permissions to run given kubectl command.

func NewK8sAuth added in v1.9.0

func NewK8sAuth(cli v1.AuthorizationV1Interface) *K8sAuth

NewK8sAuth return a new K8sAuth instance.

func (*K8sAuth) ValidateUserAccess added in v1.9.0

func (c *K8sAuth) ValidateUserAccess(ns, verb, resource, name string) (bool, *api.Section)

ValidateUserAccess validates that a given verbs are allowed. Returns user-facing message if not allowed.

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.

func (*Kubectl) Handle

func (e *Kubectl) Handle(ctx context.Context, cmd string, isInteractivitySupported bool, state *slack.BlockActionStates) (api.Message, error)

Handle constructs the interactive command builder messages.

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.

Jump to

Keyboard shortcuts

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