settings

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultResolverTimeout is the default timeout for individual resolver execution.
	DefaultResolverTimeout = 30 * time.Second

	// DefaultPhaseTimeout is the default timeout for resolver phase execution.
	DefaultPhaseTimeout = 5 * time.Minute

	// DefaultActionTimeout is the default timeout for action execution.
	DefaultActionTimeout = 5 * time.Minute

	// DefaultGracePeriod is the default grace period for action cancellation.
	DefaultGracePeriod = 30 * time.Second

	// DefaultPluginFetchTimeout is the default timeout for fetching plugins from catalogs.
	DefaultPluginFetchTimeout = 2 * time.Minute

	// DefaultPluginResolveTimeout is the default timeout for plugin resolution
	DefaultPluginResolveTimeout = 30 * time.Second
)

Timeout defaults

View Source
const (
	// DefaultConflictStrategy is the default conflict resolution strategy for file writes.
	DefaultConflictStrategy = "error"

	// DefaultMaxBackups is the maximum number of backup files (.bak, .bak.1, etc.) per source file.
	DefaultMaxBackups = 5
)

File conflict defaults

View Source
const (
	// DefaultHTTPTimeout is the default timeout for HTTP requests.
	DefaultHTTPTimeout = 30 * time.Second

	// DefaultHTTPRetryMax is the default maximum number of HTTP retries.
	DefaultHTTPRetryMax = 3

	// DefaultHTTPRetryWaitMinimum is the minimum wait time between HTTP retries.
	DefaultHTTPRetryWaitMinimum = 1 * time.Second

	// DefaultHTTPRetryWaitMaximum is the maximum wait time between HTTP retries.
	DefaultHTTPRetryWaitMaximum = 30 * time.Second

	// DefaultHTTPCacheTTL is the default TTL for HTTP cache entries.
	DefaultHTTPCacheTTL = 10 * time.Minute

	// DefaultHTTPCacheKeyPrefix is the default prefix for HTTP cache keys.
	DefaultHTTPCacheKeyPrefix = "scafctl:"

	// DefaultArtifactCacheTTL is the default TTL for the artifact cache.
	// Catalog artifacts are cached for 24 hours by default.
	DefaultArtifactCacheTTL = 24 * time.Hour

	// DefaultRegistryConcurrency is the maximum number of concurrent OCI
	// registry requests when listing artifacts. Bounded to avoid
	// rate-limiting (429s) on registries like GHCR or Docker Hub.
	DefaultRegistryConcurrency = 5
)

HTTP client defaults

View Source
const (
	// DefaultPluginCacheMaxSize is the default maximum size for the managed
	// plugin cache in API server mode. Parsed as a human-readable byte string
	// (e.g., "512MB", "1GB"). 512 MB comfortably holds ~35 plugins with room
	// for version overlap during updates.
	DefaultPluginCacheMaxSize = "512MB"

	// DefaultMaxResponseBodySize is the maximum HTTP response body size the
	// HTTP provider will read into memory (100 MB). This prevents denial of
	// service via unbounded response bodies from malicious or misconfigured
	// servers. Configurable per-deployment via httpClient.maxResponseBodySize.
	DefaultMaxResponseBodySize int64 = 100 * 1024 * 1024

	// DefaultMaxCacheFileSize is the maximum size for a single cached file (10MB).
	DefaultMaxCacheFileSize = 10 * 1024 * 1024

	// DefaultMemoryCacheSize is the maximum number of entries in memory caches.
	DefaultMemoryCacheSize = 1000

	// DefaultWarnValueSize is the threshold for warning about large resolver values (1MB).
	DefaultWarnValueSize = 1024 * 1024

	// DefaultMaxValueSize is the maximum allowed resolver value size (10MB).
	DefaultMaxValueSize = 10 * 1024 * 1024
)

Size limits

View Source
const (
	// DefaultOTelSamplerType is the default trace sampler. always_on means every
	// span is recorded (appropriate for a CLI tool with low call volume).
	DefaultOTelSamplerType = "always_on"

	// DefaultOTelSamplerArg is the default argument for the sampler.
	// For traceidratio this is the sampling probability (0.0–1.0).
	DefaultOTelSamplerArg = 1.0
)

