env

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: 31 Imported by: 0

Documentation

Overview

The VirtEnvPrinter is a specialized component that manages virtual machine and container runtime environment configuration. It provides environment variable management for Docker and Incus runtimes, handling Docker host, context, registry configuration, and Incus socket paths. The VirtEnvPrinter ensures proper CLI integration and environment setup for container operations across different virtualization backends.

Index

Constants

This section is empty.

Variables

View Source
var WindsorPrefixedVars = []string{
	"WINDSOR_CONTEXT",
	"WINDSOR_CONTEXT_ID",
	"BUILD_ID",
	"WINDSOR_PROJECT_ROOT",
	"WINDSOR_SESSION_TOKEN",
	"WINDSOR_MANAGED_ENV",
	"WINDSOR_MANAGED_ALIAS",
}

WindsorPrefixedVars are the environment variables that are managed by Windsor.

Functions

This section is empty.

Types

type AwsEnvPrinter

type AwsEnvPrinter struct {
	BaseEnvPrinter
}

AwsEnvPrinter is a struct that implements AWS environment configuration

func NewAwsEnvPrinter

func NewAwsEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler) *AwsEnvPrinter

NewAwsEnvPrinter creates a new AwsEnvPrinter instance

func (*AwsEnvPrinter) GetEnvVars

func (e *AwsEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars returns the AWS env vars for the current context. In project mode AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE always point at the context's .aws/ so `aws configure` stays scoped to the context. AWS_PROFILE is emitted only when the named profile is actually defined in the relevant AWS config: the context's .aws/ in project mode, or the operator's ambient ~/.aws/ (or AWS_CONFIG_FILE override) in global mode. When the profile is absent the var is omitted so the AWS SDK falls through to env keys, IMDS, ECS task creds, or whatever else the credential chain finds rather than failing with "profile not found" against a file the named profile was never in.

type AzureEnvPrinter

type AzureEnvPrinter struct {
	BaseEnvPrinter
}

AzureEnvPrinter is a struct that implements Azure environment configuration

func NewAzureEnvPrinter

func NewAzureEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler) *AzureEnvPrinter

NewAzureEnvPrinter creates a new AzureEnvPrinter instance

func (*AzureEnvPrinter) GetEnvVars

func (e *AzureEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars retrieves the environment variables for the Azure environment. In project mode AZURE_CONFIG_DIR always points at the context's .azure dir, matching how the AWS env printer scopes AWS_CONFIG_FILE — keeps `az login` from contaminating the operator's global ~/.azure. In global mode it is not emitted; ARM_SUBSCRIPTION_ID / ARM_TENANT_ID / ARM_ENVIRONMENT, TF_VAR_region (when set), and TF_VAR_kubelogin_mode are emitted in both modes — the ARM_* vars describe the target account/tenant and the TF_VAR_* vars feed terraform, which runs from global shells too. TF_VAR_region is omitted when azure.region is unset so consuming modules fall back to their own variable defaults rather than receiving an empty string.

type BaseEnvPrinter

type BaseEnvPrinter struct {
	EnvPrinter
	// contains filtered or unexported fields
}

BaseEnvPrinter is a base implementation of the EnvPrinter interface

func NewBaseEnvPrinter

func NewBaseEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler) *BaseEnvPrinter

NewBaseEnvPrinter creates a new BaseEnvPrinter instance

func (*BaseEnvPrinter) GetAlias

func (e *BaseEnvPrinter) GetAlias() (map[string]string, error)

GetAlias is a placeholder for creating an alias for a command.

func (*BaseEnvPrinter) GetEnvVars

func (e *BaseEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars is a placeholder for retrieving environment variables.

func (*BaseEnvPrinter) GetManagedAlias

func (e *BaseEnvPrinter) GetManagedAlias() []string

GetManagedAlias returns the shell aliases that are managed by Windsor.

func (*BaseEnvPrinter) GetManagedEnv

func (e *BaseEnvPrinter) GetManagedEnv() []string

GetManagedEnv returns the environment variables that are managed by Windsor.

func (*BaseEnvPrinter) PostEnvHook

func (e *BaseEnvPrinter) PostEnvHook(directory ...string) error

PostEnvHook simulates running any necessary commands after the environment variables have been set.

func (*BaseEnvPrinter) Reset

func (e *BaseEnvPrinter) Reset()

Reset removes all managed environment variables and aliases. It delegates to the shell's Reset method to handle the reset logic.

func (*BaseEnvPrinter) SetManagedAlias

func (e *BaseEnvPrinter) SetManagedAlias(alias string)

SetManagedAlias sets the shell aliases that are managed by Windsor.

func (*BaseEnvPrinter) SetManagedEnv

func (e *BaseEnvPrinter) SetManagedEnv(env string)

SetManagedEnv sets the environment variables that are managed by Windsor.

type DotEnvEnvPrinter added in v0.9.0

type DotEnvEnvPrinter struct {
	BaseEnvPrinter
	// contains filtered or unexported fields
}

DotEnvEnvPrinter is a struct that implements per-context .env environment configuration

func NewDotEnvEnvPrinter added in v0.9.0

func NewDotEnvEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler, eval evaluator.ExpressionEvaluator) *DotEnvEnvPrinter

