config

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const SensitiveRedactionMarker = "<sensitive>"

SensitiveRedactionMarker is the placeholder shown in place of a sensitive value in display output, so operators see that a field exists and is sensitive without its value being printed.

Variables

View Source
var DefaultConfig = v1alpha1.Context{
	Platform: ptrString("none"),
}

DefaultConfig is the base configuration for non-dev contexts (platform "none").

View Source
var DefaultConfig_Dev = v1alpha1.Context{}

DefaultConfig_Dev provides defaults for all dev contexts (docker-desktop, colima, incus).

Functions

func FormatValidationErrors added in v0.9.0

func FormatValidationErrors(errs []string) string

FormatValidationErrors renders a Validate result's Errors as an indented list, one violation per line, instead of Go's flat space-joined %v slice format, so a multi-error result reads as a scannable list rather than a run-on string.

func RedactSensitiveValues added in v0.9.0

func RedactSensitiveValues(values map[string]any, sensitivePaths []string) map[string]any

RedactSensitiveValues replaces, in place, every existing value at a sensitive path with SensitiveRedactionMarker so display surfaces (e.g. windsor show values) never print secret material while still revealing that the field is set. A "*" path segment matches any single key. Absent paths are left untouched — redaction never fabricates keys. The same map is returned for convenience.

func RenderValuesWithDescriptions added in v0.9.0

func RenderValuesWithDescriptions(values map[string]any, schema map[string]any) string

RenderValuesWithDescriptions renders context values as YAML annotated with schema descriptions. It walks the union of schema properties and effective values so that every configurable field appears in the output. Set keys render as normal YAML with description comments; unset schema-defined keys render as commented-out reference lines. Top-level keys are separated by blank lines. When schema is nil, values are rendered as plain YAML without comments.

Types

type ConfigHandler

type ConfigHandler interface {
	LoadConfig() error
	LoadConfigForContext(contextName string) error
	LoadConfigString(content string) error
	GetString(key string, defaultValue ...string) string
	GetInt(key string, defaultValue ...int) int
	GetBool(key string, defaultValue ...bool) bool
	GetStringSlice(key string, defaultValue ...[]string) []string
	GetStringMap(key string, defaultValue ...map[string]string) map[string]string
	Set(key string, value any) error
	Get(key string) any
	SaveConfig(overwrite ...bool) error
	SaveWorkstationState() error
	SetDefault(context v1alpha1.Context) error
	GetConfig() *v1alpha1.Context
	GetContext() string
	WithContext(name string) ConfigHandler
	IsDevMode(contextName string) bool
	SetContext(context string) error
	GetConfigRoot() (string, error)
	GetWindsorScratchPath() (string, error)
	Clean() error
	IsLoaded() bool
	GenerateContextID() error
	LoadSchema(schemaPath string) error
	LoadSchemaFromBytes(schemaContent []byte) error
	GetSchema() map[string]any
	GetContextValues() (map[string]any, error)
	GetSetValues() map[string]any
	SetApplySchemaDefaults(enabled bool)
	GetSensitivePaths() []string
	IsSensitivePath(path string) bool
	RegisterProvider(prefix string, provider ValueProvider)
	ValidateContextValues() error
}

func NewConfigHandler

func NewConfigHandler(shell shell.Shell) ConfigHandler

NewConfigHandler creates a new ConfigHandler instance with default context configuration.

type MockConfigHandler

type MockConfigHandler struct {
	LoadConfigFunc             func() error
	LoadConfigForContextFunc   func(contextName string) error
	LoadConfigStringFunc       func(content string) error
	IsLoadedFunc               func() bool
	GetStringFunc              func(key string, defaultValue ...string) string
	GetIntFunc                 func(key string, defaultValue ...int) int
	GetBoolFunc                func(key string, defaultValue ...bool) bool
	GetStringSliceFunc         func(key string, defaultValue ...[]string) []string
	GetStringMapFunc           func(key string, defaultValue ...map[string]string) map[string]string
	SetFunc                    func(key string, value any) error
	SaveConfigFunc             func(overwrite ...bool) error
	SaveWorkstationStateFunc   func() error
	GetFunc                    func(key string) any
	SetDefaultFunc             func(context v1alpha1.Context) error
	GetConfigFunc              func() *v1alpha1.Context
	GetContextFunc             func() string
	IsDevModeFunc              func(contextName string) bool
	SetContextFunc             func(context string) error
	GetConfigRootFunc          func() (string, error)
	GetWindsorScratchPathFunc  func() (string, error)
	CleanFunc                  func() error
	GenerateContextIDFunc      func() error
	LoadSchemaFunc             func(schemaPath string) error
	LoadSchemaFromBytesFunc    func(schemaContent []byte) error
	GetSchemaFunc              func() map[string]any
	GetContextValuesFunc       func() (map[string]any, error)
	GetSetValuesFunc           func() map[string]any
	SetApplySchemaDefaultsFunc func(enabled bool)
	GetSensitivePathsFunc      func() []string
	IsSensitivePathFunc        func(path string) bool
	RegisterProviderFunc       func(prefix string, provider ValueProvider)
	ValidateContextValuesFunc  func() error
	// contains filtered or unexported fields
}

