config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package config provides application configuration management using Viper. It supports configuration files, environment variables, and CLI flag overrides.

Index

Constants

View Source
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"
)
View Source
const (
	CatalogTypeFilesystem = "filesystem"
	CatalogTypeOCI        = "oci"
	CatalogTypeHTTP       = "http"
)

CatalogType constants define the supported catalog types.

View Source
const (
	HTTPClientCacheTypeMemory     = "memory"
	HTTPClientCacheTypeFilesystem = "filesystem"
)

HTTPClientCacheType constants define the supported HTTP cache types.

View Source
const CurrentConfigVersion = 1

CurrentConfigVersion is the current config file version.

View Source
const LoggingFormatConsole = "console"

LoggingFormatConsole is the human-readable console log format.

View Source
const LoggingFormatJSON = "json"

LoggingFormatJSON is the JSON log format.

View Source
const LoggingFormatText = "text"

LoggingFormatText is the text log format (alias for console).

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath() (string, error)

DefaultConfigPath returns the default configuration file path. Uses XDG Base Directory Specification.

func IsValidCatalogType

func IsValidCatalogType(t string) bool

IsValidCatalogType returns true if the given type is valid.

func IsValidHTTPClientCacheType

func IsValidHTTPClientCacheType(t string) bool

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.

func WithConfig

func WithConfig(ctx context.Context, cfg *Config) context.Context

WithConfig returns a new context with the Config stored in it.

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 BuildConfig added in v0.3.0

type BuildConfig struct {
	// EnableCache enables build-level caching to skip redundant builds.
	EnableCache *bool `json:"enableCache,omitempty" yaml:"enableCache,omitempty" mapstructure:"enableCache" doc:"Enable build-level caching"`

	// CacheDir is the directory for storing build cache entries.
	CacheDir string `json:"cacheDir,omitempty" yaml:"cacheDir,omitempty" mapstructure:"cacheDir" doc:"Build cache directory" maxLength:"4096"`

	// AutoCacheRemoteArtifacts automatically caches remote catalog fetches into the local catalog.
	AutoCacheRemoteArtifacts *bool `` /* 171-byte string literal not displayed */

	// PluginCacheDir is the directory for cached plugin binaries.
	PluginCacheDir string `` /* 146-byte string literal not displayed */
}

BuildConfig holds build command configuration.

func (*BuildConfig) IsAutoCacheRemoteArtifacts added in v0.3.0

func (b *BuildConfig) IsAutoCacheRemoteArtifacts() bool

IsAutoCacheRemoteArtifacts returns whether remote artifacts are auto-cached (defaults to true).

func (*BuildConfig) IsCacheEnabled added in v0.3.0

func (b *BuildConfig) IsCacheEnabled() bool

IsCacheEnabled returns whether build caching is enabled (defaults to true).

func (*BuildConfig) Validate added in v0.3.0

func (b *BuildConfig) Validate() error

Validate validates the build configuration.

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.

func (*CELConfig) Validate

func (c *CELConfig) Validate() error

Validate validates the CEL configuration. Returns an error if any value is invalid.

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"`
	Build      BuildConfig      `json:"build,omitempty" yaml:"build,omitempty" mapstructure:"build" doc:"Build command configuration"`
}

Config represents the application configuration.

func FromContext

func FromContext(ctx context.Context) *Config

FromContext retrieves the Config from the context. Returns nil if no Config is stored in the context.

func Global

func Global() (*Config, error)

Global returns the global configuration (loads once).

func MustFromContext

func MustFromContext(ctx context.Context) *Config

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

func (c *Config) CheckVersion() string

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

func (c *Config) RemoveCatalog(name string) error

RemoveCatalog removes a catalog by name.

func (*Config) SetDefaultCatalog

func (c *Config) SetDefaultCatalog(name string) error

SetDefaultCatalog sets the default catalog by name. Returns an error if the catalog doesn't exist.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the entire configuration. Returns an error if any configuration value is invalid.

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

func NewManager(configPath string) *Manager

NewManager creates a new configuration manager. If configPath is empty, the XDG-compliant default path will be used.

func (*Manager) AllSettings

func (m *Manager) AllSettings() map[string]any

AllSettings returns all settings as a map.

func (*Manager) Config

func (m *Manager) Config() *Config

Config returns the loaded configuration.

func (*Manager) ConfigPath

func (m *Manager) ConfigPath() string

ConfigPath returns the path to the config file.

func (*Manager) Get

func (m *Manager) Get(key string) any

Get returns a configuration value by key.

func (*Manager) GetUnknownKeys

func (m *Manager) GetUnknownKeys() []string

GetUnknownKeys returns a list of configuration keys that are not recognized by the config schema. Useful for programmatic validation.

func (*Manager) IsSet

func (m *Manager) IsSet(key string) bool

IsSet checks if a configuration key is set.

func (*Manager) Load

func (m *Manager) Load() (*Config, error)

Load loads the configuration from file and environment.

func (*Manager) Save

func (m *Manager) Save() error

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

func (m *Manager) SaveAs(path string) error

SaveAs saves the configuration to a specific path.

func (*Manager) Set

func (m *Manager) Set(key string, value any)

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

func (m *Manager) WarnUnknownKeys(ctx context.Context)

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.

Jump to

Keyboard shortcuts

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