config

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = v1alpha1.Context{
	Provider: ptrString("local"),
	Cluster: &cluster.ClusterConfig{
		Enabled: ptrBool(true),
	},
	Terraform: &terraform.TerraformConfig{
		Enabled: ptrBool(true),
		Backend: &terraform.BackendConfig{
			Type: "local",
		},
	},
}

DefaultConfig returns the default configuration

View Source
var DefaultConfig_Full = v1alpha1.Context{
	Provider:    ptrString("local"),
	Environment: map[string]string{},
	Docker:      commonDockerConfig.Copy(),
	Git:         commonGitConfig.Copy(),
	Terraform:   commonTerraformConfig.Copy(),
	Cluster:     commonClusterConfig_NoHostPorts.Copy(),
	Network: &network.NetworkConfig{
		CIDRBlock: ptrString(constants.DEFAULT_NETWORK_CIDR),
		LoadBalancerIPs: &struct {
			Start *string `yaml:"start,omitempty"`
			End   *string `yaml:"end,omitempty"`
		}{
			Start: ptrString("10.5.1.1"),
			End:   ptrString("10.5.1.10"),
		},
	},
	DNS: &dns.DNSConfig{
		Enabled: ptrBool(true),
		Domain:  ptrString("test"),
		Forward: []string{
			"10.5.1.1",
		},
	},
}
View Source
var DefaultConfig_Localhost = v1alpha1.Context{
	Provider:    ptrString("local"),
	Environment: map[string]string{},
	Docker:      commonDockerConfig.Copy(),
	Git:         commonGitConfig.Copy(),
	Terraform:   commonTerraformConfig.Copy(),
	Cluster:     commonClusterConfig_WithHostPorts.Copy(),
	Network: &network.NetworkConfig{
		CIDRBlock: ptrString(constants.DEFAULT_NETWORK_CIDR),
	},
	DNS: &dns.DNSConfig{
		Enabled: ptrBool(true),
		Domain:  ptrString("test"),
		Forward: []string{
			"10.5.0.1:8053",
		},
	},
}

Functions

This section is empty.

Types

type BaseConfigHandler

type BaseConfigHandler struct {
	ConfigHandler
	// contains filtered or unexported fields
}

BaseConfigHandler is a base implementation of the ConfigHandler interface

func NewBaseConfigHandler added in v0.3.0

func NewBaseConfigHandler(injector di.Injector) *BaseConfigHandler

NewBaseConfigHandler creates a new BaseConfigHandler instance

func (*BaseConfigHandler) Clean added in v0.3.0

func (c *BaseConfigHandler) Clean() error

Clean cleans up context specific artifacts

func (*BaseConfigHandler) GetConfigRoot added in v0.3.0

func (c *BaseConfigHandler) GetConfigRoot() (string, error)

GetConfigRoot retrieves the configuration root path based on the current context

func (*BaseConfigHandler) GetContext added in v0.3.0

func (c *BaseConfigHandler) GetContext() string

GetContext retrieves the current context from the environment, file, or defaults to "local"

func (*BaseConfigHandler) Initialize added in v0.3.0

func (c *BaseConfigHandler) Initialize() error

Initialize sets up the config handler by resolving and storing the shell dependency.

func (*BaseConfigHandler) IsLoaded added in v0.5.0

func (c *BaseConfigHandler) IsLoaded() bool

IsLoaded checks if the configuration has been loaded

func (*BaseConfigHandler) LoadContextConfig added in v0.7.0

func (c *BaseConfigHandler) LoadContextConfig() error

LoadContextConfig provides a base implementation that should be overridden by concrete implementations

func (*BaseConfigHandler) SetContext added in v0.3.0

func (c *BaseConfigHandler) SetContext(context string) error

SetContext sets the current context in the file and updates the cache

func (*BaseConfigHandler) SetSecretsProvider added in v0.5.0

func (c *BaseConfigHandler) SetSecretsProvider(provider secrets.SecretsProvider)

SetSecretsProvider sets the secrets provider for the config handler

type ConfigHandler

type ConfigHandler interface {
	Initialize() error
	LoadConfig(path string) error
	LoadConfigString(content string) error
	LoadContextConfig() 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
	SetContextValue(key string, value any) error
	Get(key string) any
	SaveConfig(overwrite ...bool) error
	SetDefault(context v1alpha1.Context) error
	GetConfig() *v1alpha1.Context
	GetContext() string
	SetContext(context string) error
	GetConfigRoot() (string, error)
	Clean() error
	IsLoaded() bool
	SetSecretsProvider(provider secrets.SecretsProvider)
	GenerateContextID() error
	YamlMarshalWithDefinedPaths(v any) ([]byte, error)
}