MockConfigHandler is a mock implementation of the ConfigHandler interface

func NewMockConfigHandler

func NewMockConfigHandler() *MockConfigHandler

NewMockConfigHandler is a constructor for MockConfigHandler

func (*MockConfigHandler) Clean

func (m *MockConfigHandler) Clean() error

Clean calls the mock CleanFunc if set, otherwise returns nil

func (*MockConfigHandler) GenerateContextID

func (m *MockConfigHandler) GenerateContextID() error

GenerateContextID calls the mock GenerateContextIDFunc if set, otherwise returns nil

func (*MockConfigHandler) Get

func (m *MockConfigHandler) Get(key string) any

Get calls the mock GetFunc if set, otherwise returns a reasonable default value

func (*MockConfigHandler) GetBool

func (m *MockConfigHandler) GetBool(key string, defaultValue ...bool) bool

GetBool calls the mock GetBoolFunc if set, otherwise returns a reasonable default bool

func (*MockConfigHandler) GetConfig

func (m *MockConfigHandler) GetConfig() *v1alpha1.Context

GetConfig calls the mock GetConfigFunc if set, otherwise returns a reasonable default Context

func (*MockConfigHandler) GetConfigRoot

func (m *MockConfigHandler) GetConfigRoot() (string, error)

GetConfigRoot calls the mock GetConfigRootFunc if set, otherwise returns a reasonable default string

func (*MockConfigHandler) GetContext

func (m *MockConfigHandler) GetContext() string

GetContext calls the mock GetContextFunc if set; WithContext override takes priority over both

func (*MockConfigHandler) GetContextValues

func (m *MockConfigHandler) GetContextValues() (map[string]any, error)

GetContextValues calls the mock GetContextValuesFunc if set, otherwise returns an error

func (*MockConfigHandler) GetInt

func (m *MockConfigHandler) GetInt(key string, defaultValue ...int) int

GetInt calls the mock GetIntFunc if set, otherwise returns a reasonable default int

func (*MockConfigHandler) GetSchema added in v0.9.0

func (m *MockConfigHandler) GetSchema() map[string]any

GetSchema calls the mock GetSchemaFunc if set, otherwise returns nil

func (*MockConfigHandler) GetSensitivePaths added in v0.9.0

func (m *MockConfigHandler) GetSensitivePaths() []string

GetSensitivePaths calls the mock GetSensitivePathsFunc if set, otherwise returns nil

func (*MockConfigHandler) GetSetValues added in v0.9.0

func (m *MockConfigHandler) GetSetValues() map[string]any

GetSetValues calls the mock GetSetValuesFunc if set, otherwise returns nil.

func (*MockConfigHandler) GetString

func (m *MockConfigHandler) GetString(key string, defaultValue ...string) string

GetString calls the mock GetStringFunc if set, otherwise returns a reasonable default string

func (*MockConfigHandler) GetStringMap

func (m *MockConfigHandler) GetStringMap(key string, defaultValue ...map[string]string) map[string]string

GetStringMap calls the mock GetStringMapFunc if set, otherwise returns a reasonable default map of strings

func (*MockConfigHandler) GetStringSlice

func (m *MockConfigHandler) GetStringSlice(key string, defaultValue ...[]string) []string

GetStringSlice calls the mock GetStringSliceFunc if set, otherwise returns a reasonable default slice of strings

func (*MockConfigHandler) GetWindsorScratchPath

func (m *MockConfigHandler) GetWindsorScratchPath() (string, error)

