config

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: BSD-3-Clause-Clear Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultUnsafeClockSkew is the default tolerated clock skew used when an unsafe override is not provided.
	DefaultUnsafeClockSkew = time.Minute
)
View Source
const LoaderNameDefaultSettings = "default-settings"
View Source
const LoaderNameEnvironmentValue = "environment-value"
View Source
const LoaderNameFile = "config-file"
View Source
const LoaderNameLegacy = "legacy"

Variables

View Source
var (
	ErrLoadingConfig       = errors.New("error loading config")
	ErrUnmarshallingConfig = errors.New("error unmarshalling config")
	ErrSettingConfig       = errors.New("error setting config")
)

Functions

This section is empty.

Types

type ChangeHook

type ChangeHook func(configServices ServicesMap) error

ChangeHook is a function invoked when the configuration changes.

type Config

type Config struct {
	// DevMode specifies whether the service is running in development mode.
	DevMode bool `mapstructure:"dev_mode" json:"dev_mode"`

	// DB represents the configuration settings for the database.
	DB db.Config `mapstructure:"db" json:"db"`

	// Server represents the configuration settings for the server.
	Server server.Config `mapstructure:"server" json:"server"`

	// Logger represents the configuration settings for the logger.
	Logger logger.Config `mapstructure:"logger" json:"logger"`

	// Mode specifies which services to run.
	// By default, it runs all services.
	Mode []string `mapstructure:"mode" json:"mode" default:"[\"all\"]"`

	// Security holds platform-wide security overrides.
	Security SecurityConfig `mapstructure:"security" json:"security"`

	// SDKConfig represents the configuration settings for the SDK.
	SDKConfig SDKConfig `mapstructure:"sdk_config" json:"sdk_config"`

	// Services represents the configuration settings for the services.
	Services ServicesMap `mapstructure:"services" json:"services"`
	// contains filtered or unexported fields
}

Config represents the configuration settings for the service.

func Load added in v0.10.0

func Load(ctx context.Context, loaders ...Loader) (*Config, error)

Load loads configuration using the provided loaders

func LoadConfig deprecated

func LoadConfig(ctx context.Context, key, file string) (*Config, error)

Deprecated: Use the `Load` method with your preferred loaders

func (*Config) AddLoader

func (c *Config) AddLoader(loader Loader)

AddLoader adds a configuration loader to the list of loaders.

func (*Config) AddOnConfigChangeHook

func (c *Config) AddOnConfigChangeHook(hook ChangeHook)

AddOnConfigChangeHook adds a hook to the list of hooks to call when the configuration changes.

func (*Config) Close

func (c *Config) Close(ctx context.Context) error

Close invokes close method on all config loaders.

func (*Config) LogValue

func (c *Config) LogValue() slog.Value

LogValue returns a slog.Value representation of the config. We exclude logging service configuration as it may contain sensitive information.

func (*Config) OnChange

func (c *Config) OnChange(ctx context.Context) error

OnChange invokes all registered onConfigChangeHooks after a configuration change.

func (*Config) Reload added in v0.10.0

func (c *Config) Reload(ctx context.Context) error

Reload re-reads and merges configuration from all registered loaders. It is thread-safe and handles dependencies between loaders by iterating until the configuration stabilizes.

func (*Config) Watch

func (c *Config) Watch(ctx context.Context) error

Watch starts watching the configuration for changes in all config loaders.

type Connection

type Connection struct {
	// Endpoint is the URL of the platform or service.
	Endpoint string `mapstructure:"endpoint" json:"endpoint"`

	// Plaintext specifies whether the SDK should use plaintext communication.
	Plaintext bool `mapstructure:"plaintext" json:"plaintext" default:"false" validate:"boolean"`

	// Insecure specifies whether the SDK should use insecure TLS communication.
	Insecure bool `mapstructure:"insecure" json:"insecure" default:"false" validate:"boolean"`
}

type DefaultSettingsLoader added in v0.10.0

