env

package
v1.202.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyGlobalEnvToSlice

func ApplyGlobalEnvToSlice(envSlice []string, globalEnv map[string]string) []string

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

func ConvertEnvVars(envVarsMap map[string]any) []string

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

func ConvertMapStringToAny(env map[string]string) map[string]any

ConvertMapStringToAny converts a map[string]string to map[string]any. Returns nil if the input map is nil.

func ConvertMapToSlice

func ConvertMapToSlice(envMap map[string]string) []string

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

func EnsureBinaryInPath(envSlice []string, binaryPath string) []string

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

func EnvironToMap() map[string]string

EnvironToMap converts all the environment variables in the environment into a map of strings.

func EnvironToMapFiltered

func EnvironToMapFiltered(excludeKeys []string, excludePrefixes []string) map[string]string

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

func GetPathFromEnvironment(envSlice []string) string

GetPathFromEnvironment extracts the PATH value from an environment slice.

func MergeGlobalEnv

func MergeGlobalEnv(baseEnv []string, globalEnv map[string]string) []string

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

func MergeSystemEnv(componentEnvList []string) []string

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

func MergeSystemEnvSimple(newEnvList []string) []string

MergeSystemEnvSimple merges system environment variables with new env without TF_CLI_ARGS_* special handling. Priority order: system env < new env list.

func MergeSystemEnvSimpleWithGlobal

func MergeSystemEnvSimpleWithGlobal(newEnvList []string, globalEnv map[string]string) []string

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

func MergeSystemEnvWithGlobal(componentEnvList []string, globalEnv map[string]string) []string

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

func PrependToPath(currentPath, newDir string) string

PrependToPath adds a directory to the beginning of the PATH environment variable. Returns the new PATH value.

func UpdateEnvVar

func UpdateEnvVar(envSlice []string, key, value string) []string

UpdateEnvVar updates or adds an environment variable in an environment slice. Returns a new environment slice with the variable updated.

func UpdateEnvironmentPath

func UpdateEnvironmentPath(envSlice []string, newDir string) []string

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

func NewBuilder(initial ...[]string) *Builder

NewBuilder creates a new Builder with an optional initial environment slice. If no initial slice is provided, starts with an empty slice.

func (*Builder) Build

func (b *Builder) Build() []string

Build returns the constructed environment slice.

func (*Builder) WithEnv

func (b *Builder) WithEnv(keyValue string) *Builder

WithEnv adds an environment variable in KEY=value format.

func (*Builder) WithEnvMap

func (b *Builder) WithEnvMap(envMap map[string]string) *Builder

WithEnvMap adds all environment variables from a map.

func (*Builder) WithEnvVar

func (b *Builder) WithEnvVar(key, value string) *Builder

WithEnvVar adds an environment variable with the given key and value.

func (*Builder) WithEnvVarf

func (b *Builder) WithEnvVarf(key, format string, args ...any) *Builder

WithEnvVarf adds an environment variable using a format string for the value.

Jump to

Keyboard shortcuts

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