This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
/
step_env.go
62 lines (48 loc) · 1.76 KB
/
step_env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package pipeline
import "github.com/grafana/scribe/state"
type EnvVarType int
const (
// EnvVarString should be used whenever the value is known and static.
EnvVarString EnvVarType = iota
// EnvVarArgument means that the environment variable will be populated by an argument from the state at run-time.
// Most (all?) CI services will then leave these values out of the configuration and will be injected when the step runs.
EnvVarArgument
)
type EnvVar struct {
Type EnvVarType
// argument will be populated if this EnvVar is created using the NewEnvArgument function.
argument state.Argument
// str will be populated if this EnvVar is created using the NewEnvString function.
str string
}
type StepEnv map[string]EnvVar
// NewEnvArgument creates a new EnvVar that will be populated based on an Argument found in the state when the step runs.
func NewEnvArgument(arg state.Argument) EnvVar {
return EnvVar{
Type: EnvVarArgument,
argument: arg,
}
}
// NewEnvString creates a new EnvVar that will be populated with a static string value.
func NewEnvString(val string) EnvVar {
return EnvVar{
Type: EnvVarArgument,
str: val,
}
}
// String retrieves the static string value set when using the NewEnvString function.
// If the EnvVar's Type property is not "EnvVarString" then it will panic.
func (e EnvVar) String() string {
if e.Type != EnvVarString {
panic("envvar is not a string type, but String() was called")
}
return e.str
}
// Argument retrieves the argument value set when using the NewEnvArgument function.
// If the EnvVar's Type property is not "EnvVarString" then it will panic.
func (e EnvVar) Argument() state.Argument {
if e.Type != EnvVarArgument {
panic("envvar is not an argument type, but Argument() was called")
}
return e.argument
}