diff options
Diffstat (limited to 'internal/templates/funcs.go')
| -rw-r--r-- | internal/templates/funcs.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/internal/templates/funcs.go b/internal/templates/funcs.go index 5f7db217e..fe44a8e0c 100644 --- a/internal/templates/funcs.go +++ b/internal/templates/funcs.go @@ -17,6 +17,7 @@ import ( "sort" "strconv" "strings" + "syscall" "time" "github.com/google/uuid" @@ -29,6 +30,7 @@ func FuncMap() map[string]any { "fileContent": FuncFileContent, "secret": FuncSecret, "env": FuncGetEnv, + "mustEnv": FuncMustGetEnv, "expandenv": FuncExpandEnv, "split": FuncStringSplit, "splitList": FuncStringSplitList, @@ -134,7 +136,24 @@ func FuncGetEnv(key string) string { return "" } - return os.Getenv(key) + value, _ := syscall.Getenv(key) + + return value +} + +// FuncMustGetEnv is a special version of os.GetEnv that excludes secret keys and returns an error if it doesn't exist. +func FuncMustGetEnv(key string) (string, error) { + if isSecretEnvKey(key) { + return "", nil + } + + value, found := syscall.Getenv(key) + + if !found { + return "", fmt.Errorf("environment variable '%s' isn't set", key) + } + + return value, nil } // FuncHashSum is a helper function that provides similar functionality to helm sum funcs. |