OTel / telemetry defaults

View Source
const (
	// DefaultCELCacheSize is the default size for the CEL program cache.
	DefaultCELCacheSize = 10000

	// DefaultCELCostLimit is the default cost limit for CEL expression evaluation.
	// Set to 0 to disable cost limiting.
	DefaultCELCostLimit = 1000000
)

CEL defaults

View Source
const (
	// DefaultGRPCMaxMessageSize is the default maximum gRPC message size for
	// plugin communication (64 MB). The Go gRPC library default is 4 MB, which
	// is too small for solutions with legitimately large provider inputs or
	// outputs (e.g., large HCL files, API responses). This applies to both
	// send and receive directions.
	DefaultGRPCMaxMessageSize = 64 * 1024 * 1024

	// MinGRPCMaxMessageSize is the minimum accepted gRPC message size (1 MB).
	// Values below this floor are treated as misconfiguration and the default
	// is used instead. Matches the minimum:"1048576" validation tag on the
	// config struct.
	MinGRPCMaxMessageSize = 1024 * 1024

	// DefaultFetchConcurrency is the max concurrency for plugin fetches in FetchPlugins (errgroup limit).
	DefaultFetchConcurrency = 4
)

Plugin defaults

View Source
const (
	// DefaultAPIPort is the default port for the API server.
	DefaultAPIPort = 8080

	// DefaultAPIHost is the default host for the API server.
	// Binds to localhost only; use --host 0.0.0.0 or config to expose publicly.
	DefaultAPIHost = "127.0.0.1"

	// DefaultAPIVersion is the default API version prefix.
	DefaultAPIVersion = "v1"

	// DefaultAPIShutdownTimeout is the default graceful shutdown timeout.
	DefaultAPIShutdownTimeout = "30s"

	// DefaultAPIRequestTimeout is the default request timeout.
	DefaultAPIRequestTimeout = "60s"

	// DefaultAPIMaxRequestSize is the default maximum request body size in bytes (10MB).
	DefaultAPIMaxRequestSize int64 = 10 * 1024 * 1024

	// DefaultAPICompressionLevel is the default gzip compression level.
	DefaultAPICompressionLevel = 6

	// DefaultAPICORSMaxAge is the default CORS max age in seconds.
	DefaultAPICORSMaxAge = 3600

	// DefaultAPIRateLimitMaxRequests is the default rate limit max requests.
	DefaultAPIRateLimitMaxRequests = 100

	// DefaultAPIRateLimitWindow is the default rate limit window.
	DefaultAPIRateLimitWindow = "1m"

	// DefaultAPIMaxConcurrentRequests is the default max concurrent in-flight requests (chi Throttle).
	DefaultAPIMaxConcurrentRequests = 1000

	// DefaultAPIFilterCostLimit is the CEL cost limit for API filter expressions.
	// Lower than the CLI default (1,000,000) to prevent DoS via user-supplied expressions.
	DefaultAPIFilterCostLimit uint64 = 10000

	// DefaultAPIEvalCostLimit is the CEL cost limit for the eval endpoint.
	// Higher than the filter limit because eval is the primary use-case, but
	// still bounded to protect the server from expensive expressions.
	DefaultAPIEvalCostLimit uint64 = 100000

	// DefaultAPIBodyReadTimeout is the default timeout for reading request bodies.
	DefaultAPIBodyReadTimeout = "15s"

	// DefaultAPIOperationMaxBodyBytes is the default per-operation max body size (1 MiB).
	// This is the Huma-level limit; the chi middleware limit (MaxRequestSize) is the outer bound.
	DefaultAPIOperationMaxBodyBytes int64 = 1 << 20

	// DefaultAPIAdminMaxBodyBytes is the max body size for admin endpoints (1 KiB).
	// Admin POST endpoints have empty or tiny bodies.
	DefaultAPIAdminMaxBodyBytes int64 = 1024

	// DefaultAPIEvalTimeout is the maximum wall-clock time allowed for a single
	// CEL or Go-template evaluation request. Prevents CPU exhaustion from
	// expensive user-supplied expressions.
	DefaultAPIEvalTimeout = 30 * time.Second

	// DefaultAPIIdentityCacheSize is the default LRU cache size for delegated tokens.
	DefaultAPIIdentityCacheSize = 1024
)

