config

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ENV_KW_CONFIG_REPO is the name of the environment variable which contains the path to the kubeswitcher config repo
	ENV_KW_CONFIG_REPO = "KW_CONFIG_REPO"
	// KW_CONFIG_REPO_DEFAULT_NAME is the default name of the folder containing the kubeswitcher config files
	KW_CONFIG_REPO_DEFAULT_NAME = ".kubeswitcher_config"
	// ENV_KW_SESSION_ID is the name of the environment variable which contains the kubeswitcher-specific session id
	ENV_KW_SESSION_ID = "KW_SESSION_ID"
	// ENV_DEFAULT_SESSION_ID is the name of the environment variable which is used if the env var from ENV_KW_SESSION_ID is not set
	ENV_DEFAULT_SESSION_ID = "TERM_SESSION_ID"
)
View Source
const (
	KubeconfigFileName                = "kubeconfig"
	GenericStateFileName              = "state.json"
	PluginStateFileName               = "plugin_state.json"
	NotificationMessageFileName       = "message"
	NotificationMessageBackupFileName = "message.bak"
	IdFileName                        = "id"
	InternalCallFileName              = "internal_call"
	InternalCallbackFilePrefix        = "icb_"
	InternalCallbackRequestSuffix     = "_request"
	InternalCallbackStateSuffix       = "_state"
)
View Source
const ConfigFileName = "config.yaml"

Variables

View Source
var (
	BuiltinSubcommands sets.Set[string]  // set of built-in subcommand names
	BuiltinAliases     map[string]string // map of built-in subcommand aliases as keys, mapped to the subcommands they belong to
)
View Source
var (
	SIDRegex  = regexp.MustCompile(`^[\w-]{1,128}$`)
	UUIDRegex = regexp.MustCompile(`([a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12})`)
)

Functions

This section is empty.

Types

type BuiltinConfig

type BuiltinConfig struct {
	Custom *BuiltinCustomConfig `json:"custom,omitempty"`
}

func (*BuiltinConfig) GetBuiltinCustomConfig

func (c *BuiltinConfig) GetBuiltinCustomConfig() *BuiltinCustomConfig

GetBuiltinCustomConfig is a getter method that will not panic on a nil receiver.

type BuiltinCustomConfig

type BuiltinCustomConfig struct {
	// MaxIdLength is the maximum length of the id that is generated by the 'custom' subcommand.
	// Usually, the id is 'custom:' followed by the path to the kubeconfig.
	// Since this can get somewhat long and the id is meant to be displayed in the shell prompt, it can be shortened.
	// This value affects only the path part of the id, not the prefix, and it cuts off the beginning of the path.
	// Example: The path '/foo/bar/baz' could lead to the id 'custom:…ar/baz' if the max length is set to 6.
	// The total length of the id will be maxIdLength + 8.
	// If set to 0 or a negative value, the id will not be shortened.
	MaxIdLength int `json:"maxIdLength,omitempty"`
}

type Config

type Config struct {
	Kubeswitcher *KubeswitcherConfig `json:"kubeswitcher"`
	Builtin      *BuiltinConfig      `json:"builtin,omitempty"`
	Plugins      PluginConfigList    `json:"plugins,omitempty"`
}

func LoadConfig

func LoadConfig() (*Config, error)

func (*Config) Default

func (c *Config) Default() error

func (*Config) String

func (c *Config) String() string

func (*Config) Validate

func (c *Config) Validate() error

type KubeswitcherConfig

type KubeswitcherConfig struct {
	// KubectlBinary is the path to the kubectl binary to use.
	// If not set, "kubectl" is used and is expected to be resolvable via $PATH.
	KubectlBinary string `json:"kubectlBinary,omitempty"`
	// PrintInfoOnKubeconfigChange controls whether a message is printed if the kubeconfig changed.
	PrintInfoOnKubeconfigChange bool `json:"printInfoOnKubeconfigChange"`
	// PrintChangeInfoToStderr controls whether the info message is printed to stderr or stdout.
	PrintChangeInfoToStderr bool `json:"printChangeInfoToStderr"`
	// HistoryDepth controls how many entries are stored in the history.
	// If set to 0, the history is disabled.
	HistoryDepth int `json:"historyDepth"`
}