type MockConfigHandler

type MockConfigHandler struct {
	InitializeFunc                  func() error
	LoadConfigFunc                  func(path string) error
	LoadConfigStringFunc            func(content string) error
	LoadContextConfigFunc           func() 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
	SetContextValueFunc             func(key string, value any) error
	SaveConfigFunc                  func(overwrite ...bool) error
	GetFunc                         func(key string) any
	SetDefaultFunc                  func(context v1alpha1.Context) error
	GetConfigFunc                   func() *v1alpha1.Context
	GetContextFunc                  func() string
	SetContextFunc                  func(context string) error
	GetConfigRootFunc               func() (string, error)
	CleanFunc                       func() error
	SetSecretsProviderFunc          func(provider secrets.SecretsProvider)
	GenerateContextIDFunc           func() error
	YamlMarshalWithDefinedPathsFunc func(v any) ([]byte, error)
}

MockConfigHandler is a mock implementation of the ConfigHandler interface

func NewMockConfigHandler

func NewMockConfigHandler() *MockConfigHandler

NewMockConfigHandler is a constructor for MockConfigHandler

func (*MockConfigHandler) Clean added in v0.3.0

func (m *MockConfigHandler) Clean() error

Clean calls the mock CleanFunc if set, otherwise returns nil

func (*MockConfigHandler) GenerateContextID added in v0.5.7

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

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

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

func (*MockConfigHandler) GetContext added in v0.3.0

func (m *MockConfigHandler) GetContext() string

GetContext calls the mock GetContextFunc if set, otherwise returns a reasonable default string

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

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

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) Initialize added in v0.3.0

func (m *MockConfigHandler) Initialize() error

Initialize calls the mock InitializeFunc if set, otherwise returns nil

func (*MockConfigHandler) IsLoaded added in v0.5.0

func (m *MockConfigHandler) IsLoaded() bool

IsLoaded calls the mock IsLoadedFunc if set, otherwise returns false

func (*MockConfigHandler) LoadConfig

func (m *MockConfigHandler) LoadConfig(path string) error

LoadConfig calls the mock LoadConfigFunc if set, otherwise returns nil

func (*MockConfigHandler) LoadConfigString added in v0.5.7

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

LoadConfigString calls the mock LoadConfigStringFunc if set, otherwise returns nil

func (*MockConfigHandler) LoadContextConfig added in v0.7.0

func (m *MockConfigHandler) LoadContextConfig() error

LoadContextConfig calls the mock LoadContextConfigFunc if set, otherwise returns nil

func (*MockConfigHandler) SaveConfig

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

SaveConfig calls the SaveConfigFunc 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) SetContext added in v0.3.0

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

SetContext calls the mock SetContextFunc if set, otherwise returns nil

func (*MockConfigHandler) SetContextValue

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

SetContextValue calls the mock SetContextValueFunc 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) SetSecretsProvider added in v0.5.0

func (m *MockConfigHandler) SetSecretsProvider(provider secrets.SecretsProvider)

SetSecretsProvider calls the mock SetSecretsProviderFunc if set, otherwise does nothing

func (*MockConfigHandler) YamlMarshalWithDefinedPaths added in v0.7.0

func (m *MockConfigHandler) YamlMarshalWithDefinedPaths(v any) ([]byte, error)

YamlMarshalWithDefinedPaths calls the mock YamlMarshalWithDefinedPathsFunc if set, otherwise returns a reasonable default

type Shims added in v0.5.7

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)
}

Shims provides mockable wrappers around system and runtime functions

func NewShims added in v0.5.7

func NewShims() *Shims

NewShims creates a new Shims instance with default implementations

type YamlConfigHandler

type YamlConfigHandler struct {
	BaseConfigHandler
	// contains filtered or unexported fields
}

func NewYamlConfigHandler

func NewYamlConfigHandler(injector di.Injector) *YamlConfigHandler

NewYamlConfigHandler creates a new instance of YamlConfigHandler with default context configuration.

func (*YamlConfigHandler) GenerateContextID added in v0.5.7

func (y *YamlConfigHandler) GenerateContextID() error

