ctx

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns the configuration directory.

func Configure

func Configure(next Options)

Configure sets package-level context storage defaults for a consumer CLI.

func SetConfigPath

func SetConfigPath(path string)

SetConfigPath overrides the default config path for this process.

Types

type Base

type Base struct {
	Server                string            `yaml:"server"`
	Username              string            `yaml:"username,omitempty"`
	Password              string            `yaml:"password,omitempty"`
	Env                   string            `yaml:"env,omitempty"`
	Protected             bool              `yaml:"protected,omitempty"`
	TicketPattern         string            `yaml:"ticketPattern,omitempty"`
	TicketValidator       string            `yaml:"ticketValidator,omitempty"`
	CredentialBackend     string            `yaml:"credentialBackend,omitempty"`
	Roles                 map[string]string `yaml:"roles,omitempty"`
	RolesSource           string            `yaml:"rolesSource,omitempty"`
	RolesURL              string            `yaml:"rolesURL,omitempty"`
	AllowInsecureRolesURL bool              `yaml:"allowInsecureRolesURL,omitempty"`
	OTLPEndpoint          string            `yaml:"otlpEndpoint,omitempty"`
	OTLPEndpointSource    string            `yaml:"otlpEndpointSource,omitempty"`
	OTLPMetricsEndpoint   string            `yaml:"otlpMetricsEndpoint,omitempty"`
	OTLPMetricsSource     string            `yaml:"otlpMetricsSource,omitempty"`
	OTLPInsecure          bool              `yaml:"otlpInsecure,omitempty"`
	OTLPRedact            bool              `yaml:"otlpRedact"`
	OTLPRedactApp         string            `yaml:"otlpRedactApp,omitempty"`
	AuditMaxSize          int64             `yaml:"auditMaxSize,omitempty"`
	AuditEncryptKey       string            `yaml:"auditEncryptKey,omitempty"`
	BackupKeep            int               `yaml:"backupKeep"`
	VaultAddr             string            `yaml:"vaultAddr,omitempty"`
	VaultPath             string            `yaml:"vaultPath,omitempty"`
	VaultRoleID           string            `yaml:"vaultRoleID,omitempty"`
	VaultNamespace        string            `yaml:"vaultNamespace,omitempty"`
}

Base contains common context fields shared by governed CLI tools.

func (Base) ResolvePasswordContext

func (b Base) ResolvePasswordContext(ctx context.Context, contextName string) (string, error)

ResolvePasswordContext resolves literal or credstore referenced passwords.

type BaseAccessor

type BaseAccessor[T any] func(*T) *Base

type Config

type Config[T any] struct {
	APIVersion     string       `yaml:"apiVersion"`
	CurrentContext string       `yaml:"current-context"`
	Contexts       map[string]T `yaml:"contexts"`
}

Config is the top-level context file structure.

type Options

type Options struct {
	APIVersion    string
	ConfigDirName string
}

Options configures package-level context storage defaults.

type Store

type Store[T any] struct {
	// contains filtered or unexported fields
}

Store provides typed context persistence for a CLI-specific context type.

func NewStore

func NewStore[T any](base BaseAccessor[T]) Store[T]

NewStore creates a typed context store.

func NewStoreWithoutBase

func NewStoreWithoutBase[T any]() Store[T]

NewStoreWithoutBase creates a typed context store for schemas that do not embed Base.

func (Store[T]) Current

func (s Store[T]) Current() (*T, string, error)

Current returns the active context.

func (Store[T]) DeleteContext

func (s Store[T]) DeleteContext(name string) error

DeleteContext removes a context.

func (Store[T]) Load

func (s Store[T]) Load() (*Config[T], error)

Load reads the context config file. Missing file returns an empty config.

func (Store[T]) Save

func (s Store[T]) Save(cfg *Config[T]) error

Save writes the full config under a file lock.

func (Store[T]) SetContext

func (s Store[T]) SetContext(name string, ctx T) error

SetContext adds or updates a context.

func (Store[T]) Update

func (s Store[T]) Update(fn func(cfg *Config[T]) error) error

Update performs a locked read-modify-write cycle.

func (Store[T]) UseContext

func (s Store[T]) UseContext(name string) error

UseContext switches the current context.

Jump to

Keyboard shortcuts

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