env

package
v3.116.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

A small library for creating typed, consistent and documented environmental variable accesses.

Declaring a variable is as simple as declaring a module level constant.

var Var = env.Bool("VAR", "A boolean variable")

Typed values can be retrieved by calling `Var.Value()`.

Index

Constants

View Source
const Prefix = "PULUMI_"

The default prefix for a environmental variable.

Variables

This section is empty.

Functions

func NoPrefix

func NoPrefix(opts *options)

NoPrefix indicates that a variable should not have the default prefix applied.

func Secret added in v3.77.0

func Secret(opts *options)

Secret indicates that the value should not be displayed in plaintext.

Types

type BoolValue

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

A boolean retrieved from the environment.

func Bool

func Bool(name, description string, opts ...Option) BoolValue

Declare a new environmental value of type bool.

`name` is the runtime name of the variable. Unless `NoPrefix` is passed, name is pre-appended with `Prefix`. For example, a variable named "FOO" would be set by declaring "PULUMI_FOO=1" in the enclosing environment.

`description` is the string description of what the variable does.

func (BoolValue) String

func (v BoolValue) String() string

func (BoolValue) Type

func (BoolValue) Type() string

func (BoolValue) Underlying

func (v BoolValue) Underlying() (string, bool)

func (BoolValue) Validate

func (b BoolValue) Validate() ValidateError

func (BoolValue) Value

func (b BoolValue) Value() bool

The boolean value of the variable.

If the variable is unset, false is returned.

func (BoolValue) Var

func (v BoolValue) Var() Var

type Env

type Env interface {
	GetString(val StringValue) string
	GetBool(val BoolValue) bool
	GetInt(val IntValue) int
}

A strongly typed environment.

func NewEnv

func NewEnv(store Store) Env

Create a new strongly typed Env from an untyped Store.

type IntValue

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

An integer retrieved from the environment.

func Int

func Int(name, description string, opts ...Option) IntValue

Declare a new environmental value of type integer.

`name` is the runtime name of the variable. Unless `NoPrefix` is passed, name is pre-appended with `Prefix`. For example, a variable named "FOO" would be set by declaring "PULUMI_FOO=1" in the enclosing environment.

`description` is the string description of what the variable does.

func (IntValue) String

func (v IntValue) String() string

func (IntValue) Type

func (IntValue) Type() string

func (IntValue) Underlying

func (v IntValue) Underlying() (string, bool)

func (IntValue) Validate

func (i IntValue) Validate() ValidateError

func (IntValue) Value

func (i IntValue) Value() int

The integer value of the variable.

If the variable is unset or not parsable, 0 is returned.

func (IntValue) Var

func (v IntValue) Var() Var

type MapStore

type MapStore map[string]string

func (MapStore) Raw

func (m MapStore) Raw(key string) (string, bool)

type Option

type Option func(*options)

An Option to configure a environmental variable.

func Alternative added in v3.104.0

func Alternative(name string) Option

Alternative indicates that the variable has an alternative name. This is generally used for backwards compatibility.

func Needs

func Needs(val BoolValue) Option

Needs indicates that a variable can only be set if `val` is truthy.

type Store

type Store interface {
	// Retrieve a raw value from the Store. If the value is not present, "", false should
	// be returned.
	Raw(key string) (string, bool)
}

Store holds a collection of key, value? pairs.

Store acts like the environment that values are drawn from.

var Global Store = envStore{}

The global store of values that Value.Value() uses.

Setting this value is not thread safe, and should be restricted to testing.

type StringValue

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

A string retrieved from the environment.

func String

func String(name, description string, opts ...Option) StringValue

Declare a new environmental value.

`name` is the runtime name of the variable. Unless `NoPrefix` is passed, name is pre-appended with `Prefix`. For example, a variable named "FOO" would be set by declaring "PULUMI_FOO=val" in the enclosing environment.

`description` is the string description of what the variable does.

func (StringValue) String

func (v StringValue) String() string

func (StringValue) Type

func (StringValue) Type() string

func (StringValue) Underlying

func (v StringValue) Underlying() (string, bool)

func (StringValue) Validate

func (StringValue) Validate() ValidateError

func (StringValue) Value

func (s StringValue) Value() string

The string value of the variable.

If the variable is unset, "" is returned.

func (StringValue) Var

func (v StringValue) Var() Var

type ValidateError

type ValidateError struct {
	Warning error
	Error   error
}

type Value

type Value interface {
	fmt.Stringer

	// Retrieve the underlying string value associated with the variable.
	//
	// If the variable was not set, ("", false) is returned.
	Underlying() (string, bool)
	// Retrieve the Var associated with this value.
	Var() Var

	Validate() ValidateError
	// contains filtered or unexported methods
}

The value of a environmental variable.

In general, `Value`s should only be used in collections. For specific values, used the typed version (StringValue, BoolValue).

Every implementer of Value also includes a `Value() T` method that returns a typed representation of the value.

type Var

type Var struct {
	Value       Value
	Description string
	// contains filtered or unexported fields
}

An environmental variable.

func Variables

func Variables() []Var

Variables is a list of variables declared.

func (Var) Alternative added in v3.104.0

func (v Var) Alternative() string

The alternative name of an environmental variable.

func (Var) Name

func (v Var) Name() string

The name of an environmental variable.

Name accounts for prefix if appropriate.

func (Var) Requires

func (v Var) Requires() []BoolValue

The list of variables that a must be truthy for `v` to be set.

Jump to

Keyboard shortcuts

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