runtime

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runtime

type Runtime struct {
	// ContextName is the current context name
	ContextName string

	// ProjectRoot is the project root directory path
	ProjectRoot string

	// ConfigRoot is the config root directory (<projectRoot>/contexts/<contextName>)
	ConfigRoot string

	// TemplateRoot is the template directory (<projectRoot>/contexts/_template)
	TemplateRoot string

	// WindsorScratchPath is the windsor scratch directory (<projectRoot>/.windsor/contexts/<contextName>)
	WindsorScratchPath string

	// Global indicates the runtime is operating in global mode, where no windsor.yaml
	// project was found and $HOME/.config/windsor is used as the effective project root.
	Global bool

	// Core dependencies
	ConfigHandler config.ConfigHandler
	Shell         shell.Shell
	Evaluator     evaluator.ExpressionEvaluator

	// Resolver dispatches secret references across configured providers
	Resolver *secretsRuntime.Resolver

	// EnvPrinters contains environment printers for various providers and tools
	EnvPrinters struct {
		DotEnvEnv    env.EnvPrinter
		AwsEnv       env.EnvPrinter
		AzureEnv     env.EnvPrinter
		GcpEnv       env.EnvPrinter
		VsphereEnv   env.EnvPrinter
		DockerEnv    env.EnvPrinter
		KubeEnv      env.EnvPrinter
		TalosEnv     env.EnvPrinter
		TerraformEnv env.EnvPrinter
		WindsorEnv   env.EnvPrinter
	}

	// ToolsManager manages tool installation and configuration
	ToolsManager tools.ToolsManager

	// TerraformProvider provides Terraform-specific operations
	TerraformProvider terraform.TerraformProvider
	// contains filtered or unexported fields
}

Runtime holds common execution values and core dependencies used across the Windsor CLI. These fields are set during various initialization steps rather than computed on-demand. Includes secret providers for Sops and 1Password, enabling access to secrets across all contexts. Also includes environment printers, tools manager, and environment variable/alias storage.

func NewRuntime

func NewRuntime(opts ...*Runtime) *Runtime

NewRuntime creates a new Runtime with ConfigHandler and Shell initialized if not already present. This is the base constructor that ensures core dependencies are available. If Shell is nil, it creates a new DefaultShell. If ConfigHandler is nil, it creates one using the Shell. The runtime also initializes envVars and aliases maps, and automatically sets up ContextName, ProjectRoot, ConfigRoot, and TemplateRoot based on the current project state. Optional overrides can be provided via opts to inject mocks for testing. Panics if Shell or ConfigHandler cannot be initialized.

func (*Runtime) ApplyConfigDefaults

func (rt *Runtime) ApplyConfigDefaults(flagOverrides ...map[string]any) error

ApplyConfigDefaults applies base configuration defaults if no config is currently loaded. It sets "dev" mode in config if the context is a dev context, chooses a default workstation runtime (optionally honoring flagOverrides["workstation.runtime"]), and sets platform to "docker" in dev mode if not already set, or "incus" when overrides or config specify incus. After those, it loads a default configuration set, choosing among standard, full, localhost, or none defaults depending on platform, dev mode, and workstation runtime. This must be called before loading from disk to ensure proper defaulting. Returns error on config operation failure.

func (*Runtime) CheckTools

func (rt *Runtime) CheckTools() error

CheckTools performs tool version checking using the tools manager against the full AllRequirements set. Equivalent to CheckToolsFor(tools.AllRequirements()) and exists for backward compatibility plus the explicit "verify everything" command (`windsor check`). New callers should declare per-command requirements via CheckToolsFor.

func (*Runtime) CheckToolsFor added in v0.9.0

func (rt *Runtime) CheckToolsFor(reqs tools.Requirements) error

CheckToolsFor verifies only the tool families the caller has opted into via reqs. Each check still respects the project's config gates (e.g. requesting Docker on a non-docker context is a no-op), so over-requesting is safe — it simply runs more no-op checks. The tools manager must be initialized before calling this method.

func (*Runtime) GenerateBuildID

func (rt *Runtime) GenerateBuildID() (string, error)