GetWindsorScratchPath calls the mock GetWindsorScratchPathFunc if set, otherwise returns a reasonable default string

func (*MockConfigHandler) IsDevMode

func (m *MockConfigHandler) IsDevMode(contextName string) bool

IsDevMode calls the mock IsDevModeFunc if set, otherwise returns default dev mode logic

func (*MockConfigHandler) IsLoaded

func (m *MockConfigHandler) IsLoaded() bool

IsLoaded calls the mock IsLoadedFunc if set, otherwise returns false

func (*MockConfigHandler) IsSensitivePath added in v0.9.0

func (m *MockConfigHandler) IsSensitivePath(path string) bool

IsSensitivePath calls the mock IsSensitivePathFunc if set, otherwise returns false

func (*MockConfigHandler) LoadConfig

func (m *MockConfigHandler) LoadConfig() error

LoadConfig calls the mock LoadConfigFunc if set, otherwise returns nil

func (*MockConfigHandler) LoadConfigForContext added in v0.9.0

func (m *MockConfigHandler) LoadConfigForContext(contextName string) error

LoadConfigForContext calls the mock LoadConfigForContextFunc if set, otherwise returns nil

func (*MockConfigHandler) LoadConfigString

func (m *MockConfigHandler) LoadConfigString(content string) error

LoadConfigString calls the mock LoadConfigStringFunc if set, otherwise returns nil

func (*MockConfigHandler) LoadSchema

func (m *MockConfigHandler) LoadSchema(schemaPath string) error

LoadSchema calls the mock LoadSchemaFunc if set, otherwise returns an error

func (*MockConfigHandler) LoadSchemaFromBytes

func (m *MockConfigHandler) LoadSchemaFromBytes(schemaContent []byte) error

LoadSchemaFromBytes calls the mock LoadSchemaFromBytesFunc if set, otherwise returns an error

func (*MockConfigHandler) RegisterProvider added in v0.9.0

func (m *MockConfigHandler) RegisterProvider(prefix string, provider ValueProvider)

RegisterProvider calls the mock RegisterProviderFunc if set, otherwise does nothing

func (*MockConfigHandler) SaveConfig

func (m *MockConfigHandler) SaveConfig(overwrite ...bool) error

SaveConfig calls the SaveConfigFunc if set, otherwise returns nil

func (*MockConfigHandler) SaveWorkstationState added in v0.9.0

func (m *MockConfigHandler) SaveWorkstationState() error

SaveWorkstationState calls the mock SaveWorkstationStateFunc if set, otherwise returns nil

func (*MockConfigHandler) Set

func (m *MockConfigHandler) Set(key string, value any) error

Set calls the mock SetFunc if set, otherwise returns nil

func (*MockConfigHandler) SetApplySchemaDefaults added in v0.9.0

func (m *MockConfigHandler) SetApplySchemaDefaults(enabled bool)

SetApplySchemaDefaults calls the mock SetApplySchemaDefaultsFunc if set, otherwise is a no-op

func (*MockConfigHandler) SetContext

func (m *MockConfigHandler) SetContext(context string) error

SetContext calls the mock SetContextFunc if set, otherwise returns nil

func (*MockConfigHandler) SetDefault

func (m *MockConfigHandler) SetDefault(context v1alpha1.Context) error

SetDefault calls the mock SetDefaultFunc if set, otherwise does nothing

func (*MockConfigHandler) ValidateContextValues added in v0.9.0

func (m *MockConfigHandler) ValidateContextValues() error

ValidateContextValues calls the mock ValidateContextValuesFunc if set, otherwise returns nil

func (*MockConfigHandler) WithContext added in v0.9.0

func (m *MockConfigHandler) WithContext(name string) ConfigHandler

WithContext returns a new MockConfigHandler with the given context override applied. The original mock is not modified, consistent with the immutable semantics of WithContext.

type SchemaValidationResult

type SchemaValidationResult struct {
	Valid    bool           `json:"valid"`
	Errors   []string       `json:"errors,omitempty"`
	Defaults map[string]any `json:"defaults,omitempty"`
}

SchemaValidationResult carries the outcome of a Validate call. Defaults is populated by Validate for callers that want both validation and defaults in one pass; standalone defaults extraction uses GetSchemaDefaults instead.

type SchemaValidator