API server defaults

View Source
const (
	// DefaultCircuitBreakerMaxFailures is the number of consecutive failures before opening the circuit.
	DefaultCircuitBreakerMaxFailures = 5

	// DefaultCircuitBreakerOpenTimeout is how long to wait before transitioning from Open to HalfOpen.
	DefaultCircuitBreakerOpenTimeout = 30 * time.Second

	// DefaultCircuitBreakerHalfOpenRequests is the number of successful requests in HalfOpen before closing.
	DefaultCircuitBreakerHalfOpenRequests = 1
)

Circuit breaker defaults

View Source
const (
	CliBinaryName = "scafctl"
)
View Source
const (
	// DefaultGoTemplateCacheSize is the default size for the Go template compilation cache.
	DefaultGoTemplateCacheSize = 10000
)

Go template defaults

Variables

View Source
var VersionInformation = VersionInfo{
	Commit:       "unknown",
	BuildVersion: "v0.0.0-nightly",
	BuildTime:    "unknown",
}

Functions

func ActionFileNamesFor added in v0.10.0

func ActionFileNamesFor(binaryName string) []string

ActionFileNamesFor returns the action-preferred file names for the given binary name. Action files come first, then solution files as fallback.

func BinaryNameFromContext added in v0.7.0

func BinaryNameFromContext(ctx context.Context) string

BinaryNameFromContext returns the configured binary name from context. Returns CliBinaryName when settings are absent or BinaryName is empty.

func BuildCacheDirFor added in v0.7.0

func BuildCacheDirFor(binaryName string) string

BuildCacheDirFor returns the build cache directory for the given binary name. An empty binaryName defaults to CliBinaryName.

func DefaultBuildCacheDir added in v0.3.0

func DefaultBuildCacheDir() string

DefaultBuildCacheDir returns the default directory for build cache. Uses XDG Base Directory Specification:

  • Linux: ~/.cache/scafctl/build-cache/
  • macOS: ~/.cache/scafctl/build-cache/
  • Windows: %LOCALAPPDATA%\cache\scafctl\build-cache\

func DefaultHTTPCacheDir

func DefaultHTTPCacheDir() string

DefaultHTTPCacheDir returns the default directory for HTTP cache. Uses XDG Base Directory Specification:

  • Linux: ~/.cache/scafctl/http-cache/
  • macOS: ~/.cache/scafctl/http-cache/
  • Windows: %LOCALAPPDATA%\cache\scafctl\http-cache\

func DefaultPluginCacheDir added in v0.3.0

func DefaultPluginCacheDir() string

DefaultPluginCacheDir returns the default directory for cached plugin binaries. Uses XDG Base Directory Specification:

  • Linux: ~/.cache/scafctl/plugins/
  • macOS: ~/.cache/scafctl/plugins/
  • Windows: %LOCALAPPDATA%\cache\scafctl\plugins\

func FileNamesForMode added in v0.10.0

func FileNamesForMode(mode DiscoveryMode, binaryName string, customActionFiles []string) []string

FileNamesForMode returns the appropriate file name list based on mode and binary name. When customActionFiles is non-empty and mode is DiscoveryModeAction, those file names are used instead of the defaults (with solution and taskfile names appended as fallback).

func GetRootSolutionFolders added in v0.17.0

func GetRootSolutionFolders() []string

GetRootSolutionFolders returns the current solution folder search paths.

func GetSolutionFileNames added in v0.17.0

func GetSolutionFileNames() []string

GetSolutionFileNames returns the current solution file names.

func HTTPCacheDirFor added in v0.7.0

func HTTPCacheDirFor(binaryName string) string

HTTPCacheDirFor returns the HTTP cache directory for the given binary name. An empty binaryName defaults to CliBinaryName.

func HTTPCacheKeyPrefixFor added in v0.7.0

func HTTPCacheKeyPrefixFor(binaryName string) string

