env

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type AwsEnvPrinter

type AwsEnvPrinter struct {
	BaseEnvPrinter
}

AwsEnvPrinter is a struct that simulates an AWS environment for testing purposes.

func NewAwsEnvPrinter

func NewAwsEnvPrinter(injector di.Injector) *AwsEnvPrinter

NewAwsEnvPrinter initializes a new awsEnv instance using the provided dependency injector.

func (*AwsEnvPrinter) GetEnvVars

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

GetEnvVars retrieves the environment variables for the AWS environment.

func (*AwsEnvPrinter) Print

func (e *AwsEnvPrinter) Print() error

Print prints the environment variables for the AWS environment.

type BaseEnvPrinter

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

Env is a struct that implements the EnvPrinter interface.

func NewBaseEnvPrinter

func NewBaseEnvPrinter(injector di.Injector) *BaseEnvPrinter

NewBaseEnvPrinter creates a new BaseEnvPrinter instance.

func (*BaseEnvPrinter) GetAlias added in v0.3.0

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

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

GetManagedAlias returns the shell aliases that are managed by Windsor.

func (*BaseEnvPrinter) GetManagedEnv added in v0.5.6

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

GetManagedEnv returns the environment variables that are managed by Windsor.

func (*BaseEnvPrinter) Initialize

func (e *BaseEnvPrinter) Initialize() error

Initialize resolves and assigns the shell and configHandler from the injector.

func (*BaseEnvPrinter) PostEnvHook

func (e *BaseEnvPrinter) PostEnvHook() error

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

func (*BaseEnvPrinter) Print

func (e *BaseEnvPrinter) Print(customVars ...map[string]string) error

Print outputs the environment variables to the console. If a map of key:value strings is provided, it prints those instead.

func (*BaseEnvPrinter) PrintAlias added in v0.5.6

func (e *BaseEnvPrinter) PrintAlias(customAlias ...map[string]string) error

PrintAlias retrieves and prints the shell alias. If a map of key:value strings is provided, it prints those instead.

func (*BaseEnvPrinter) Reset added in v0.5.6

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

func (e *BaseEnvPrinter) SetManagedAlias(alias string)

SetManagedAlias sets the shell aliases that are managed by Windsor.

func (*BaseEnvPrinter) SetManagedEnv added in v0.5.6

func (e *BaseEnvPrinter) SetManagedEnv(env string)

SetManagedEnv sets the environment variables that are managed by Windsor.

type DockerEnvPrinter

type DockerEnvPrinter struct {
	BaseEnvPrinter
}

DockerEnvPrinter is a struct that simulates a Docker environment for testing purposes.

func NewDockerEnvPrinter

func NewDockerEnvPrinter(injector di.Injector) *DockerEnvPrinter

NewDockerEnvPrinter initializes a new dockerEnv instance using the provided dependency injector.

func (*DockerEnvPrinter) GetAlias added in v0.3.0

func (e *DockerEnvPrinter) 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 (*DockerEnvPrinter) GetEnvVars

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

GetEnvVars sets Docker-specific env vars, using DOCKER_HOST from vm.driver config or existing env. Defaults to WINDSORCONFIG or home dir for Docker paths, ensuring config directory exists. Writes config if content changes, adds DOCKER_CONFIG and REGISTRY_URL, and returns the map. Handles "colima", "docker-desktop", and "docker" vm.driver settings, defaulting to "default" if unrecognized.

func (*DockerEnvPrinter) Print

func (e *DockerEnvPrinter) Print() error

Print retrieves and prints the environment variables for the Docker environment.

type EnvPrinter

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

EnvPrinter defines the method for printing environment variables.

type KubeEnvPrinter

type KubeEnvPrinter struct {
	BaseEnvPrinter
}

KubeEnvPrinter is a struct that simulates a Kubernetes environment for testing purposes.

func NewKubeEnvPrinter

func NewKubeEnvPrinter(injector di.Injector) *KubeEnvPrinter

NewKubeEnv initializes a new kubeEnv instance using the provided dependency injector.

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.

func (*KubeEnvPrinter) Print

func (e *KubeEnvPrinter) Print() error

Print prints the environment variables for the Kube environment.