NewDotEnvEnvPrinter creates a new DotEnvEnvPrinter instance

func (*DotEnvEnvPrinter) GetEnvVars added in v0.9.0

func (e *DotEnvEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars loads contexts/<context>/.env, evaluating secret(...) expressions and registering every value with the shell for output scrubbing. A key already cached in the shell is omitted rather than re-evaluated. Returns an empty map when the file is absent, and warns (without failing) when the file has group- or world-readable permissions.

type EnvPrinter

type EnvPrinter interface {
	GetEnvVars() (map[string]string, error)
	GetAlias() (map[string]string, error)
	PostEnvHook(directory ...string) error
	GetManagedEnv() []string
	GetManagedAlias() []string
	SetManagedEnv(env string)
	SetManagedAlias(alias string)
	Reset()
}

EnvPrinter defines the method for printing environment variables. Secret-scrubbing contract: only values resolved through the evaluator's secret() expression are scrub-protected (the resolver in pkg/runtime/secrets calls shell.RegisterSecret automatically at resolve time). A printer setting literal credential material directly, not via secret(), must call shell.RegisterSecret itself; none of the provider printers do today, since none currently emit raw credentials — only identifiers, paths, and config, with the actual secret left to secrets.

type GcpEnvPrinter added in v0.9.0

type GcpEnvPrinter struct {
	BaseEnvPrinter
}

GcpEnvPrinter is a struct that implements GCP environment configuration

func NewGcpEnvPrinter added in v0.9.0

func NewGcpEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler) *GcpEnvPrinter

NewGcpEnvPrinter creates a new GcpEnvPrinter instance

func (*GcpEnvPrinter) GetEnvVars added in v0.9.0

func (e *GcpEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars retrieves the environment variables for the GCP environment. In global mode (no windsor.yaml in the project tree) windsor defers to the operator's ambient gcloud setup: CLOUDSDK_CONFIG is not emitted, the context-scoped gcloud directory is not created, and GOOGLE_APPLICATION_CREDENTIALS is only emitted when gcp.credentials_path is set explicitly. The project identifiers (GOOGLE_CLOUD_PROJECT, GCLOUD_PROJECT, GOOGLE_CLOUD_QUOTA_PROJECT) are still emitted because they describe which GCP project the context targets, not whose credentials are used.

type KubeEnvPrinter

type KubeEnvPrinter struct {
	BaseEnvPrinter
}

KubeEnvPrinter is a struct that implements Kubernetes environment configuration

func NewKubeEnvPrinter

func NewKubeEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler) *KubeEnvPrinter

NewKubeEnvPrinter creates a new KubeEnvPrinter instance

func (*KubeEnvPrinter) GetEnvVars