type DefaultSettingsLoader struct {
	KVMap map[string]any
	// contains filtered or unexported fields
}

DefaultSettingsLoader implements Loader using Viper

func NewDefaultSettingsLoader added in v0.10.0

func NewDefaultSettingsLoader() (*DefaultSettingsLoader, error)

NewDefaultSettingsLoader creates a new Viper-based configuration loader to hold default config.

func (*DefaultSettingsLoader) Close added in v0.10.0

func (l *DefaultSettingsLoader) Close() error

func (*DefaultSettingsLoader) Get added in v0.10.0

func (l *DefaultSettingsLoader) Get(key string) (any, error)

Get fetches a particular config value by dot-delimited key from the source

func (*DefaultSettingsLoader) GetConfigKeys added in v0.10.0

func (l *DefaultSettingsLoader) GetConfigKeys() ([]string, error)

GetConfigKeys returns all the default configuration keys pulled from the Config struct.

func (*DefaultSettingsLoader) Load added in v0.10.0

func (l *DefaultSettingsLoader) Load(_ Config) error

Load loads the configuration into the provided struct

func (*DefaultSettingsLoader) Name added in v0.10.0

func (l *DefaultSettingsLoader) Name() string

func (*DefaultSettingsLoader) Watch added in v0.10.0

type EnvironmentValueLoader added in v0.10.0

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

EnvironmentValueLoader implements Loader using Viper

func NewEnvironmentValueLoader added in v0.10.0

func NewEnvironmentValueLoader(key string, allowList []string) (*EnvironmentValueLoader, error)

NewEnvironmentValueLoader creates a new Viper-based configuration loader to load from environment variables, from a default or specified file (or k8s config map), or some combination

func (*EnvironmentValueLoader) Close added in v0.10.0

func (l *EnvironmentValueLoader) Close() error

Close closes the environment configuration loader

func (*EnvironmentValueLoader) Get added in v0.10.0

func (l *EnvironmentValueLoader) Get(key string) (any, error)

Get fetches a particular config value by dot-delimited key from the source

func (*EnvironmentValueLoader) GetConfigKeys added in v0.10.0

func (l *EnvironmentValueLoader) GetConfigKeys() ([]string, error)

GetConfigKeys returns all the configuration keys found in the environment variables.

func (*EnvironmentValueLoader) Load added in v0.10.0

func (l *EnvironmentValueLoader) Load(_ Config) error

Load loads the configuration into the provided struct

func (*EnvironmentValueLoader) Name added in v0.10.0

func (l *EnvironmentValueLoader) Name() string

Name returns the name of the environment configuration loader

func (*EnvironmentValueLoader) Watch added in v0.10.0

Watch starts watching the config file for configuration changes

type FileLoader added in v0.10.0

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

FileLoader implements Loader using Viper

func NewConfigFileLoader added in v0.10.0

func NewConfigFileLoader(key, file string) (*FileLoader, error)

NewConfigFileLoader creates a new Viper-based configuration loader to load from a default or specified file.

func (*FileLoader) Close added in v0.10.0

func (l *FileLoader) Close() error

func (*FileLoader) Get added in v0.10.0

func (l *FileLoader) Get(key string) (any, error)

Get fetches a particular config value by dot-delimited key from the source

func (*FileLoader) GetConfigKeys added in v0.10.0

func (l *FileLoader) GetConfigKeys() ([]string, error)

GetConfigKeys returns all the configuration keys found in the config file.

func (*FileLoader) Load added in v0.10.0

func (l *FileLoader) Load(_ Config) error

Load loads the configuration into the provided struct

func (*FileLoader) Name added in v0.10.0

func (l *FileLoader) Name() string

func (*FileLoader) Watch added in v0.10.0

func (l *FileLoader) Watch(ctx context.Context, _ *Config, onChange func(context.Context) error) error

Watch starts watching the config file for configuration changes

type LegacyLoader added in v0.11.0

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

