environment

package
v1.52.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package environment defines object describing the current environment.

Index

Constants

This section is empty.

Variables

View Source
var (

	// IsEnvironmentVariableKey defines a validation rule for environment variable keys ([IEEE Std 1003.1-2008 / IEEE POSIX P1003.2/ISO 9945.2](http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02)) for use with github.com/go-ozzo/ozzo-validation
	// TODO use the built-in implementation in `is` package when https://github.com/go-ozzo/ozzo-validation/issues/186 is looked at.
	IsEnvironmentVariableKey = validation.NewStringRuleWithError(isEnvVarKey, errEnvvarInvalid)
)

Functions

func ValidateEnvironmentVariables

func ValidateEnvironmentVariables(vars ...IEnvironmentVariable) error

ValidateEnvironmentVariables validates that environment variables are correctly defined in regard to their schema.

Types

type EnvVar

type EnvVar struct {
	// contains filtered or unexported fields
}

func (*EnvVar) Equal

func (e *EnvVar) Equal(v IEnvironmentVariable) bool

func (*EnvVar) GetKey

func (e *EnvVar) GetKey() string

func (*EnvVar) GetValue

func (e *EnvVar) GetValue() string

func (*EnvVar) MarshalText

func (e *EnvVar) MarshalText() (text []byte, err error)

func (*EnvVar) String

func (e *EnvVar) String() string

func (*EnvVar) UnmarshalText

func (e *EnvVar) UnmarshalText(text []byte) error

func (*EnvVar) Validate

func (e *EnvVar) Validate() (err error)

type IEnvironment

type IEnvironment interface {
	// GetCurrentUser returns the environment current user.
	GetCurrentUser() *user.User
	// GetEnvironmentVariables returns the variables defining the environment  (and optionally those supplied in `dotEnvFiles`)
	// `dotEnvFiles` corresponds to `.env` files present on the machine and follows the mechanism described by https://github.com/bkeepers/dotenv
	GetEnvironmentVariables(dotEnvFiles ...string) []IEnvironmentVariable
	// GetExpandedEnvironmentVariables  is similar to GetEnvironmentVariables but returns variables with fully expanded values.
	// e.g. on Linux, if variable1=${variable2}, then the reported value of variable1 will be the value of variable2
	GetExpandedEnvironmentVariables(dotEnvFiles ...string) []IEnvironmentVariable
	// GetFilesystem returns the filesystem associated with the current environment
	GetFilesystem() filesystem.FS
	// GetEnvironmentVariable returns the environment variable corresponding to `envvar` or an error if it not set. optionally it searches `dotEnvFiles` files too
	// `dotEnvFiles` corresponds to `.env` files present on the machine and follows the mechanism described by https://github.com/bkeepers/dotenv
	GetEnvironmentVariable(envvar string, dotEnvFiles ...string) (IEnvironmentVariable, error)
	// GetExpandedEnvironmentVariable is similar to GetEnvironmentVariable but returns variables with fully expanded values.
	//	// e.g. on Linux, if variable1=${variable2}, then the reported value of variable1 will be the value of variable2
	GetExpandedEnvironmentVariable(envvar string, dotEnvFiles ...string) (IEnvironmentVariable, error)
}

IEnvironment defines an environment for an application to run on.

func NewCurrentEnvironment

func NewCurrentEnvironment() IEnvironment

NewCurrentEnvironment returns system current environment.

type IEnvironmentVariable

type IEnvironmentVariable interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
	fmt.Stringer
	// GetKey returns the variable key.
	GetKey() string
	// GetValue returns the variable value.
	GetValue() string
	// Validate checks whether the variable value is correctly defined
	Validate() error
	// Equal states whether two environment variables are equal or not.
	Equal(v IEnvironmentVariable) bool
}

IEnvironmentVariable defines an environment variable to be set for the commands to run.

func CloneEnvironementVariable added in v1.52.0

func CloneEnvironementVariable(envVar IEnvironmentVariable) IEnvironmentVariable

CloneEnvironementVariable returns a clone of the environment variable.

func ExpandEnvironmentVariable added in v1.52.0

func ExpandEnvironmentVariable(recursive bool, envVarToExpand IEnvironmentVariable, envvars ...IEnvironmentVariable) (expandedEnvVar IEnvironmentVariable)

ExpandEnvironmentVariable returns a clone of envVarToExpand but with an expanded value based on environment variables defined in envvars list. Expansion assumes that all the variables are present in the envvars list. If recursive is set to true, then expansion is performed recursively over the variable list.

func ExpandEnvironmentVariables added in v1.52.0

func ExpandEnvironmentVariables(recursive bool, envvars ...IEnvironmentVariable) (expandedEnvVars []IEnvironmentVariable)

ExpandEnvironmentVariables returns a list of environment variables with their value being expanded. Expansion assumes that all the variables are present in the envvars list. If recursive is set to true, then expansion is performed recursively over the variable list.

func FindEnvironmentVariable added in v1.49.0

func FindEnvironmentVariable(envvar string, envvars ...IEnvironmentVariable) (IEnvironmentVariable, error)

FindEnvironmentVariable looks for an environment variable in a list. if no environment variable matches, an error is returned

func NewEnvironmentVariable

func NewEnvironmentVariable(key, value string) IEnvironmentVariable

NewEnvironmentVariable returns an environment variable defined by a key and a value.

func NewEnvironmentVariableWithValidation

func NewEnvironmentVariableWithValidation(key, value string, rules ...validation.Rule) IEnvironmentVariable

NewEnvironmentVariableWithValidation returns an environment variable defined by a key and a value but with the possibility to define value validation rules.

func ParseEnvironmentVariable

func ParseEnvironmentVariable(variable string) (IEnvironmentVariable, error)

ParseEnvironmentVariable parses an environment variable definition, in the form "key=value".

func ParseEnvironmentVariables added in v1.49.0

func ParseEnvironmentVariables(variables ...string) (envVars []IEnvironmentVariable)

ParseEnvironmentVariables parses a list of key=value entries such as os.Environ() and returns a list of the corresponding environment variables. Any entry failing parsing will be ignored.

Jump to

Keyboard shortcuts

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