config

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package config contains the definition of the application config structure and logic required to load and update it.

Index

Constants

View Source
const (
	// RegistryTypeFile represents a local file registry
	RegistryTypeFile = "file"
	// RegistryTypeURL represents a remote URL registry
	RegistryTypeURL = "url"
)

Variables

This section is empty.

Functions

func DetectRegistryType added in v0.2.4

func DetectRegistryType(input string) (registryType string, cleanPath string)

DetectRegistryType determines if input is a URL or file path and returns cleaned path

func ResetSingleton added in v0.3.0

func ResetSingleton()

ResetSingleton clears the singleton - useful for test cleanup

func SetSingletonConfig added in v0.3.0

func SetSingletonConfig(cfg *Config)

SetSingletonConfig allows tests to pre-initialize the singleton with test data This prevents the singleton from loading the real config file during tests

func UpdateConfig added in v0.0.32

func UpdateConfig(updateFn func(*Config)) error

UpdateConfig locks a separate lock file, reads from disk, applies the changes from the anonymous function, writes to disk and unlocks the file.

func UpdateConfigAtPath added in v0.0.45

func UpdateConfigAtPath(configPath string, updateFn func(*Config)) error

UpdateConfigAtPath locks a separate lock file, reads from disk, applies the changes from the anonymous function, writes to disk and unlocks the file. If configPath is empty, it uses the default path.

Types

type Clients

type Clients struct {
	RegisteredClients []string `yaml:"registered_clients"`
	AutoDiscovery     bool     `yaml:"auto_discovery"` // Deprecated: kept for migration purposes only
}

Clients contains settings for client configuration.

type Config

type Config struct {
	Secrets                Secrets             `yaml:"secrets"`
	Clients                Clients             `yaml:"clients"`
	RegistryUrl            string              `yaml:"registry_url"`
	LocalRegistryPath      string              `yaml:"local_registry_path"`
	AllowPrivateRegistryIp bool                `yaml:"allow_private_registry_ip"`
	CACertificatePath      string              `yaml:"ca_certificate_path,omitempty"`
	OTEL                   OpenTelemetryConfig `yaml:"otel,omitempty"`
	DefaultGroupMigration  bool                `yaml:"default_group_migration,omitempty"`
}

Config represents the configuration of the application.

func LoadOrCreateConfig

func LoadOrCreateConfig() (*Config, error)

LoadOrCreateConfig fetches the application configuration. If it does not already exist - it will create a new config file with default values.

func LoadOrCreateConfigFromPath added in v0.3.0

func LoadOrCreateConfigFromPath(configPath string) (*Config, error)

LoadOrCreateConfigFromPath is the core implementation for loading/creating config from a specific path

func LoadOrCreateConfigWithDefaultPath added in v0.3.0

func LoadOrCreateConfigWithDefaultPath() (*Config, error)

LoadOrCreateConfigWithDefaultPath is the internal implementation for loading config with the default path. This avoids circular dependency issues.

func LoadOrCreateConfigWithPath added in v0.0.45

func LoadOrCreateConfigWithPath(configPath string) (*Config, error)

LoadOrCreateConfigWithPath fetches the application configuration from a specific path. If configPath is empty, it uses the default path. If it does not already exist - it will create a new config file with default values.

type DefaultProvider added in v0.2.14

type DefaultProvider struct{}

DefaultProvider implements Provider using the default XDG config path

func NewDefaultProvider added in v0.2.14

func NewDefaultProvider() *DefaultProvider

NewDefaultProvider creates a new default config provider

func (*DefaultProvider) GetConfig added in v0.2.14

func (*DefaultProvider) GetConfig() *Config

GetConfig returns the singleton config (for backward compatibility)

func (*DefaultProvider) GetRegistryConfig added in v0.3.0

func (d *DefaultProvider) GetRegistryConfig() (url, localPath string, allowPrivateIP bool, registryType string)

GetRegistryConfig returns current registry configuration

func (*DefaultProvider) LoadOrCreateConfig added in v0.2.14

func (*DefaultProvider) LoadOrCreateConfig() (*Config, error)

LoadOrCreateConfig loads or creates config using the default path

func (*DefaultProvider) SetRegistryFile added in v0.3.0

func (d *DefaultProvider) SetRegistryFile(registryPath string) error

SetRegistryFile validates and sets a local registry file

func (*DefaultProvider) SetRegistryURL added in v0.3.0

func (d *DefaultProvider) SetRegistryURL(registryURL string, allowPrivateRegistryIp bool) error

SetRegistryURL validates and sets a registry URL

func (*DefaultProvider) UnsetRegistry added in v0.3.0

func (d *DefaultProvider) UnsetRegistry() error

UnsetRegistry resets registry configuration to defaults

func (*DefaultProvider) UpdateConfig added in v0.2.14

func (*DefaultProvider) UpdateConfig(updateFn func(*Config)) error

UpdateConfig updates the config using the default path

type KubernetesProvider added in v0.3.0

type KubernetesProvider struct{}

KubernetesProvider is a no-op implementation of Provider for Kubernetes environments. In Kubernetes, configuration is managed by the cluster, not by local files.

func NewKubernetesProvider added in v0.3.0

func NewKubernetesProvider() *KubernetesProvider

NewKubernetesProvider creates a new no-op config provider for Kubernetes environments