GenerateContextID generates a random context ID if one doesn't exist

func (*YamlConfigHandler) Get

func (y *YamlConfigHandler) Get(path string) any

Get returns the value at the given configuration path, checking current and default context if needed.

func (*YamlConfigHandler) GetBool

func (y *YamlConfigHandler) GetBool(key string, defaultValue ...bool) bool

GetBool retrieves a boolean value for the specified key from the configuration, with an optional default value.

func (*YamlConfigHandler) GetConfig

func (y *YamlConfigHandler) GetConfig() *v1alpha1.Context

GetConfig returns the context config object for the current context, or the default if none is set.

func (*YamlConfigHandler) GetInt

func (y *YamlConfigHandler) GetInt(key string, defaultValue ...int) int

GetInt retrieves an integer value for the specified key from the configuration, with an optional default value.

func (*YamlConfigHandler) GetString

func (y *YamlConfigHandler) GetString(key string, defaultValue ...string) string

GetString retrieves a string value for the specified key from the configuration, with an optional default value. If the key is not found, it returns the provided default value or an empty string if no default is provided.

func (*YamlConfigHandler) GetStringMap added in v0.5.0

func (y *YamlConfigHandler) GetStringMap(key string, defaultValue ...map[string]string) map[string]string

GetStringMap retrieves a map of string key-value pairs for the specified key from the configuration. If the key is not found, it returns the provided default value or an empty map if no default is provided.

func (*YamlConfigHandler) GetStringSlice added in v0.4.0

func (y *YamlConfigHandler) GetStringSlice(key string, defaultValue ...[]string) []string

GetStringSlice retrieves a slice of strings for the specified key from the configuration, with an optional default value. If the key is not found, it returns the provided default value or an empty slice if no default is provided.

func (*YamlConfigHandler) LoadConfig

func (y *YamlConfigHandler) LoadConfig(path string) error

LoadConfig loads the configuration from the specified path. If the file does not exist, it does nothing.

func (*YamlConfigHandler) LoadConfigString added in v0.5.7

func (y *YamlConfigHandler) LoadConfigString(content string) error

LoadConfigString loads configuration from a YAML string into the internal config structure. It unmarshals the YAML, records which contexts were present in the input, validates and sets the config version, and marks the configuration as loaded. Returns an error if unmarshalling fails or if the config version is unsupported.

func (*YamlConfigHandler) LoadContextConfig added in v0.7.0

func (y *YamlConfigHandler) LoadContextConfig() error

LoadContextConfig loads context-specific windsor.yaml configuration and merges it with the existing configuration. It looks for windsor.yaml files in the current context's directory (contexts/<context>/windsor.yaml). The context-specific configuration is expected to contain only the context configuration values without the top-level "contexts" key. These values are merged into the current context configuration.

func (*YamlConfigHandler) SaveConfig

func (y *YamlConfigHandler) SaveConfig(overwrite ...bool) error

SaveConfig writes configuration to root windsor.yaml and the current context's windsor.yaml. Root windsor.yaml contains only the version field. The context file contains the context config without the contexts wrapper. Files are created only if absent: root windsor.yaml is created if missing; context windsor.yaml is created if missing and context is not in root config. Existing files are never overwritten.

func (*YamlConfigHandler) Set

func (y *YamlConfigHandler) Set(path string, value any) error

Set updates the value at the specified path in the configuration using reflection.

func (*YamlConfigHandler) SetContextValue

func (y *YamlConfigHandler) SetContextValue(path string, value any) error

SetContextValue sets a configuration value within the current context.

func (*YamlConfigHandler) SetDefault

func (y *YamlConfigHandler) SetDefault(context v1alpha1.Context) error

SetDefault sets the given context configuration as the default and merges it with any existing context configuration. If no context exists, the default becomes the context. If a context exists, it merges the default with the existing context, with existing values taking precedence over defaults.

func (*YamlConfigHandler) YamlMarshalWithDefinedPaths added in v0.7.0

func (y *YamlConfigHandler) YamlMarshalWithDefinedPaths(v any) ([]byte, error)

YamlMarshalWithDefinedPaths marshals data to YAML format while ensuring all parent paths are defined. It handles struct fields, slices, maps, and primitive types with proper YAML tag handling and nil value representation. This method ensures that empty slices and maps are explicitly defined as empty rather than being omitted, which is important for configuration templates that need to show structure even when empty.

Jump to

Keyboard shortcuts

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