type KubeswitcherRuntime

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

KubeswitcherRuntime holds the internal state during commands. Basically, it stores values like the session ID and directory, which have to be computed once per command call and are then reused.

var (
	Runtime *KubeswitcherRuntime
)

func (*KubeswitcherRuntime) Config

func (kr *KubeswitcherRuntime) Config() *Config

Config returns the kubeswitcher config

func (*KubeswitcherRuntime) ConfigDirectory

func (kr *KubeswitcherRuntime) ConfigDirectory() string

ConfigDirectory returns the path to the kubeswitcher config directory

func (*KubeswitcherRuntime) Context

func (kr *KubeswitcherRuntime) Context() *libcontext.Context

Context returns the context. Creates a new context with an empty plugin name if no context has been created yet.

func (*KubeswitcherRuntime) GenericStatePath

func (kr *KubeswitcherRuntime) GenericStatePath() string

GenericStatePath returns the path to the state file

func (*KubeswitcherRuntime) IdPath

func (kr *KubeswitcherRuntime) IdPath() string

IdPath returns the path to the file containing the id

func (*KubeswitcherRuntime) InternalCallPath

func (kr *KubeswitcherRuntime) InternalCallPath() string

InternalCallPath returns the path to the file containing the internal call

func (*KubeswitcherRuntime) InternalCallbackRequestPath added in v1.1.0

func (kr *KubeswitcherRuntime) InternalCallbackRequestPath(callbackID string) string

InternalCallbackRequestPath returns the path where a request for an internal callback with the given ID can be placed

func (*KubeswitcherRuntime) InternalCallbackStatePath added in v1.1.0

func (kr *KubeswitcherRuntime) InternalCallbackStatePath(callbackID string) string

InternalCallbackStatePath returns the path where the state for an internal callback with the given ID can be read from

func (*KubeswitcherRuntime) KubeconfigPath

func (kr *KubeswitcherRuntime) KubeconfigPath() string

KubeconfigPath returns the path to the kubeconfig file

func (*KubeswitcherRuntime) NotificationMessageBackupPath

func (kr *KubeswitcherRuntime) NotificationMessageBackupPath() string

NotificationMessageBackupPath returns the path to the backup file containing the notification message

func (*KubeswitcherRuntime) NotificationMessagePath

func (kr *KubeswitcherRuntime) NotificationMessagePath() string

NotificationMessagePath returns the path to the file containing the notification message

func (*KubeswitcherRuntime) PluginStatePath

func (kr *KubeswitcherRuntime) PluginStatePath() string

PluginStatePath returns the path to the plugin state file

func (*KubeswitcherRuntime) SessionDir

func (kr *KubeswitcherRuntime) SessionDir() string

SessionDir returns the current session directory

func (*KubeswitcherRuntime) SessionID

func (kr *KubeswitcherRuntime) SessionID() string

SessionID() returns the current session ID

func (*KubeswitcherRuntime) State

func (kr *KubeswitcherRuntime) State() *state.State

State returns the state

type PluginConfig

type PluginConfig struct {
	// Name of the plugin and also the subcommand.
	Name string `json:"name"`
	// Aliases for the subcommand.
	// Optional.
	Aliases []string `json:"aliases,omitempty"`
	// Binary is the path to the binary for the plugin.
	// Must be either an absolute path or resolvable via $PATH.
	Binary string `json:"binary"`
	// Short description of the plugin to display on 'kw --help'.
	Short string `json:"short"`
	// Config contains plugin-specific configuration.
	// Optional.
	Config json.RawMessage `json:"config,omitempty"`
	// Env contains environment variables to set before running the plugin.
	// Optional.
	Env map[string]string `json:"env,omitempty"`
}

type PluginConfigList

type PluginConfigList []*PluginConfig

Jump to

Keyboard shortcuts

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