func (e *KubeEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars constructs a map of Kubernetes environment variables by setting KUBECONFIG and KUBE_CONFIG_PATH based on the configuration root directory. It checks for a project-specific volume directory and returns current variables if it doesn't exist. If it does, it ensures each PVC directory has a corresponding "PV_" environment variable, returning the map if all are accounted for. If not all volumes are accounted for, it attempts to query the Kubernetes API to create environment variables for matching PVCs. If the API is unavailable, it gracefully degrades by returning the basic environment variables without failing.

type MockEnvPrinter

type MockEnvPrinter struct {
	BaseEnvPrinter
	PrintFunc           func() error
	PrintAliasFunc      func() error
	PostEnvHookFunc     func(directory ...string) error
	GetEnvVarsFunc      func() (map[string]string, error)
	GetAliasFunc        func() (map[string]string, error)
	GetManagedEnvFunc   func() []string
	GetManagedAliasFunc func() []string
	ResetFunc           func()
}

MockEnvPrinter is a struct that implements mock environment configuration

func NewMockEnvPrinter

func NewMockEnvPrinter() *MockEnvPrinter

NewMockEnvPrinter creates a new MockEnvPrinter instance

func (*MockEnvPrinter) GetAlias

func (m *MockEnvPrinter) GetAlias() (map[string]string, error)

GetAlias simulates retrieving the shell alias. If a custom GetAliasFunc is provided, it will use that function instead.

func (*MockEnvPrinter) GetEnvVars

func (m *MockEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars simulates retrieving environment variables. If a custom GetEnvVarsFunc is provided, it will use that function instead.

func (*MockEnvPrinter) GetManagedAlias

func (m *MockEnvPrinter) GetManagedAlias() []string

GetManagedAlias returns the managed aliases. If a custom GetManagedAliasFunc is provided, it will use that function instead.

func (*MockEnvPrinter) GetManagedEnv

func (m *MockEnvPrinter) GetManagedEnv() []string

GetManagedEnv returns the managed environment variables. If a custom GetManagedEnvFunc is provided, it will use that function instead.

func (*MockEnvPrinter) PostEnvHook

func (m *MockEnvPrinter) PostEnvHook(directory ...string) error

PostEnvHook simulates running any necessary commands after the environment variables have been set. If a custom PostEnvHookFunc is provided, it will use that function instead.

func (*MockEnvPrinter) Print

func (m *MockEnvPrinter) Print() error

Print simulates printing the provided environment variables. If a custom PrintFunc is provided, it will use that function instead.

func (*MockEnvPrinter) PrintAlias

func (m *MockEnvPrinter) PrintAlias() error

PrintAlias simulates printing the shell aliases. If a custom PrintAliasFunc is provided, it will use that function instead.

func (*MockEnvPrinter) Reset

func (m *MockEnvPrinter) Reset()

Reset simulates resetting environment variables. If a custom ResetFunc is provided, it will use that function instead.

type Shims

type Shims struct {
	Stat           func(string) (os.FileInfo, error)
	Getwd          func() (string, error)
	Glob           func(string) ([]string, error)
	WriteFile      func(string, []byte, os.FileMode) error
	ReadDir        func(string) ([]os.DirEntry, error)
	YamlUnmarshal  func([]byte, any) error
	YamlMarshal    func(any) ([]byte, error)
	JsonUnmarshal  func([]byte, any) error
	JsonMarshal    func(any) ([]byte, error)
	Remove         func(string) error
	RemoveAll      func(string) error
	CryptoRandRead func([]byte) (int, error)
	Goos           func() string
	UserHomeDir    func() (string, error)
	MkdirAll       func(string, os.FileMode) error
	ReadFile       func(string) ([]byte, error)
	LookPath       func(string) (string, error)
	LookupEnv      func(string) (string, bool)
	Environ        func() []string
	Getenv         func(string) string
}

Shims provides mockable wrappers around system and runtime functions

func NewShims

func NewShims() *Shims

NewShims creates a new Shims instance with default implementations

type TalosEnvPrinter

type TalosEnvPrinter struct {
	BaseEnvPrinter
}

TalosEnvPrinter manages Talos environment configuration, providing Talos-specific environment variable management and configuration for CLI integration and environment setup.

func NewTalosEnvPrinter

func NewTalosEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler) *TalosEnvPrinter

NewTalosEnvPrinter creates and returns a new TalosEnvPrinter instance.

func (*TalosEnvPrinter) GetEnvVars

func (e *TalosEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars returns a map of environment variables for the Talos and Omni environments. It sets TALOSCONFIG only when cluster.driver is "talos" and sets OMNICONFIG only when platform is "omni". Returns an error if the configuration root cannot be determined.

type TerraformArgs

type TerraformArgs = terraform.TerraformArgs

TerraformArgs is an alias for terraform.TerraformArgs to maintain backward compatibility

type TerraformEnvPrinter

type TerraformEnvPrinter struct {
	BaseEnvPrinter
	// contains filtered or unexported fields
}

TerraformEnvPrinter is a struct that implements Terraform environment configuration

func NewTerraformEnvPrinter

func NewTerraformEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler, toolsManager tools.ToolsManager, terraformProvider terraform.TerraformProvider) *TerraformEnvPrinter

NewTerraformEnvPrinter creates a new TerraformEnvPrinter instance

func (*TerraformEnvPrinter) GetEnvVars

func (e *TerraformEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars returns a map of environment variables for Terraform operations. If not in a Terraform project directory, it unsets managed variables present in the environment. Otherwise, it generates Terraform arguments for the current project, merged with any contexts/<context>/terraform/.env content. Every returned key is tracked as managed so it is unset cleanly when the operator leaves the directory; the terraform/.env key names are additionally recorded in WINDSOR_MANAGED_TERRAFORM_ENV so getEmptyEnvVars can still unset them later even if the file's contents change or the file is removed in the meantime. Returns the environment variable map or an error if resolution fails.

func (*TerraformEnvPrinter) PostEnvHook

func (e *TerraformEnvPrinter) PostEnvHook(directory ...string) error

PostEnvHook executes operations after setting the environment variables.

type VirtEnvPrinter added in v0.9.0

type VirtEnvPrinter struct {
	BaseEnvPrinter
}

VirtEnvPrinter is a struct that implements virtual machine and container runtime environment configuration

func NewVirtEnvPrinter added in v0.9.0

func NewVirtEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler) *VirtEnvPrinter

NewVirtEnvPrinter creates a new VirtEnvPrinter instance

func (*VirtEnvPrinter) GetAlias added in v0.9.0

func (e *VirtEnvPrinter) GetAlias() (map[string]string, error)

GetAlias creates an alias for a command and returns it in a map. In this case, it looks for docker-cli-plugin-docker-compose and creates an alias for docker-compose.

func (*VirtEnvPrinter) GetEnvVars added in v0.9.0

func (e *VirtEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars sets environment variables for virtual machine and container runtimes. When workstation.runtime is configured, it writes a Docker config file and sets DOCKER_CONFIG. DOCKER_HOST is set from the runtime when it does not yet exist or was previously managed by Windsor (present in WINDSOR_MANAGED_ENV); if DOCKER_HOST was set by the user it is left untouched. Handles "colima", "docker-desktop", and "docker" workstation runtimes. Also sets REGISTRY_URL from docker registry config, and INCUS_SOCKET for colima-incus setups.

type VsphereEnvPrinter added in v0.9.0

type VsphereEnvPrinter struct {
	BaseEnvPrinter
}

VsphereEnvPrinter is a struct that implements vSphere environment configuration

func NewVsphereEnvPrinter added in v0.9.0

func NewVsphereEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler) *VsphereEnvPrinter

NewVsphereEnvPrinter creates a new VsphereEnvPrinter instance

func (*VsphereEnvPrinter) GetEnvVars added in v0.9.0

func (e *VsphereEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars retrieves the environment variables for the vSphere environment. In project mode, VSPHERE_PERSIST_SESSION, VSPHERE_VIM_SESSION_PATH, and VSPHERE_REST_SESSION_PATH are always emitted, scoping the Terraform vSphere provider's SOAP/REST session cache to the context's .vsphere/ directory — mirrors how AZURE_CONFIG_DIR scopes az CLI state for the Azure env printer. In global mode these three are omitted so the provider falls back to its own ambient defaults (~/.govmomi/sessions, ~/.govmomi/rest_sessions) untouched. The remaining three env vars consumed by the provider are emitted from config: VSPHERE_SERVER, VSPHERE_USER, and VSPHERE_ALLOW_UNVERIFIED_SSL. Inventory pointers (datacenter, cluster, datastore, network, etc.) are Terraform variable inputs wired by the facet — they are not read from the environment. VSPHERE_PASSWORD must be supplied via secrets or the ambient environment; plaintext passwords are never written to the shell config file.

type WindsorEnvPrinter

type WindsorEnvPrinter struct {
	BaseEnvPrinter
	// contains filtered or unexported fields
}

WindsorEnvPrinter is a struct that implements Windsor environment configuration

func NewWindsorEnvPrinter

func NewWindsorEnvPrinter(shell shell.Shell, configHandler config.ConfigHandler, eval evaluator.ExpressionEvaluator, allEnvPrinters []EnvPrinter) *WindsorEnvPrinter

NewWindsorEnvPrinter creates a new WindsorEnvPrinter instance

func (*WindsorEnvPrinter) GetEnvVars

func (e *WindsorEnvPrinter) GetEnvVars() (map[string]string, error)

GetEnvVars constructs a map of Windsor-specific environment variables by retrieving the current context, project root, and session token. It resolves secrets in custom environment variables using configured providers, handles caching of values, and manages environment variables and aliases. For secrets, it leverages the secrets cache to avoid unnecessary decryption while ensuring variables are properly tracked in the managed environment list. Windsor-prefixed variables are automatically included in the final environment setup to provide a comprehensive configuration.

Jump to

Keyboard shortcuts

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