type SchemaValidator struct {
	Shims  *Shims
	Schema map[string]any
	// contains filtered or unexported fields
}

SchemaValidator handles Windsor blueprint schema validation.

func NewSchemaValidator

func NewSchemaValidator(shell shell.Shell) *SchemaValidator

NewSchemaValidator creates a new schema validator instance.

func (*SchemaValidator) ErrorsAlreadyReported added in v0.9.0

func (sv *SchemaValidator) ErrorsAlreadyReported(errs []string) bool

ErrorsAlreadyReported reports whether errs is the same set of errors last recorded by MarkErrorsReported, regardless of order.

func (*SchemaValidator) GetSchemaDefaults

func (sv *SchemaValidator) GetSchemaDefaults() (map[string]any, error)

GetSchemaDefaults returns the default values declared in the loaded schema as a single nested map. Callers (accessors.go, resolve.go) merge this under user values to fill in fields the operator omitted. Defaults extraction walks the raw merged schema without touching kaptinlin's compiled form — see extractDefaults for why.

func (*SchemaValidator) GetSensitivePaths added in v0.9.0

func (sv *SchemaValidator) GetSensitivePaths() []string

GetSensitivePaths returns the dotted config paths of every property marked `sensitive: true` in the loaded schema, sorted for stable output. A free-form map region (additionalProperties) contributes a "*" wildcard segment for its dynamic key. Returns nil when no schema is loaded. The result is computed once per loaded schema and cached (invalidated on LoadSchemaFromBytes), so repeated calls — e.g. IsSensitivePath over every key of a config map — do not re-walk the schema. The returned slice is shared; callers must not mutate it.

func (*SchemaValidator) LoadSchema

func (sv *SchemaValidator) LoadSchema(schemaPath string) error

LoadSchema loads a schema fragment from a file on disk and merges it into the current in-memory schema. Subsequent Validate / GetSchemaDefaults calls operate on the union.

func (*SchemaValidator) LoadSchemaFromBytes

func (sv *SchemaValidator) LoadSchemaFromBytes(schemaContent []byte) error

LoadSchemaFromBytes parses a YAML schema fragment and merges it into the current in-memory schema. The first fragment becomes the base; later fragments deep-merge over it with overlay properties winning on conflict (see schema_merge.go). Loading any new fragment invalidates the compiled schema cache; recompilation runs on the next Validate or GetSchemaDefaults call.

func (*SchemaValidator) MarkErrorsReported added in v0.9.0

func (sv *SchemaValidator) MarkErrorsReported(errs []string)

MarkErrorsReported records errs (a Validate result's Errors) as already surfaced to the operator, so a later ErrorsAlreadyReported call for the identical error set — e.g. ValidateContextValues revalidating the same invalid data already warned about by valuesSource.Load earlier in the same invocation — can recognize the duplicate and skip re-printing it.

func (*SchemaValidator) Validate

func (sv *SchemaValidator) Validate(values map[string]any) (*SchemaValidationResult, error)

Validate checks values against the loaded schema and returns the outcome plus extracted defaults. Errors are flattened from kaptinlin's hierarchical EvaluationResult into one deduplicated, prioritized "<instance-path>: <keyword>: <message>" line per leaf — see collectErrors — pass them to FormatValidationErrors for display, or ErrorsAlreadyReported to check whether a caller earlier in this invocation already surfaced the identical set.

type Shims

type Shims struct {
	ReadFile          func(string) ([]byte, error)
	WriteFile         func(string, []byte, os.FileMode) error
	RemoveAll         func(string) error
	Getenv            func(string) string
	Setenv            func(string, string) error
	Stat              func(string) (os.FileInfo, error)
	MkdirAll          func(string, os.FileMode) error
	YamlMarshal       func(any) ([]byte, error)
	YamlUnmarshal     func([]byte, any) error
	CryptoRandRead    func([]byte) (int, error)
	RegexpMatchString func(pattern, s string) (bool, error)
}

Shims provides mockable wrappers around system and runtime functions

func NewShims

func NewShims() *Shims

NewShims creates a new Shims instance with default implementations

type ValueProvider added in v0.9.0

type ValueProvider interface {
	GetValue(key string) (any, error)
}

ValueProvider defines the interface for dynamic value providers that can resolve configuration keys with special prefixes (e.g., terraform.*, cluster.*).

Jump to

Keyboard shortcuts

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