GenerateBuildID generates a new build ID and persists it to the .windsor/.build-id file, overwriting any existing value. Returns the new build ID or an error if generation or persistence fails.

func (*Runtime) GetAliases

func (rt *Runtime) GetAliases() map[string]string

GetAliases returns a copy of the collected aliases.

func (*Runtime) GetBuildID

func (rt *Runtime) GetBuildID() (string, error)

GetBuildID retrieves the current build ID from the .windsor/.build-id file. This is a read-only operation - it never creates a build ID. Returns the build ID string if it exists, or empty string if it doesn't exist. Returns an error only if file read fails (not if file doesn't exist).

func (*Runtime) GetEnvVars

func (rt *Runtime) GetEnvVars() map[string]string

GetEnvVars returns a copy of the collected environment variables.

func (*Runtime) HandleSessionReset

func (rt *Runtime) HandleSessionReset() error

HandleSessionReset checks for reset flags and session tokens, then resets managed environment variables if needed. It checks for WINDSOR_SESSION_TOKEN and uses the shell's CheckResetFlags method to determine if a reset should occur. A command like `windsor exec` that never establishes its own session token always has hasSessionToken false, so every invocation would otherwise be treated as a fresh reset; NO_CACHE only defaults to "true" when the caller hasn't already set it explicitly (to "true" or "false"), so an explicit `NO_CACHE=false windsor exec -- ...` — or a value already present in the calling shell — is honored instead of being force-overwritten on every reset. Returns an error if reset flag checking fails.

func (*Runtime) InitializeComponents added in v0.9.0

func (rt *Runtime) InitializeComponents() error

InitializeComponents initializes all environment-related components required after setup. Initializes TerraformProvider if terraform is enabled. Returns an error if initialization fails.

func (*Runtime) LoadEnvironment

func (rt *Runtime) LoadEnvironment(decrypt bool) error

LoadEnvironment loads environment variables and aliases from all configured environment printers, then executes post-environment hooks. It initializes all necessary components, optionally loads secrets if requested, and aggregates all environment variables and aliases into the Runtime instance. Returns an error if any step fails.

func (*Runtime) PrepareTools

func (rt *Runtime) PrepareTools() error

PrepareTools checks and installs every tool family. Equivalent to PrepareToolsFor with AllRequirements; preserved for backward compatibility. New callers should narrow their requirements via PrepareToolsFor so commands like `windsor init` don't trip checks they won't actually exercise.

func (*Runtime) PrepareToolsFor added in v0.9.0

func (rt *Runtime) PrepareToolsFor(reqs tools.Requirements) error

PrepareToolsFor checks the tool families requested via reqs and then installs any that are missing or outdated. Each check still respects the project's config gates so requesting more than a command actually needs is safe. The tools manager must be available.

func (*Runtime) ResolveConfig added in v0.9.0

func (rt *Runtime) ResolveConfig(flagOverrides map[string]any) error

ResolveConfig runs the full config pipeline: infer platform for dev when missing, apply pre-load defaults, load from disk, apply flag overrides, then apply dev-mode platform normalization (colima+incus). Call this once to produce final config. Mutates flagOverrides when inferring platform. Returns error on config load or set failure.

func (*Runtime) SaveConfig added in v0.9.0

func (rt *Runtime) SaveConfig(overwrite ...bool) error

SaveConfig migrates provider→platform and clears the deprecated provider key before persistence. Delegates persistence to the config handler. Workstation-managed keys are written to .windsor/contexts/<context>/workstation.yaml and excluded from values.yaml.

Directories

Path Synopsis
The VirtEnvPrinter is a specialized component that manages virtual machine and container runtime environment configuration.
The VirtEnvPrinter is a specialized component that manages virtual machine and container runtime environment configuration.
internal
awsprofile
Package awsprofile checks whether a named AWS profile is defined in either a context-scoped .aws/ directory or the operator's ambient AWS config.
Package awsprofile checks whether a named AWS profile is defined in either a context-scoped .aws/ directory or the operator's ambient AWS config.

Jump to

Keyboard shortcuts

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