template/interpolate: flip disable to enableenv
This commit is contained in:
parent
97a48e35bb
commit
47b570a2d2
|
@ -51,7 +51,7 @@ func Funcs(ctx *Context) template.FuncMap {
|
||||||
|
|
||||||
func funcGenEnv(ctx *Context) interface{} {
|
func funcGenEnv(ctx *Context) interface{} {
|
||||||
return func(k string) (string, error) {
|
return func(k string) (string, error) {
|
||||||
if ctx.DisableEnv {
|
if !ctx.EnableEnv {
|
||||||
// The error message doesn't have to be that detailed since
|
// The error message doesn't have to be that detailed since
|
||||||
// semantic checks should catch this.
|
// semantic checks should catch this.
|
||||||
return "", errors.New("env vars are not allowed here")
|
return "", errors.New("env vars are not allowed here")
|
||||||
|
|
|
@ -26,7 +26,7 @@ func TestFuncEnv(t *testing.T) {
|
||||||
os.Setenv("PACKER_TEST_ENV", "foo")
|
os.Setenv("PACKER_TEST_ENV", "foo")
|
||||||
defer os.Setenv("PACKER_TEST_ENV", "")
|
defer os.Setenv("PACKER_TEST_ENV", "")
|
||||||
|
|
||||||
ctx := &Context{}
|
ctx := &Context{EnableEnv: true}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
i := &I{Value: tc.Input}
|
i := &I{Value: tc.Input}
|
||||||
result, err := i.Render(ctx)
|
result, err := i.Render(ctx)
|
||||||
|
@ -53,7 +53,7 @@ func TestFuncEnv_disable(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := &Context{DisableEnv: true}
|
ctx := &Context{EnableEnv: false}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
i := &I{Value: tc.Input}
|
i := &I{Value: tc.Input}
|
||||||
result, err := i.Render(ctx)
|
result, err := i.Render(ctx)
|
||||||
|
|
|
@ -15,8 +15,8 @@ type Context struct {
|
||||||
// "user" function reads from.
|
// "user" function reads from.
|
||||||
UserVariables map[string]string
|
UserVariables map[string]string
|
||||||
|
|
||||||
// DisableEnv disables the env function
|
// EnableEnv enables the env function
|
||||||
DisableEnv bool
|
EnableEnv bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// I stands for "interpolation" and is the main interpolation struct
|
// I stands for "interpolation" and is the main interpolation struct
|
||||||
|
|
Loading…
Reference in New Issue