runtime

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MPL-2.0 Imports: 16 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

	// Core dependencies
	ConfigHandler config.ConfigHandler
	Shell         shell.Shell

	// SecretsProviders contains providers for Sops and 1Password secrets management
	SecretsProviders struct {
		Sops        secretsRuntime.SecretsProvider
		Onepassword []secretsRuntime.SecretsProvider
	}

	// EnvPrinters contains environment printers for various providers and tools
	EnvPrinters struct {
		AwsEnv       env.EnvPrinter
		AzureEnv     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
	// 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, error)

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. Returns the Runtime with initialized dependencies or an error if initialization fails.

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 VM driver (optionally honoring a value from flagOverrides), and sets provider to "generic" in dev mode if not already set. After those, it loads a default configuration set, choosing among standard, full, localhost, or none defaults depending on provider, dev mode, and vm.driver. This must be called before loading from disk to ensure proper defaulting. Returns error on config operation failure.

func (*Runtime) ApplyProviderDefaults

func (rt *Runtime) ApplyProviderDefaults(providerOverride string) error

ApplyProviderDefaults sets provider-specific configuration values based on the provider type. For "aws", it enables AWS and sets the cluster driver to "eks". For "azure", it enables Azure and sets the cluster driver to "aks". For "generic", it sets the cluster driver to "talos". If no provider is set but dev mode is enabled, it defaults the cluster driver to "talos". The context name is read from rt.ContextName. Returns an error if any configuration operation fails.

func (*Runtime) CheckTools

func (rt *Runtime) CheckTools() error

CheckTools performs tool version checking using the tools manager. It validates that all required tools are installed and meet minimum version requirements. The tools manager must be initialized before calling this method. Returns an error if the tools manager is not available or if tool checking fails.

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. If no build ID exists, a new one is generated, persisted, and returned. Returns the build ID string or an error if retrieval or persistence fails.

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. If reset is needed, it calls Shell.Reset() and sets NO_CACHE=true. Returns an error if Shell is not initialized or if reset flag checking 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 required dependency is missing or if any step fails. This method expects the ConfigHandler to be set before invocation.

func (*Runtime) PrepareTools

func (rt *Runtime) PrepareTools() error

PrepareTools checks and installs required tools using the tools manager. It first checks that all required tools are installed and meet version requirements, then installs any missing or outdated tools. The tools manager must be available. Returns an error if the tools manager is not available or if checking or installation fails.

Directories

Path Synopsis
ssh

Jump to

Keyboard shortcuts

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