Skip to content

Commit

Permalink
Add "env" template func to get env var value
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Dementiev committed Jan 28, 2020
1 parent 2c72255 commit faa2c43
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ssm/transformations/template_funcs.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package transformations

import (
"fmt"
"net/url"
"os"
"strings"
"text/template"
)

var funcMap = template.FuncMap{
"env": GetEnv,
"url_host": URLHost,
"url_password": URLPassword,
"url_path": URLPath,
Expand All @@ -16,6 +19,15 @@ var funcMap = template.FuncMap{
"replace": strings.Replace,
}

// GetEnv gets the environment variable
func GetEnv(input string) (string, error) {
val, ok := os.LookupEnv(input)
if !ok {
return "", fmt.Errorf("can't find %s in the environment variables", input)
}
return val, nil
}

// URLUser extracts user from the URL or returns "" if it's not set
func URLUser(input string) (string, error) {
u, err := url.Parse(input)
Expand Down

0 comments on commit faa2c43

Please sign in to comment.