Documentation
¶
Overview ¶
Package env provides utilities for working with environment variables. It includes functions for converting, merging, updating, and managing environment variable slices used throughout atmos.
Package env provides utilities for working with environment variables.
Index ¶
- func ApplyGlobalEnvToSlice(envSlice []string, globalEnv map[string]string) []string
- func CommandEnvToMap(envs []schema.CommandEnv) map[string]string
- func ConvertEnvVars(envVarsMap map[string]any) []string
- func ConvertMapStringToAny(env map[string]string) map[string]any
- func ConvertMapToSlice(envMap map[string]string) []string
- func EnsureBinaryInPath(envSlice []string, binaryPath string) []string
- func EnvironToMap() map[string]string
- func EnvironToMapFiltered(excludeKeys []string, excludePrefixes []string) map[string]string
- func GetPathFromEnvironment(envSlice []string) string
- func MergeGlobalEnv(baseEnv []string, globalEnv map[string]string) []string
- func MergeSystemEnv(componentEnvList []string) []string
- func MergeSystemEnvSimple(newEnvList []string) []string
- func MergeSystemEnvSimpleWithGlobal(newEnvList []string, globalEnv map[string]string) []string
- func MergeSystemEnvWithGlobal(componentEnvList []string, globalEnv map[string]string) []string
- func PrependToPath(currentPath, newDir string) string
- func UpdateEnvVar(envSlice []string, key, value string) []string
- func UpdateEnvironmentPath(envSlice []string, newDir string) []string
- type Builder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyGlobalEnvToSlice ¶
ApplyGlobalEnvToSlice applies global env vars to an environment slice. For each key in globalEnv, if it doesn't exist in envSlice, it is added. If it exists, it is NOT overwritten (preserves higher-priority values). This is useful when global env needs to be applied as defaults.
func CommandEnvToMap ¶
func CommandEnvToMap(envs []schema.CommandEnv) map[string]string
CommandEnvToMap converts a slice of schema.CommandEnv to a map[string]string. Keys are taken from the Key field; later entries overwrite earlier ones on duplicate keys.
func ConvertEnvVars ¶
ConvertEnvVars converts ENV vars from a map to a list of strings in the format ["key1=val1", "key2=val2", "key3=val3" ...]. Variables with nil or "null" values are skipped.
func ConvertMapStringToAny ¶
ConvertMapStringToAny converts a map[string]string to map[string]any. Returns nil if the input map is nil.
func ConvertMapToSlice ¶
ConvertMapToSlice converts a map[string]string to []string{"KEY=value", ...}. The order of the resulting slice is not guaranteed due to map iteration.
func EnsureBinaryInPath ¶
EnsureBinaryInPath checks if a binary directory is in PATH and adds it if missing. Returns updated environment with the binary directory prepended to PATH.
func EnvironToMap ¶
EnvironToMap converts all the environment variables in the environment into a map of strings.
func EnvironToMapFiltered ¶
EnvironToMapFiltered converts environment variables to a map, excluding specified keys and prefixes. This is useful for terraform-exec which prohibits certain environment variables.
func GetPathFromEnvironment ¶
GetPathFromEnvironment extracts the PATH value from an environment slice.
func MergeGlobalEnv ¶
MergeGlobalEnv merges atmos.yaml global env into an environment slice. Global env has lowest priority and is appended (can be overridden by command-specific env). The baseEnv slice typically comes from os.Environ().
func MergeSystemEnv ¶
MergeSystemEnv merges system environment variables with component-specific env. Priority order: system env < component env. Special handling is applied for TF_CLI_ARGS_* variables where new values are prepended to existing values.
func MergeSystemEnvSimple ¶
MergeSystemEnvSimple merges system environment variables with new env without TF_CLI_ARGS_* special handling. Priority order: system env < new env list.
func MergeSystemEnvSimpleWithGlobal ¶
MergeSystemEnvSimpleWithGlobal merges system environment variables with global env from atmos.yaml and new env without TF_CLI_ARGS_* special handling. Priority order: system env < global env < new env list.
func MergeSystemEnvWithGlobal ¶
MergeSystemEnvWithGlobal merges system environment variables with global env from atmos.yaml and component-specific env. Priority order: system env < global env < component env. Special handling is applied for TF_CLI_ARGS_* variables where new values are prepended to existing values.
func PrependToPath ¶
PrependToPath adds a directory to the beginning of the PATH environment variable. Returns the new PATH value.
func UpdateEnvVar ¶
UpdateEnvVar updates or adds an environment variable in an environment slice. Returns a new environment slice with the variable updated.
func UpdateEnvironmentPath ¶
UpdateEnvironmentPath updates the PATH in an environment slice. Returns a new environment slice with the updated PATH.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides a fluent API for constructing environment variable slices.
func NewBuilder ¶
NewBuilder creates a new Builder with an optional initial environment slice. If no initial slice is provided, starts with an empty slice.
func (*Builder) WithEnvMap ¶
WithEnvMap adds all environment variables from a map.
func (*Builder) WithEnvVar ¶
WithEnvVar adds an environment variable with the given key and value.