settings

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 8 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
)

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 (
	// 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 (
	// 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
)

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 (
	RootSolutionFolders = SolutionFoldersFor(CliBinaryName)
	SolutionFileNames   = SolutionFileNamesFor(CliBinaryName)
)
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 files appended as fallback).

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 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 SolutionFileNamesFor added in v0.7.0

func SolutionFileNamesFor(binaryName string) []string

SolutionFileNamesFor returns the solution file names for the given binary name.

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 SolutionOnlyFileNamesFor added in v0.10.0

func SolutionOnlyFileNamesFor(binaryName string) []string

SolutionOnlyFileNamesFor returns file names excluding actions.yaml/yml.

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 all known file names (current behavior).
	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"`

	// 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 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