func (*KubernetesProvider) GetConfig added in v0.3.0

func (*KubernetesProvider) GetConfig() *Config

GetConfig returns a default config for Kubernetes environments

func (*KubernetesProvider) GetRegistryConfig added in v0.3.0

func (*KubernetesProvider) GetRegistryConfig() (url, localPath string, allowPrivateIP bool, registryType string)

GetRegistryConfig returns empty registry configuration for Kubernetes environments

func (*KubernetesProvider) LoadOrCreateConfig added in v0.3.0

func (*KubernetesProvider) LoadOrCreateConfig() (*Config, error)

LoadOrCreateConfig returns a default config for Kubernetes environments

func (*KubernetesProvider) SetRegistryFile added in v0.3.0

func (*KubernetesProvider) SetRegistryFile(_ string) error

SetRegistryFile is a no-op for Kubernetes environments

func (*KubernetesProvider) SetRegistryURL added in v0.3.0

func (*KubernetesProvider) SetRegistryURL(_ string, _ bool) error

SetRegistryURL is a no-op for Kubernetes environments

func (*KubernetesProvider) UnsetRegistry added in v0.3.0

func (*KubernetesProvider) UnsetRegistry() error

UnsetRegistry is a no-op for Kubernetes environments

func (*KubernetesProvider) UpdateConfig added in v0.3.0

func (*KubernetesProvider) UpdateConfig(_ func(*Config)) error

UpdateConfig is a no-op for Kubernetes environments

type OpenTelemetryConfig added in v0.1.2

type OpenTelemetryConfig struct {
	Endpoint                    string   `yaml:"endpoint,omitempty"`
	SamplingRate                float64  `yaml:"sampling-rate,omitempty"`
	EnvVars                     []string `yaml:"env-vars,omitempty"`
	MetricsEnabled              bool     `yaml:"metrics-enabled,omitempty"`
	TracingEnabled              bool     `yaml:"tracing-enabled,omitempty"`
	Insecure                    bool     `yaml:"insecure,omitempty"`
	EnablePrometheusMetricsPath bool     `yaml:"enable-prometheus-metrics-path,omitempty"`
}

OpenTelemetryConfig contains the settings for OpenTelemetry configuration.

type PathProvider added in v0.2.14

type PathProvider struct {
	// contains filtered or unexported fields
}

PathProvider implements Provider using a specific config path

func NewPathProvider added in v0.2.14

func NewPathProvider(configPath string) *PathProvider

NewPathProvider creates a new config provider with a specific path

func (*PathProvider) GetConfig added in v0.2.14

func (p *PathProvider) GetConfig() *Config

GetConfig loads and returns the config from the specific path

func (*PathProvider) GetRegistryConfig added in v0.3.0

func (p *PathProvider) GetRegistryConfig() (url, localPath string, allowPrivateIP bool, registryType string)

GetRegistryConfig returns current registry configuration

func (*PathProvider) LoadOrCreateConfig added in v0.2.14

func (p *PathProvider) LoadOrCreateConfig() (*Config, error)

LoadOrCreateConfig loads or creates config at the specific path

func (*PathProvider) SetRegistryFile added in v0.3.0

func (p *PathProvider) SetRegistryFile(registryPath string) error

SetRegistryFile validates and sets a local registry file

func (*PathProvider) SetRegistryURL added in v0.3.0

func (p *PathProvider) SetRegistryURL(registryURL string, allowPrivateRegistryIp bool) error

SetRegistryURL validates and sets a registry URL

func (*PathProvider) UnsetRegistry added in v0.3.0

func (p *PathProvider) UnsetRegistry() error

UnsetRegistry resets registry configuration to defaults

func (*PathProvider) UpdateConfig added in v0.2.14

func (p *PathProvider) UpdateConfig(updateFn func(*Config)) error

UpdateConfig updates the config at the specific path

type Provider added in v0.2.14

type Provider interface {
	GetConfig() *Config
	UpdateConfig(updateFn func(*Config)) error
	LoadOrCreateConfig() (*Config, error)

	// Registry operations
	SetRegistryURL(registryURL string, allowPrivateRegistryIp bool) error
	SetRegistryFile(registryPath string) error
	UnsetRegistry() error
	GetRegistryConfig() (url, localPath string, allowPrivateIP bool, registryType string)
}

Provider defines the interface for configuration operations

func NewProvider added in v0.3.0

func NewProvider() Provider

NewProvider creates the appropriate config provider based on the runtime environment

type Secrets

type Secrets struct {
	ProviderType   string `yaml:"provider_type"`
	SetupCompleted bool   `yaml:"setup_completed"`
}

Secrets contains the settings for secrets management.

func (*Secrets) GetProviderType added in v0.0.33

func (s *Secrets) GetProviderType() (secrets.ProviderType, error)

GetProviderType returns the secrets provider type from the environment variable or application config. It first checks the TOOLHIVE_SECRETS_PROVIDER environment variable, and falls back to the config file. Returns ErrSecretsNotSetup if secrets have not been configured yet.

func (*Secrets) GetProviderTypeWithEnv added in v0.2.13

func (s *Secrets) GetProviderTypeWithEnv(envReader env.Reader) (secrets.ProviderType, error)

GetProviderTypeWithEnv returns the secrets provider type using the provided environment reader. This method allows for dependency injection of environment variable access for testing.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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