HTTPCacheKeyPrefixFor returns the HTTP cache key prefix for the given binary name.

func IntoContext

func IntoContext(ctx context.Context, s *Run) context.Context

IntoContext stores a Settings object in the context

func IsActionFile added in v0.10.0

func IsActionFile(name string) bool

IsActionFile returns true when the given filename is an action file (actions.yaml or actions.yml).

func IsTaskFile added in v0.17.0

func IsTaskFile(name string) bool

IsTaskFile returns true when the given filename is a task file (taskfile.yaml or taskfile.yml).

func MockedResolversFileFromContext added in v0.11.0

func MockedResolversFileFromContext(ctx context.Context) (string, bool)

MockedResolversFileFromContext returns the mocked resolvers file path from context, if set. Returns empty string and false when not present.

func PluginCacheDirFor added in v0.7.0

func PluginCacheDirFor(binaryName string) string

PluginCacheDirFor returns the plugin cache directory for the given binary name. An empty binaryName defaults to CliBinaryName.

func SafeEnvPrefix added in v0.7.0

func SafeEnvPrefix(binaryName string) string

SafeEnvPrefix returns an environment variable prefix derived from a binary name. It upper-cases the name and replaces non-alphanumeric characters with underscores.

func SanitizeBinaryName added in v0.7.0

func SanitizeBinaryName(raw string) string

SanitizeBinaryName normalizes a raw binary name into a safe identifier. It strips directory components and extensions, replaces unsafe characters with underscores, and falls back to CliBinaryName when the result is empty.

func SetSolutionDiscovery added in v0.17.0

func SetSolutionDiscovery(folders, fileNames []string)

SetSolutionDiscovery atomically updates both solution folder and file name lists.

func SolutionFileNamesFor added in v0.7.0

func SolutionFileNamesFor(binaryName string) []string

SolutionFileNamesFor returns the solution file names for the given binary name. Action file names (actions.yaml/yml) are intentionally excluded; they are only returned by ActionFileNamesFor for use with DiscoveryModeAction.

func SolutionFoldersFor added in v0.7.0

func SolutionFoldersFor(binaryName string) []string

SolutionFoldersFor returns the solution folder search paths for the given binary name.

func WithMockedResolversFile added in v0.11.0

func WithMockedResolversFile(ctx context.Context, path string) context.Context

WithMockedResolversFile stores the path to a mocked resolvers JSON file in the context. Used by the test runner to pass mock data to in-process command execution without relying on process-global environment variables.

Types

type DiscoveryMode added in v0.10.0

type DiscoveryMode int

DiscoveryMode controls which file names auto-discovery searches for.

const (
	// DiscoveryModeDefault searches solution and taskfile names (excludes action files).
	DiscoveryModeDefault DiscoveryMode = iota
	// DiscoveryModeAction searches action files first, then falls back to solution files.
	DiscoveryModeAction
	// DiscoveryModeSolution searches only solution files (excludes actions.yaml/yml).
	DiscoveryModeSolution
)

func (DiscoveryMode) String added in v0.10.0

func (m DiscoveryMode) String() string

String returns a human-readable label for the discovery mode.

type EntryPointSettings

type EntryPointSettings struct {
	FromAPI bool   `json:"fromAPI" yaml:"fromAPI" doc:"Whether the entry point is provided via API"`
	FromCli bool   `json:"fromCli" yaml:"fromCli" doc:"Whether the entry point is provided via CLI"`
	Path    string `json:"path,omitempty" yaml:"path,omitempty" doc:"Path to the entry point" maxLength:"512" example:"./solution.yaml"`
}

EntryPointSettings holds configuration options for determining the entry point source. It specifies whether the entry point is provided via an API or CLI, and the path to the entry point.

type Run

