Documentation ¶
Index ¶
- Variables
- type BaseConfigHandler
- type Config
- type ConfigHandler
- type Context
- type MockConfigHandler
- func (m *MockConfigHandler) Get(key string) interface{}
- func (m *MockConfigHandler) GetBool(key string, defaultValue ...bool) bool
- func (m *MockConfigHandler) GetConfig() *Context
- func (m *MockConfigHandler) GetInt(key string, defaultValue ...int) int
- func (m *MockConfigHandler) GetString(key string, defaultValue ...string) string
- func (m *MockConfigHandler) LoadConfig(path string) error
- func (m *MockConfigHandler) SaveConfig(path string) error
- func (m *MockConfigHandler) Set(key string, value interface{}) error
- func (m *MockConfigHandler) SetContextValue(key string, value interface{}) error
- func (m *MockConfigHandler) SetDefault(context Context) error
- type YamlConfigHandler
- func (y *YamlConfigHandler) Get(path string) interface{}
- func (y *YamlConfigHandler) GetBool(key string, defaultValue ...bool) bool
- func (y *YamlConfigHandler) GetConfig() *Context
- func (y *YamlConfigHandler) GetInt(key string, defaultValue ...int) int
- func (y *YamlConfigHandler) GetString(key string, defaultValue ...string) string
- func (y *YamlConfigHandler) LoadConfig(path string) error
- func (y *YamlConfigHandler) SaveConfig(path string) error
- func (y *YamlConfigHandler) Set(path string, value interface{}) error
- func (y *YamlConfigHandler) SetContextValue(path string, value interface{}) error
- func (y *YamlConfigHandler) SetDefault(context Context) error
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Context{ Environment: map[string]string{}, AWS: &aws.AWSConfig{ Enabled: nil, AWSEndpointURL: nil, AWSProfile: nil, S3Hostname: nil, MWAAEndpoint: nil, Localstack: &aws.LocalstackConfig{ Enabled: nil, Services: nil, }, }, Docker: &docker.DockerConfig{ Enabled: nil, Registries: map[string]docker.RegistryConfig{}, NetworkCIDR: nil, }, Terraform: &terraform.TerraformConfig{ Backend: nil, }, Cluster: nil, DNS: &dns.DNSConfig{ Enabled: nil, Name: nil, Address: nil, }, }
DefaultConfig returns the default configuration
var DefaultLocalConfig = Context{ Environment: map[string]string{}, Docker: &docker.DockerConfig{ Enabled: ptrBool(true), Registries: map[string]docker.RegistryConfig{ "registry": {}, "registry-1.docker": { Remote: "https://registry-1.docker.io", Local: "https://docker.io", }, "registry.k8s": { Remote: "https://registry.k8s.io", }, "gcr": { Remote: "https://gcr.io", }, "ghcr": { Remote: "https://ghcr.io", }, "quay": { Remote: "https://quay.io", }, }, NetworkCIDR: ptrString("10.5.0.0/16"), }, Git: &git.GitConfig{ Livereload: &git.GitLivereloadConfig{ Enabled: ptrBool(true), RsyncExclude: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_EXCLUDE), RsyncProtect: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_PROTECT), Username: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_USERNAME), Password: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_PASSWORD), WebhookUrl: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_WEBHOOK_URL), Image: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_IMAGE), VerifySsl: ptrBool(false), }, }, Terraform: &terraform.TerraformConfig{ Backend: ptrString("local"), }, Cluster: &cluster.ClusterConfig{ Enabled: ptrBool(true), Driver: ptrString("talos"), ControlPlanes: struct { Count *int `yaml:"count,omitempty"` CPU *int `yaml:"cpu,omitempty"` Memory *int `yaml:"memory,omitempty"` Nodes map[string]cluster.NodeConfig `yaml:"nodes,omitempty"` }{ Count: ptrInt(1), CPU: ptrInt(2), Memory: ptrInt(2), Nodes: make(map[string]cluster.NodeConfig), }, Workers: struct { Count *int `yaml:"count,omitempty"` CPU *int `yaml:"cpu,omitempty"` Memory *int `yaml:"memory,omitempty"` Nodes map[string]cluster.NodeConfig `yaml:"nodes,omitempty"` }{ Count: ptrInt(1), CPU: ptrInt(4), Memory: ptrInt(4), Nodes: make(map[string]cluster.NodeConfig), }, }, DNS: &dns.DNSConfig{ Enabled: ptrBool(true), Name: ptrString("test"), Address: nil, }, }
DefaultLocalConfig returns the default configuration for the "local" context
Functions ¶
This section is empty.
Types ¶
type BaseConfigHandler ¶
type BaseConfigHandler struct {
ConfigHandler
}
BaseConfigHandler is a base implementation of the ConfigHandler interface
type Config ¶
type Config struct { Context *string `yaml:"context"` Contexts map[string]*Context `yaml:"contexts"` }
Config represents the entire configuration
type ConfigHandler ¶
type ConfigHandler interface { // LoadConfig loads the configuration from the specified path LoadConfig(path string) error // GetString retrieves a string value for the specified key from the configuration GetString(key string, defaultValue ...string) string // GetInt retrieves an integer value for the specified key from the configuration GetInt(key string, defaultValue ...int) int // GetBool retrieves a boolean value for the specified key from the configuration GetBool(key string, defaultValue ...bool) bool // Set sets the value for the specified key in the configuration Set(key string, value interface{}) error // SetContextValue sets the value for the specified key in the configuration SetContextValue(key string, value interface{}) error // Get retrieves a value for the specified key from the configuration Get(key string) interface{} // SaveConfig saves the current configuration to the specified path SaveConfig(path string) error // SetDefault sets the default context configuration SetDefault(context Context) error // GetConfig returns the context config object GetConfig() *Context }
ConfigHandler defines the interface for handling configuration operations
type Context ¶
type Context struct { Environment map[string]string `yaml:"environment,omitempty"` AWS *aws.AWSConfig `yaml:"aws,omitempty"` Docker *docker.DockerConfig `yaml:"docker,omitempty"` Git *git.GitConfig `yaml:"git,omitempty"` Terraform *terraform.TerraformConfig `yaml:"terraform,omitempty"` VM *vm.VMConfig `yaml:"vm,omitempty"` Cluster *cluster.ClusterConfig `yaml:"cluster,omitempty"` DNS *dns.DNSConfig `yaml:"dns,omitempty"` }
Context represents the context configuration
type MockConfigHandler ¶
type MockConfigHandler struct { LoadConfigFunc func(path string) error GetStringFunc func(key string, defaultValue ...string) string GetIntFunc func(key string, defaultValue ...int) int GetBoolFunc func(key string, defaultValue ...bool) bool SetFunc func(key string, value interface{}) error SetContextValueFunc func(key string, value interface{}) error SaveConfigFunc func(path string) error GetFunc func(key string) interface{} SetDefaultFunc func(context Context) error GetConfigFunc func() *Context }
MockConfigHandler is a mock implementation of the ConfigHandler interface
func NewMockConfigHandler ¶
func NewMockConfigHandler() *MockConfigHandler
NewMockConfigHandler is a constructor for MockConfigHandler
func (*MockConfigHandler) Get ¶
func (m *MockConfigHandler) Get(key string) interface{}
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() *Context
GetConfig calls the mock GetConfigFunc if set, otherwise returns a reasonable default Context
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) LoadConfig ¶
func (m *MockConfigHandler) LoadConfig(path string) error
LoadConfig calls the mock LoadConfigFunc 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 interface{}) error
Set calls the mock SetFunc if set, otherwise returns nil
func (*MockConfigHandler) SetContextValue ¶
func (m *MockConfigHandler) SetContextValue(key string, value interface{}) error
SetContextValue calls the mock SetContextValueFunc if set, otherwise returns nil
func (*MockConfigHandler) SetDefault ¶
func (m *MockConfigHandler) SetDefault(context Context) error
SetDefault calls the mock SetDefaultFunc if set, otherwise does nothing
type YamlConfigHandler ¶
type YamlConfigHandler struct { ConfigHandler // contains filtered or unexported fields }
YamlConfigHandler implements the ConfigHandler interface using goccy/go-yaml
func NewYamlConfigHandler ¶
func NewYamlConfigHandler() *YamlConfigHandler
NewYamlConfigHandler creates a new instance of YamlConfigHandler with default context configuration.
func (*YamlConfigHandler) Get ¶
func (y *YamlConfigHandler) Get(path string) interface{}
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() *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.
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) 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 interface{}) error
Set updates the value at the specified path in the configuration using reflection.
func (*YamlConfigHandler) SetContextValue ¶
func (y *YamlConfigHandler) SetContextValue(path string, value interface{}) error
SetContextValue sets a configuration value within the current context.
func (*YamlConfigHandler) SetDefault ¶
func (y *YamlConfigHandler) SetDefault(context Context) error
SetDefault sets the given context configuration as the default. Defaults to "local" if no current context is set.