type MockEnvPrinter

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

MockEnvPrinter is a struct that simulates an environment for testing purposes.

func NewMockEnvPrinter

func NewMockEnvPrinter() *MockEnvPrinter

NewMockEnvPrinter creates a new instance of MockEnvPrinter.

func (*MockEnvPrinter) GetAlias added in v0.5.6

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) Initialize

func (m *MockEnvPrinter) Initialize() error

Initialize calls the custom InitializeFunc if provided.

func (*MockEnvPrinter) PostEnvHook

func (m *MockEnvPrinter) PostEnvHook() 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 added in v0.5.6

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

func (m *MockEnvPrinter) Reset()

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

type OmniEnvPrinter

type OmniEnvPrinter struct {
	BaseEnvPrinter
}

OmniEnvPrinter is a struct that simulates a Kubernetes environment for testing purposes.

func NewOmniEnvPrinter

func NewOmniEnvPrinter(injector di.Injector) *OmniEnvPrinter

NewOmniEnv initializes a new omniEnv instance using the provided dependency injector.

func (*OmniEnvPrinter) GetEnvVars

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

GetEnvVars retrieves the environment variables for the Omni environment.

func (*OmniEnvPrinter) Print

func (e *OmniEnvPrinter) Print() error

Print prints the environment variables for the Omni environment.

type TalosEnvPrinter

type TalosEnvPrinter struct {
	BaseEnvPrinter
}

TalosEnvPrinter is a struct that simulates a Kubernetes environment for testing purposes.

func NewTalosEnvPrinter

func NewTalosEnvPrinter(injector di.Injector) *TalosEnvPrinter

NewTalosEnvPrinter initializes a new talosEnvPrinter instance using the provided dependency injector.

func (*TalosEnvPrinter) GetEnvVars

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

GetEnvVars retrieves the environment variables for the Talos environment.

func (*TalosEnvPrinter) Print

func (e *TalosEnvPrinter) Print() error

Print prints the environment variables for the Talos environment.

type TerraformEnvPrinter

type TerraformEnvPrinter struct {
	BaseEnvPrinter
}

TerraformEnvPrinter simulates a Terraform environment for testing purposes.

func NewTerraformEnvPrinter

func NewTerraformEnvPrinter(injector di.Injector) *TerraformEnvPrinter

NewTerraformEnvPrinter initializes a new TerraformEnvPrinter instance.

func (*TerraformEnvPrinter) GetEnvVars

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

GetEnvVars retrieves environment variables for Terraform. It determines the config root and project path, checks for tfvars files, and sets variables based on the OS. If not in a terraform project folder, it resets all TF_ vars that are already set in the environment. Returns a map of environment variables or an error if any step fails.

func (*TerraformEnvPrinter) PostEnvHook

func (e *TerraformEnvPrinter) PostEnvHook() error

PostEnvHook executes operations after setting the environment variables.

func (*TerraformEnvPrinter) Print

func (e *TerraformEnvPrinter) Print() error

Print outputs the environment variables for the Terraform environment.

type WindsorEnvPrinter

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

WindsorEnvPrinter is a struct that simulates a Kubernetes environment for testing purposes.

func NewWindsorEnvPrinter

func NewWindsorEnvPrinter(injector di.Injector) *WindsorEnvPrinter

NewWindsorEnvPrinter initializes a new WindsorEnvPrinter instance using the provided dependency injector.

func (*WindsorEnvPrinter) GetEnvVars

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

GetEnvVars constructs a map of Windsor-specific environment variables. It includes the current context, project root, and session token. Custom environment variables are also added, with secrets resolved using configured providers. Managed aliases and environment variables are appended to ensure a complete environment setup. This method ensures that all Windsor-prefixed variables and managed environment variables are included in the final environment setup, providing a comprehensive configuration.

func (*WindsorEnvPrinter) Initialize added in v0.5.6

func (e *WindsorEnvPrinter) Initialize() error

Initialize sets up the WindsorEnvPrinter, including resolving secrets providers.

func (*WindsorEnvPrinter) Print

func (e *WindsorEnvPrinter) Print() error

Print prints the environment variables for the Windsor environment.

Jump to

Keyboard shortcuts

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