type Run struct {
	MinLogLevel        string             `json:"minLogLevel" yaml:"minLogLevel" doc:"Minimum log level" maxLength:"16" example:"info"`
	EntryPointSettings EntryPointSettings `json:"entryPointSettings" yaml:"entryPointSettings" doc:"Entry point configuration"`
	IsQuiet            bool               `json:"isQuiet" yaml:"isQuiet" doc:"Whether to suppress non-essential output"`
	NoColor            bool               `json:"noColor" yaml:"noColor" doc:"Whether to disable colored output"`
	Verbose            bool               `json:"verbose" yaml:"verbose" doc:"Whether to enable verbose output"`
	ExitOnError        bool               `json:"exitOnError" yaml:"exitOnError" doc:"Whether to exit on error"`
	BinaryName         string             `json:"binaryName" yaml:"binaryName" doc:"Runtime binary name for the CLI" maxLength:"64" example:"scafctl"`

	// EmbedderVersion is the version string of the embedding CLI/frontend, when
	// scafctl is used as a library. Empty when scafctl runs directly. It is used
	// to record invoking-CLI provenance (distinct from the engine version) in
	// state metadata.
	EmbedderVersion string `` /* 140-byte string literal not displayed */

	// ActionDiscoveryFileNames overrides the file names used by "run action"
	// auto-discovery. When empty, defaults from ActionFileNamesFor are used.
	ActionDiscoveryFileNames []string `json:"-" yaml:"-"`
}

Run holds configuration settings for a single execution of the application. It includes options for logging, entry point configuration, output formatting, and error handling behavior.

func FromContext

func FromContext(ctx context.Context) (*Run, bool)

FromContext retrieves a Settings object from the context

func NewCliParams

func NewCliParams() *Run

NewCliParams initializes and returns a pointer to a Run struct with default CLI parameters. It sets logging level to "none" (no structured logs by default), configures entry point settings for CLI usage, and sets default flags for quiet mode, color output, and error handling.

type RuntimeProvenance added in v0.34.0

type RuntimeProvenance struct {
	// EngineName is the execution engine name (typically CliBinaryName).
	EngineName string
	// EngineVersion is the engine build version.
	EngineVersion string
	// CLIName is the invoking CLI/frontend binary name. Empty mirrors EngineName.
	CLIName string
	// CLIVersion is the invoking CLI/frontend version. Empty mirrors EngineVersion.
	CLIVersion string
}

RuntimeProvenance is the primitive, dependency-free description of who performed a run: the execution engine (the scafctl library) and the invoking CLI/frontend. It is the single source of truth for provenance fallback semantics -- the state and resolver-snapshot packages adapt it into their own struct families rather than reimplementing the "default CLI to engine" logic.

When the CLI fields are empty they mirror the engine fields, which is the case for direct (non-embedded) scafctl use.

func RuntimeProvenanceFromContext added in v0.34.0

func RuntimeProvenanceFromContext(ctx context.Context, engineVersion string) RuntimeProvenance

RuntimeProvenanceFromContext builds provenance from the ambient CLI settings. The engine identity is always scafctl at its build version. The CLI identity is the configured binary name and (when embedded) the embedder version; otherwise it defaults to the engine via the Resolved* accessors.

engineVersion is passed explicitly so callers that already hold a build version string (e.g. snapshot capture) stay authoritative; when empty it falls back to VersionInformation.BuildVersion.

func (RuntimeProvenance) ResolvedCLIName added in v0.34.0

func (p RuntimeProvenance) ResolvedCLIName() string

ResolvedCLIName returns the effective CLI name, falling back to the engine name when no distinct invoker is set.

func (RuntimeProvenance) ResolvedCLIVersion added in v0.34.0

func (p RuntimeProvenance) ResolvedCLIVersion() string

ResolvedCLIVersion returns the effective CLI version, falling back to the engine version when no distinct invoker version is set.

type VersionInfo

type VersionInfo struct {
	Commit       string `json:"commit" yaml:"commit" doc:"Git commit hash" maxLength:"64" example:"abc1234"`
	BuildVersion string `json:"buildVersion" yaml:"buildVersion" doc:"Build version string" maxLength:"64" example:"v1.2.3"`
	BuildTime    string `json:"buildTime" yaml:"buildTime" doc:"Build timestamp" maxLength:"64" example:"2025-01-01T00:00:00Z"`
}

VersionInfo holds metadata about the build, including the commit hash, build version, and build timestamp.

Jump to

Keyboard shortcuts

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