config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

DefaultConfig returns the default configuration

View Source
var DefaultConfig_Full = v1alpha1.Context{
	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",
		},
	},
}
View Source
var DefaultConfig_Localhost = v1alpha1.Context{
	Environment: map[string]string{},
	Docker:      commonDockerConfig.Copy(),
	Git:         commonGitConfig.Copy(),
	Terraform:   commonTerraformConfig.Copy(),
	Cluster: &cluster.ClusterConfig{
		Enabled: ptrBool(true),
		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 file or cache

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

type ConfigHandler

type ConfigHandler interface {
	// Initialize initializes the config handler
	Initialize() error

	// 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

	// GetStringSlice retrieves a slice of strings for the specified key from the configuration
	GetStringSlice(key string, defaultValue ...[]string) []string

	// 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 v1alpha1.Context) error

	// GetConfig returns the context config object
	GetConfig() *v1alpha1.Context

	// GetContext retrieves the current context
	GetContext() string

	// SetContext sets the current context
	SetContext(context string) error

	// GetConfigRoot retrieves the configuration root path based on the current context
	GetConfigRoot() (string, error)

	// Clean cleans up context specific artifacts
	Clean() error
}

ConfigHandler defines the interface for handling configuration operations

type MockConfigHandler

type MockConfigHandler struct {
	InitializeFunc      func() error
	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
	GetStringSliceFunc  func(key string, defaultValue ...[]string) []string
	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 v1alpha1.Context) error
	GetConfigFunc       func() *v1alpha1.Context
	GetContextFunc      func() string
	SetContextFunc      func(context string) error
	GetConfigRootFunc   func() (string, error)
	CleanFunc           func() 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) 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() *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) 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) 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) 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 interface{}) 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

type YamlConfigHandler

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

YamlConfigHandler implements the ConfigHandler interface using goccy/go-yaml

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) 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() *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.

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.

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 v1alpha1.Context) error

SetDefault sets the given context configuration as the default.

Jump to

Keyboard shortcuts

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