Documentation
¶
Index ¶
- Variables
- type BaseConfigHandler
- func (c *BaseConfigHandler) Clean() error
- func (c *BaseConfigHandler) GetConfigRoot() (string, error)
- func (c *BaseConfigHandler) GetContext() string
- func (c *BaseConfigHandler) Initialize() error
- func (c *BaseConfigHandler) IsLoaded() bool
- func (c *BaseConfigHandler) SetContext(context string) error
- func (c *BaseConfigHandler) SetSecretsProvider(provider secrets.SecretsProvider)
- type ConfigHandler
- type MockConfigHandler
- func (m *MockConfigHandler) Clean() error
- func (m *MockConfigHandler) Get(key string) any
- func (m *MockConfigHandler) GetBool(key string, defaultValue ...bool) bool
- func (m *MockConfigHandler) GetConfig() *v1alpha1.Context
- func (m *MockConfigHandler) GetConfigRoot() (string, error)
- func (m *MockConfigHandler) GetContext() string
- func (m *MockConfigHandler) GetInt(key string, defaultValue ...int) int
- func (m *MockConfigHandler) GetString(key string, defaultValue ...string) string
- func (m *MockConfigHandler) GetStringMap(key string, defaultValue ...map[string]string) map[string]string
- func (m *MockConfigHandler) GetStringSlice(key string, defaultValue ...[]string) []string
- func (m *MockConfigHandler) Initialize() error
- func (m *MockConfigHandler) IsLoaded() bool
- func (m *MockConfigHandler) LoadConfig(path string) error
- func (m *MockConfigHandler) LoadConfigString(content string) error
- func (m *MockConfigHandler) SaveConfig(path string) error
- func (m *MockConfigHandler) Set(key string, value any) error
- func (m *MockConfigHandler) SetContext(context string) error
- func (m *MockConfigHandler) SetContextValue(key string, value any) error
- func (m *MockConfigHandler) SetDefault(context v1alpha1.Context) error
- func (m *MockConfigHandler) SetSecretsProvider(provider secrets.SecretsProvider)
- type Shims
- type YamlConfigHandler
- func (y *YamlConfigHandler) Get(path string) any
- func (y *YamlConfigHandler) GetBool(key string, defaultValue ...bool) bool
- func (y *YamlConfigHandler) GetConfig() *v1alpha1.Context
- func (y *YamlConfigHandler) GetInt(key string, defaultValue ...int) int
- func (y *YamlConfigHandler) GetString(key string, defaultValue ...string) string
- func (y *YamlConfigHandler) GetStringMap(key string, defaultValue ...map[string]string) map[string]string
- func (y *YamlConfigHandler) GetStringSlice(key string, defaultValue ...[]string) []string
- func (y *YamlConfigHandler) LoadConfig(path string) error
- func (y *YamlConfigHandler) LoadConfigString(content string) error
- func (y *YamlConfigHandler) SaveConfig(path string) error
- func (y *YamlConfigHandler) Set(path string, value any) error
- func (y *YamlConfigHandler) SetContextValue(path string, value any) error
- func (y *YamlConfigHandler) SetDefault(context v1alpha1.Context) error
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = v1alpha1.Context{ Terraform: &terraform.TerraformConfig{ Enabled: ptrBool(true), Backend: &terraform.BackendConfig{ Type: "local", }, }, }
DefaultConfig returns the default configuration
var DefaultConfig_Full = v1alpha1.Context{ Blueprint: ptrString("full"), Environment: map[string]string{}, Docker: commonDockerConfig.Copy(), Git: commonGitConfig.Copy(), Terraform: commonTerraformConfig.Copy(), Cluster: commonClusterConfig.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", }, }, }
var DefaultConfig_Localhost = v1alpha1.Context{ Blueprint: ptrString("full"), Environment: map[string]string{}, Docker: commonDockerConfig.Copy(), Git: commonGitConfig.Copy(), Terraform: commonTerraformConfig.Copy(), Cluster: &cluster.ClusterConfig{ Enabled: ptrBool(true), Platform: ptrString("local"), Driver: ptrString("talos"), ControlPlanes: cluster.NodeGroupConfig{ Count: ptrInt(1), CPU: ptrInt(constants.DEFAULT_TALOS_CONTROL_PLANE_CPU), Memory: ptrInt(constants.DEFAULT_TALOS_CONTROL_PLANE_RAM), Nodes: make(map[string]cluster.NodeConfig), }, Workers: cluster.NodeGroupConfig{ Count: ptrInt(1), CPU: ptrInt(constants.DEFAULT_TALOS_WORKER_CPU), Memory: ptrInt(constants.DEFAULT_TALOS_WORKER_RAM), Nodes: make(map[string]cluster.NodeConfig), HostPorts: []string{"8080:30080/tcp", "8443:30443/tcp", "9292:30292/tcp", "8053:30053/udp"}, Volumes: []string{"${WINDSOR_PROJECT_ROOT}/.volumes:/var/local"}, }, }, 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) 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
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(path string) 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)
}
type MockConfigHandler ¶
type MockConfigHandler struct {
InitializeFunc func() error
LoadConfigFunc func(path 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
SetContextValueFunc func(key string, value any) error
SaveConfigFunc func(path string) 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)
}
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) 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) SaveConfig ¶
func (m *MockConfigHandler) SaveConfig(path string) error
SaveConfig calls the mock 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
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
}
Shims provides mockable wrappers around system and runtime functions
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) Get ¶
func (y *YamlConfigHandler) Get(path string) any
Get retrieves the value at the specified path in the configuration. It checks both the current and default context configurations.
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 the configuration from the provided string content.
func (*YamlConfigHandler) SaveConfig ¶
func (y *YamlConfigHandler) SaveConfig(path string) error
SaveConfig saves the current configuration to the specified path. If the path is empty, it uses the previously loaded path. If the file does not exist, it creates an empty one.
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.