Documentation
¶
Overview ¶
Package config provides application configuration management using Viper. It supports configuration files, environment variables, and CLI flag overrides.
Index ¶
- Constants
- func DefaultConfigPath() (string, error)
- func IsValidCatalogType(t string) bool
- func IsValidHTTPClientCacheType(t string) bool
- func ResetGlobal()
- func ValidCatalogTypes() []string
- func ValidHTTPClientCacheTypes() []string
- func WithConfig(ctx context.Context, cfg *Config) context.Context
- type ActionConfig
- type ActionConfigValues
- type AuthConfig
- type CELConfig
- type CELConfigValues
- type CatalogConfig
- type Config
- func (c *Config) AddCatalog(catalog CatalogConfig) error
- func (c *Config) CheckVersion() string
- func (c *Config) GetCatalog(name string) (*CatalogConfig, bool)
- func (c *Config) GetDefaultCatalog() (*CatalogConfig, bool)
- func (c *Config) RemoveCatalog(name string) error
- func (c *Config) SetDefaultCatalog(name string) error
- func (c *Config) Validate() error
- type EntraAuthConfig
- type GlobalAuthConfig
- type HTTPClientConfig
- type LoggingConfig
- type Manager
- func (m *Manager) AllSettings() map[string]any
- func (m *Manager) Config() *Config
- func (m *Manager) ConfigPath() string
- func (m *Manager) Get(key string) any
- func (m *Manager) GetUnknownKeys() []string
- func (m *Manager) IsSet(key string) bool
- func (m *Manager) Load() (*Config, error)
- func (m *Manager) Save() error
- func (m *Manager) SaveAs(path string) error
- func (m *Manager) Set(key string, value any)
- func (m *Manager) WarnUnknownKeys(ctx context.Context)
- type ResolverConfig
- type ResolverConfigValues
- type Settings
Constants ¶
const ( // DefaultConfigFileName is the default config file name (without extension). DefaultConfigFileName = "config" // DefaultConfigFileType is the default config file type. DefaultConfigFileType = "yaml" // EnvPrefix is the environment variable prefix. EnvPrefix = "SCAFCTL" )
const ( CatalogTypeFilesystem = "filesystem" CatalogTypeOCI = "oci" CatalogTypeHTTP = "http" )
CatalogType constants define the supported catalog types.
const ( HTTPClientCacheTypeMemory = "memory" HTTPClientCacheTypeFilesystem = "filesystem" )
HTTPClientCacheType constants define the supported HTTP cache types.
const CurrentConfigVersion = 1
CurrentConfigVersion is the current config file version.
const LoggingFormatConsole = "console"
LoggingFormatConsole is the human-readable console log format.
const LoggingFormatJSON = "json"
LoggingFormatJSON is the JSON log format.
const LoggingFormatText = "text"
LoggingFormatText is the text log format (alias for console).
Variables ¶
This section is empty.
Functions ¶
func DefaultConfigPath ¶
DefaultConfigPath returns the default configuration file path. Uses XDG Base Directory Specification.
func IsValidCatalogType ¶
IsValidCatalogType returns true if the given type is valid.
func IsValidHTTPClientCacheType ¶
IsValidHTTPClientCacheType returns true if the given cache type is valid.
func ResetGlobal ¶
func ResetGlobal()
ResetGlobal resets the global configuration (primarily for testing).
func ValidCatalogTypes ¶
func ValidCatalogTypes() []string
ValidCatalogTypes returns the list of valid catalog types.
func ValidHTTPClientCacheTypes ¶
func ValidHTTPClientCacheTypes() []string
ValidHTTPClientCacheTypes returns the list of valid HTTP cache types.
Types ¶
type ActionConfig ¶
type ActionConfig struct {
// DefaultTimeout is the default timeout per action execution
DefaultTimeout string `` /* 150-byte string literal not displayed */
// GracePeriod is the cancellation grace period
GracePeriod string `` /* 145-byte string literal not displayed */
// MaxConcurrency is the max concurrent actions (0 = unlimited)
MaxConcurrency int `` /* 162-byte string literal not displayed */
}
ActionConfig holds action executor configuration.
func (*ActionConfig) ToActionValues ¶
func (a *ActionConfig) ToActionValues() (ActionConfigValues, error)
ToActionValues converts ActionConfig to an ActionConfigValues struct. Duration strings are parsed, and zero/empty values use defaults from settings.
func (*ActionConfig) Validate ¶
func (a *ActionConfig) Validate() error
Validate validates the action configuration. Returns an error if any value is invalid.
type ActionConfigValues ¶
type ActionConfigValues struct {
DefaultTimeout time.Duration
GracePeriod time.Duration
MaxConcurrency int
}
ActionConfigValues holds parsed action config values with durations.
type AuthConfig ¶
type AuthConfig struct {
Type string `json:"type" yaml:"type" mapstructure:"type" doc:"Auth type" example:"token" maxLength:"50"`
TokenEnvVar string `` /* 144-byte string literal not displayed */
}
AuthConfig holds authentication settings for a catalog.
type CELConfig ¶
type CELConfig struct {
// CacheSize is the maximum number of compiled programs to cache
CacheSize int `` /* 141-byte string literal not displayed */
// CostLimit is the cost limit for expression evaluation (0 = disabled)
// Prevents runaway expressions from consuming resources
CostLimit int64 `` /* 130-byte string literal not displayed */
// UseASTBasedCaching enables AST-based cache key generation for better hit rates
// Expressions with same structure share cache entries
UseASTBasedCaching bool `` /* 139-byte string literal not displayed */
// EnableMetrics enables expression metrics collection
EnableMetrics *bool `json:"enableMetrics,omitempty" yaml:"enableMetrics,omitempty" mapstructure:"enableMetrics" doc:"Enable expression metrics"`
}
CELConfig holds CEL expression engine configuration.
func (*CELConfig) ToCELValues ¶
func (c *CELConfig) ToCELValues() CELConfigValues
ToCELValues converts CELConfig to a CELConfigValues struct. If a config value is zero/empty, the default value from settings is used.
type CELConfigValues ¶
type CELConfigValues struct {
CacheSize int
CostLimit int64
UseASTBasedCaching bool
EnableMetrics bool
}
CELConfigToCELInput converts CELConfig to celexp.CELConfigInput values. This avoids circular dependencies between config and celexp packages.
type CatalogConfig ¶
type CatalogConfig struct {
Name string `json:"name" yaml:"name" mapstructure:"name" doc:"Catalog name" example:"internal" maxLength:"255"`
Type string `json:"type" yaml:"type" mapstructure:"type" doc:"Catalog type" example:"filesystem" maxLength:"50"`
Path string `json:"path,omitempty" yaml:"path,omitempty" mapstructure:"path" doc:"Path for filesystem catalogs" maxLength:"4096"`
URL string `json:"url,omitempty" yaml:"url,omitempty" mapstructure:"url" doc:"URL for remote catalogs" maxLength:"2048"`
Auth *AuthConfig `json:"auth,omitempty" yaml:"auth,omitempty" mapstructure:"auth" doc:"Authentication configuration"`
Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty" mapstructure:"metadata" doc:"Additional metadata"`
HTTPClient *HTTPClientConfig `` /* 144-byte string literal not displayed */
}
CatalogConfig represents a single catalog configuration.
func (*CatalogConfig) Validate ¶
func (c *CatalogConfig) Validate() error
Validate validates a catalog configuration.
type Config ¶
type Config struct {
Version int `json:"version,omitempty" yaml:"version,omitempty" mapstructure:"version" doc:"Config file version" example:"1" maximum:"100"`
Catalogs []CatalogConfig `json:"catalogs" yaml:"catalogs" mapstructure:"catalogs" doc:"Configured catalogs" maxItems:"50"`
Settings Settings `json:"settings" yaml:"settings" mapstructure:"settings" doc:"Application settings"`
Logging LoggingConfig `json:"logging,omitempty" yaml:"logging,omitempty" mapstructure:"logging" doc:"Logging configuration"`
HTTPClient HTTPClientConfig `json:"httpClient,omitempty" yaml:"httpClient,omitempty" mapstructure:"httpClient" doc:"Global HTTP client configuration"`
CEL CELConfig `json:"cel,omitempty" yaml:"cel,omitempty" mapstructure:"cel" doc:"CEL expression engine configuration"`
Resolver ResolverConfig `json:"resolver,omitempty" yaml:"resolver,omitempty" mapstructure:"resolver" doc:"Resolver executor configuration"`
Action ActionConfig `json:"action,omitempty" yaml:"action,omitempty" mapstructure:"action" doc:"Action executor configuration"`
Auth GlobalAuthConfig `json:"auth,omitempty" yaml:"auth,omitempty" mapstructure:"auth" doc:"Authentication handler configuration"`
}
Config represents the application configuration.
func FromContext ¶
FromContext retrieves the Config from the context. Returns nil if no Config is stored in the context.
func MustFromContext ¶
MustFromContext retrieves the Config from the context. Panics if no Config is stored in the context.
func (*Config) AddCatalog ¶
func (c *Config) AddCatalog(catalog CatalogConfig) error
AddCatalog adds a new catalog configuration.
func (*Config) CheckVersion ¶
CheckVersion checks if the config version is current and returns a warning message if not. Returns an empty string if the version is current or if version checking should be skipped.
func (*Config) GetCatalog ¶
func (c *Config) GetCatalog(name string) (*CatalogConfig, bool)
GetCatalog returns a catalog configuration by name.
func (*Config) GetDefaultCatalog ¶
func (c *Config) GetDefaultCatalog() (*CatalogConfig, bool)
GetDefaultCatalog returns the default catalog configuration.
func (*Config) RemoveCatalog ¶
RemoveCatalog removes a catalog by name.
func (*Config) SetDefaultCatalog ¶
SetDefaultCatalog sets the default catalog by name. Returns an error if the catalog doesn't exist.
type EntraAuthConfig ¶
type EntraAuthConfig struct {
// ClientID overrides the default application ID.
// If not set, uses the default scafctl public client ID.
ClientID string `json:"clientId,omitempty" yaml:"clientId,omitempty" mapstructure:"clientId" doc:"Azure application ID" maxLength:"36"`
// TenantID sets the default tenant for authentication.
// Use "common" for multi-tenant, "organizations" for work/school only,
// or a specific tenant GUID.
TenantID string `` /* 137-byte string literal not displayed */
// DefaultScopes are requested during login if not specified on command line.
DefaultScopes []string `` /* 131-byte string literal not displayed */
}
EntraAuthConfig contains Entra-specific configuration.
type GlobalAuthConfig ¶
type GlobalAuthConfig struct {
// Entra contains Microsoft Entra ID configuration.
Entra *EntraAuthConfig `json:"entra,omitempty" yaml:"entra,omitempty" mapstructure:"entra" doc:"Microsoft Entra ID configuration"`
}
GlobalAuthConfig holds authentication handler configuration.
type HTTPClientConfig ¶
type HTTPClientConfig struct {
// Timeout is the maximum time to wait for a request to complete
Timeout string `` /* 128-byte string literal not displayed */
// Retry settings
RetryMax int `` /* 132-byte string literal not displayed */
RetryWaitMin string `` /* 155-byte string literal not displayed */
RetryWaitMax string `` /* 156-byte string literal not displayed */
// Cache settings
EnableCache *bool `json:"enableCache,omitempty" yaml:"enableCache,omitempty" mapstructure:"enableCache" doc:"Enable HTTP response caching"`
CacheType string `` /* 153-byte string literal not displayed */
CacheDir string `` /* 161-byte string literal not displayed */
CacheTTL string `` /* 144-byte string literal not displayed */
CacheKeyPrefix string `` /* 155-byte string literal not displayed */
MaxCacheFileSize int64 `` /* 171-byte string literal not displayed */
MemoryCacheSize int `` /* 176-byte string literal not displayed */
// Circuit breaker settings
EnableCircuitBreaker *bool `` /* 148-byte string literal not displayed */
CircuitBreakerMaxFailures int `` /* 190-byte string literal not displayed */
CircuitBreakerOpenTimeout string `` /* 194-byte string literal not displayed */
CircuitBreakerHalfOpenMaxRequests int `` /* 229-byte string literal not displayed */
// Compression
EnableCompression *bool `` /* 142-byte string literal not displayed */
}
HTTPClientConfig holds HTTP client configuration settings. All duration fields use string format (e.g., "30s", "5m", "1h").
func (*HTTPClientConfig) Validate ¶
func (h *HTTPClientConfig) Validate() error
Validate validates the HTTP client configuration. Returns an error if any value is invalid.
type LoggingConfig ¶
type LoggingConfig struct {
Level string `` /* 174-byte string literal not displayed */
Format string `` /* 144-byte string literal not displayed */
Timestamps bool `json:"timestamps,omitempty" yaml:"timestamps,omitempty" mapstructure:"timestamps" doc:"Include timestamps in logs"`
EnableProfiling bool `` /* 142-byte string literal not displayed */
}
LoggingConfig holds logging configuration.
func (*LoggingConfig) Validate ¶
func (l *LoggingConfig) Validate() error
Validate validates the logging configuration. Returns an error if any value is invalid.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles configuration loading and access.
func NewManager ¶
NewManager creates a new configuration manager. If configPath is empty, the XDG-compliant default path will be used.
func (*Manager) AllSettings ¶
AllSettings returns all settings as a map.
func (*Manager) ConfigPath ¶
ConfigPath returns the path to the config file.
func (*Manager) GetUnknownKeys ¶
GetUnknownKeys returns a list of configuration keys that are not recognized by the config schema. Useful for programmatic validation.
func (*Manager) Save ¶
Save saves the current configuration to file. It syncs m.config to viper before writing, then uses viper's WriteConfig. This allows both direct config modification AND Set() calls to be persisted.
func (*Manager) Set ¶
Set sets a configuration value. For individual settings fields (e.g., "logging.level"), this also updates m.config to keep it in sync. For top-level struct values like "settings" or "catalogs", only viper is updated (the caller should modify cfg directly instead).
func (*Manager) WarnUnknownKeys ¶
WarnUnknownKeys logs warnings for any configuration keys that are not recognized by the config schema. This helps users identify typos or deprecated settings in their config files.
type ResolverConfig ¶
type ResolverConfig struct {
// Timeout is the default timeout per resolver execution
Timeout string `` /* 132-byte string literal not displayed */
// PhaseTimeout is the maximum time for each resolution phase
PhaseTimeout string `` /* 144-byte string literal not displayed */
// MaxConcurrency is the maximum concurrent resolvers per phase (0 = unlimited)
MaxConcurrency int `` /* 166-byte string literal not displayed */
// WarnValueSize is the warn threshold in bytes (0 = disabled)
WarnValueSize int64 `` /* 138-byte string literal not displayed */
// MaxValueSize is the max value size in bytes (0 = disabled)
MaxValueSize int64 `` /* 136-byte string literal not displayed */
// ValidateAll enables collecting all errors instead of stopping at first
ValidateAll bool `` /* 126-byte string literal not displayed */
}
ResolverConfig holds resolver executor configuration.
func (*ResolverConfig) ToResolverValues ¶
func (r *ResolverConfig) ToResolverValues() (ResolverConfigValues, error)
ToResolverValues converts ResolverConfig to a ResolverConfigValues struct. Duration strings are parsed, and zero/empty values use defaults from settings.
func (*ResolverConfig) Validate ¶
func (r *ResolverConfig) Validate() error
Validate validates the resolver configuration. Returns an error if any value is invalid.
type ResolverConfigValues ¶
type ResolverConfigValues struct {
Timeout time.Duration
PhaseTimeout time.Duration
MaxConcurrency int
WarnValueSize int64
MaxValueSize int64
ValidateAll bool
}
ResolverConfigValues holds parsed resolver config values with durations.
type Settings ¶
type Settings struct {
DefaultCatalog string `` /* 154-byte string literal not displayed */
NoColor bool `json:"noColor,omitempty" yaml:"noColor,omitempty" mapstructure:"noColor" doc:"Disable colored output"`
Quiet bool `json:"quiet,omitempty" yaml:"quiet,omitempty" mapstructure:"quiet" doc:"Suppress non-essential output"`
}
Settings holds application-wide settings.