LegacyLoader enables loading values from a YAML file and the environment together

func NewLegacyLoader added in v0.11.0

func NewLegacyLoader(key, file string) (*LegacyLoader, error)

NewLegacyLoader creates a new Viper-based configuration loader to load from a default or specified file.

func (*LegacyLoader) Close added in v0.11.0

func (l *LegacyLoader) Close() error

func (*LegacyLoader) Get added in v0.11.0

func (l *LegacyLoader) Get(key string) (any, error)

Get fetches a particular config value by dot-delimited key from the source

func (*LegacyLoader) GetConfigKeys added in v0.11.0

func (l *LegacyLoader) GetConfigKeys() ([]string, error)

GetConfigKeys returns all the configuration keys found in the config file.

func (*LegacyLoader) Load added in v0.11.0

func (l *LegacyLoader) Load(cfg Config) error

Load is called to load/refresh the configuration from its source

func (*LegacyLoader) Name added in v0.11.0

func (l *LegacyLoader) Name() string

func (*LegacyLoader) Watch added in v0.11.0

func (l *LegacyLoader) Watch(ctx context.Context, _ *Config, onChange func(context.Context) error) error

Watch starts watching the config file for configuration changes

type Loader

type Loader interface {
	// Get fetches a particular config value by dot-delimited key
	Get(key string) (any, error)
	// GetConfigKeys returns all the top-level configuration keys that the loader can provide
	GetConfigKeys() ([]string, error)
	// Load is called to load/refresh the configuration from its source
	Load(mostRecentConfig Config) error
	// Watch starts watching for configuration changes and invokes an onChange callback
	Watch(ctx context.Context, cfg *Config, onChange func(context.Context) error) error
	// Close closes the configuration loader
	Close() error
	// Name returns the name of the configuration loader
	Name() string
}

Loader defines the interface for loading and managing configuration

type SDKConfig

type SDKConfig struct {
	// Connection to the Core Platform
	CorePlatformConnection Connection `mapstructure:"core" json:"core"`

	// Connection to an ERS if not in the core platform
	EntityResolutionConnection Connection `mapstructure:"entityresolution" json:"entityresolution"`

	// ClientID is the client ID used for client credentials grant.
	// It is required together with ClientSecret.
	ClientID string `mapstructure:"client_id" json:"client_id" validate:"required_with=ClientSecret"`

	// ClientSecret is the client secret used for client credentials grant.
	// It is required together with ClientID.
	ClientSecret string `mapstructure:"client_secret" json:"client_secret" validate:"required_with=ClientID"`
}

SDKConfig represents the configuration for the SDK.

func (SDKConfig) LogValue

func (c SDKConfig) LogValue() slog.Value

type SecurityConfig added in v0.11.4

type SecurityConfig struct {
	Unsafe UnsafeSecurityConfig `mapstructure:"unsafe" json:"unsafe"`
}

SecurityConfig collects platform-wide security toggles and overrides.

func (*SecurityConfig) ClockSkew added in v0.11.4

func (s *SecurityConfig) ClockSkew() time.Duration

ClockSkew returns the configured clock skew, defaulting to DefaultUnsafeClockSkew when unset.

type ServiceConfig

type ServiceConfig map[string]any

Config structure holding a single service.

func (ServiceConfig) LogValue added in v0.8.2

func (cfg ServiceConfig) LogValue() slog.Value

func (ServiceConfig) String added in v0.8.2

func (cfg ServiceConfig) String() string

type ServicesMap

type ServicesMap map[string]ServiceConfig

Config structure holding all services.

type UnsafeSecurityConfig added in v0.11.4

type UnsafeSecurityConfig struct {
	// ClockSkew increases the tolerated clock skew for token validation. Defaults to 1 minute.
	ClockSkew time.Duration `mapstructure:"clock_skew" json:"clock_skew"`
}

UnsafeSecurityConfig exposes overrides that may weaken standard security guarantees.

Jump to

Keyboard shortcuts

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