config

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MPL-2.0 Imports: 25 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const AllRegistriesKey = "*"

AllRegistriesKey is the registries key for each registry host with no entry.

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 = cliconfig.Context{
	Platform: "none",
}

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

View Source
var DefaultConfig_Dev = cliconfig.Context{}

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

Functions

func DefaultTerraformBackendTypeForPlatform added in v0.9.1

func DefaultTerraformBackendTypeForPlatform(platform string) string

DefaultTerraformBackendTypeForPlatform returns the canonical terraform state backend for a platform, or "" when the platform has no default backend (the caller falls back to "local"). Kept in sync with the platform description in configuration.yaml.

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 MarshalValues added in v0.10.0

func MarshalValues(values map[string]any) ([]byte, error)

MarshalValues encodes context values as YAML with the keys in header order at every level. The other keys follow the header keys in alphabetical order.

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. Keys come in header order. When schema is nil, values are rendered as plain YAML without comments.

func SensitiveValues added in v0.10.0

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

SensitiveValues returns the scalar values that values holds at each sensitive path, as strings. A "*" path segment matches any single key. A map or list at a sensitive path gives each scalar inside it. Absent paths and nil values give nothing.

Types

type ConfigHandler

type ConfigHandler interface {
	LoadConfig() error
	LoadConfigForContext(contextName string) error
	LoadConfigString(content string) error
	GetString(key string, defaultValue ...string) string
	GetTerraformBackendType() 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 cliconfig.Context) error
	GetHeader() *cliconfig.Context
	GetContext() string
	WithContext(name string) ConfigHandler
	IsDevMode(contextName string) bool
	SetContext(context string) error
	GetConfigRoot() (string, error)
	GetWindsorScratchPath() (string, error)
	GetBasePath() (string, error)
	Clean() error
	IsLoaded() bool
	GenerateContextID() error
	IsNewContext() (bool, error)
	LoadSchema(schemaPath string) error
	LoadSchemaFromBytes(schemaContent []byte) error
	GetSchema() map[string]any
	GetContextValues() (map[string]any, error)
	GetSetValues() map[string]any
	CheckRegistriesKeys() (bool, error)
	SetApplySchemaDefaults(enabled bool)
	GetSensitivePaths() []string
	IsSensitivePath(path string) bool
	ValidateContextValues() error
}

ConfigHandler loads, saves, and reads the configuration of the current context.

func NewConfigHandler

func NewConfigHandler(shell shell.Shell) ConfigHandler

NewConfigHandler creates a new ConfigHandler instance with default context configuration.

type Mirror added in v0.10.0

type Mirror struct {
	Location string
	Insecure bool
}

Mirror is the mirror of one upstream registry host. Location is the host, the optional port, and the optional path of the endpoint, with no scheme. Insecure is true when the endpoint uses http.

type Mirrors added in v0.10.0

type Mirrors map[string]Mirror

Mirrors holds the mirror of each upstream registry host, keyed by host or by AllRegistriesKey. An entry with an empty Location turns off the mirror for its host.

func NewMirrors added in v0.10.0

func NewMirrors(registries map[string]cliconfig.Registry) (Mirrors, error)

NewMirrors returns the mirror of each upstream host in registries. The upstream host is the host of the entry's local value, or its key. An entry with no endpoint gives its host an empty mirror, so the key * does not apply to that host. It returns an error when two entries give different mirrors to one upstream host.

func (Mirrors) For added in v0.10.0

func (m Mirrors) For(host string) (Mirror, bool)

For returns the mirror of host. A host with no entry uses the entry of the key *. It returns false when host has no mirror, or when the mirror is on host itself.

func (Mirrors) OCIURL added in v0.10.0

func (m Mirrors) OCIURL(url string) (string, bool)

OCIURL returns the oci:// URL of the mirror of url, and true when the mirror uses http. The mirror URL keeps the path and the tag of url after the mirror location. It returns url unchanged when url is not an oci:// URL or its host has no mirror.

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
	GetTerraformBackendTypeFunc func() 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 cliconfig.Context) error
	GetHeaderFunc               func() *cliconfig.Context
	GetContextFunc              func() string
	IsDevModeFunc               func(contextName string) bool
	SetContextFunc              func(context string) error
	GetConfigRootFunc           func() (string, error)
	GetWindsorScratchPathFunc   func() (string, error)
	GetBasePathFunc             func() (string, error)
	CleanFunc                   func() error
	GenerateContextIDFunc       func() error
	IsNewContextFunc            func() (bool, 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
	CheckRegistriesKeysFunc     func() (bool, error)
	SetApplySchemaDefaultsFunc  func(enabled bool)
	GetSensitivePathsFunc       func() []string
	IsSensitivePathFunc         func(path string) bool
	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) CheckRegistriesKeys added in v0.10.0

func (m *MockConfigHandler) CheckRegistriesKeys() (bool, error)

CheckRegistriesKeys calls the mock CheckRegistriesKeysFunc if set, otherwise returns false and no error.

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) GetBasePath added in v0.10.0

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

GetBasePath calls the mock GetBasePathFunc if set, otherwise returns an empty path

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) 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) GetHeader added in v0.10.0

func (m *MockConfigHandler) GetHeader() *cliconfig.Context

GetHeader calls the mock GetHeaderFunc if set, otherwise returns an empty header

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) GetTerraformBackendType added in v0.9.1

func (m *MockConfigHandler) GetTerraformBackendType() string

GetTerraformBackendType calls the mock GetTerraformBackendTypeFunc if set, otherwise falls back to GetString("terraform.backend.type", "local") so a test that only stubs GetStringFunc keeps working without also stubbing this method.

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) IsNewContext added in v0.10.0

func (m *MockConfigHandler) IsNewContext() (bool, error)

IsNewContext calls the mock IsNewContextFunc 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) 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 cliconfig.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 {
	shims.Shims
	YamlUnmarshalStrict func(data []byte, v any) error
	EvalSymlinks        func(path string) (string, error)
	CryptoRandRead      func([]byte) (int, error)
}

Shims holds the shared system call primitives, the strict YAML decoder, and the random byte source.

func NewShims

func NewShims() *Shims

NewShims returns a Shims with every field set to its standard library implementation.

Jump to

Keyboard shortcuts

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