command

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrVerbNotSupported is returned when the verb is not supported for the resource.
	ErrVerbNotSupported = errors.New("verb not supported")

	// ErrResourceNotFound is returned when the resource is not found on the server.
	ErrResourceNotFound = errors.New("resource not found")
)

Functions

This section is empty.

Types

type CommandGuard

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

CommandGuard is responsible for getting allowed resources for a given command.

func NewCommandGuard

func NewCommandGuard(log logrus.FieldLogger, discoveryCli K8sDiscoveryInterface) *CommandGuard

NewCommandGuard creates a new CommandGuard instance.

func (*CommandGuard) FilterSupportedVerbs

func (g *CommandGuard) FilterSupportedVerbs(allVerbs []string) []string

FilterSupportedVerbs filters out unsupported verbs by the interactive commands.

func (*CommandGuard) GetAllowedResourcesForVerb

func (g *CommandGuard) GetAllowedResourcesForVerb(verb string, allConfiguredResources []string) ([]Resource, error)

GetAllowedResourcesForVerb returns a list of allowed resources for a given verb.

func (*CommandGuard) GetResourceDetails

func (g *CommandGuard) GetResourceDetails(selectedVerb, resourceType string) (Resource, error)

GetResourceDetails returns a Resource struct for a given resource type and verb.

func (*CommandGuard) GetResourceDetailsFromMap

func (g *CommandGuard) GetResourceDetailsFromMap(selectedVerb, resourceType string, resMap map[string]v1.APIResource) (Resource, error)

GetResourceDetailsFromMap returns a Resource struct for a given resource type and verb based on the server resource map.

func (*CommandGuard) GetServerResourceMap

func (g *CommandGuard) GetServerResourceMap() (map[string]v1.APIResource, error)

GetServerResourceMap returns a map of all resources available on the server. LIMITATION: This method ignores second occurrences of the same resource name.

type K8sDiscoveryInterface

type K8sDiscoveryInterface interface {
	ServerPreferredResources() ([]*v1.APIResourceList, error)
}

K8sDiscoveryInterface describes an interface for getting K8s server resources.

type Resource

type Resource struct {
	// Name is always plural, e.g. "pods".
	Name       string
	Namespaced bool

	// SlashSeparatedInCommand indicates if the resource name should be separated with a slash in the command.
	// So, instead of `kubectl logs pods <name>` it should be `kubectl logs pods/<name>`.
	SlashSeparatedInCommand bool
}

Resource represents a Kubernetes resource.

Jump to

Keyboard shortcuts

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