diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go b/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go index f1f97b0..7b7b3f2 100644 --- a/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go +++ b/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go | |||
@@ -24,6 +24,7 @@ import ( | |||
24 | "github.com/hashicorp/hil" | 24 | "github.com/hashicorp/hil" |
25 | "github.com/hashicorp/hil/ast" | 25 | "github.com/hashicorp/hil/ast" |
26 | "github.com/mitchellh/go-homedir" | 26 | "github.com/mitchellh/go-homedir" |
27 | "golang.org/x/crypto/bcrypt" | ||
27 | ) | 28 | ) |
28 | 29 | ||
29 | // stringSliceToVariableValue converts a string slice into the value | 30 | // stringSliceToVariableValue converts a string slice into the value |
@@ -59,6 +60,7 @@ func Funcs() map[string]ast.Function { | |||
59 | "base64encode": interpolationFuncBase64Encode(), | 60 | "base64encode": interpolationFuncBase64Encode(), |
60 | "base64sha256": interpolationFuncBase64Sha256(), | 61 | "base64sha256": interpolationFuncBase64Sha256(), |
61 | "base64sha512": interpolationFuncBase64Sha512(), | 62 | "base64sha512": interpolationFuncBase64Sha512(), |
63 | "bcrypt": interpolationFuncBcrypt(), | ||
62 | "ceil": interpolationFuncCeil(), | 64 | "ceil": interpolationFuncCeil(), |
63 | "chomp": interpolationFuncChomp(), | 65 | "chomp": interpolationFuncChomp(), |
64 | "cidrhost": interpolationFuncCidrHost(), | 66 | "cidrhost": interpolationFuncCidrHost(), |
@@ -89,6 +91,7 @@ func Funcs() map[string]ast.Function { | |||
89 | "merge": interpolationFuncMerge(), | 91 | "merge": interpolationFuncMerge(), |
90 | "min": interpolationFuncMin(), | 92 | "min": interpolationFuncMin(), |
91 | "pathexpand": interpolationFuncPathExpand(), | 93 | "pathexpand": interpolationFuncPathExpand(), |
94 | "pow": interpolationFuncPow(), | ||
92 | "uuid": interpolationFuncUUID(), | 95 | "uuid": interpolationFuncUUID(), |
93 | "replace": interpolationFuncReplace(), | 96 | "replace": interpolationFuncReplace(), |
94 | "sha1": interpolationFuncSha1(), | 97 | "sha1": interpolationFuncSha1(), |
@@ -394,6 +397,17 @@ func interpolationFuncConcat() ast.Function { | |||
394 | } | 397 | } |
395 | } | 398 | } |
396 | 399 | ||
400 | // interpolationFuncPow returns base x exponential of y. | ||
401 | func interpolationFuncPow() ast.Function { | ||
402 | return ast.Function{ | ||
403 | ArgTypes: []ast.Type{ast.TypeFloat, ast.TypeFloat}, | ||
404 | ReturnType: ast.TypeFloat, | ||
405 | Callback: func(args []interface{}) (interface{}, error) { | ||
406 | return math.Pow(args[0].(float64), args[1].(float64)), nil | ||
407 | }, | ||
408 | } | ||
409 | } | ||
410 | |||
397 | // interpolationFuncFile implements the "file" function that allows | 411 | // interpolationFuncFile implements the "file" function that allows |
398 | // loading contents from a file. | 412 | // loading contents from a file. |
399 | func interpolationFuncFile() ast.Function { | 413 | func interpolationFuncFile() ast.Function { |
@@ -1310,6 +1324,40 @@ func interpolationFuncBase64Sha512() ast.Function { | |||
1310 | } | 1324 | } |
1311 | } | 1325 | } |
1312 | 1326 | ||
1327 | func interpolationFuncBcrypt() ast.Function { | ||
1328 | return ast.Function{ | ||
1329 | ArgTypes: []ast.Type{ast.TypeString}, | ||
1330 | Variadic: true, | ||
1331 | VariadicType: ast.TypeString, | ||
1332 | ReturnType: ast.TypeString, | ||
1333 | Callback: func(args []interface{}) (interface{}, error) { | ||
1334 | defaultCost := 10 | ||
1335 | |||
1336 | if len(args) > 1 { | ||
1337 | costStr := args[1].(string) | ||
1338 | cost, err := strconv.Atoi(costStr) | ||
1339 | if err != nil { | ||
1340 | return "", err | ||
1341 | } | ||
1342 | |||
1343 | defaultCost = cost | ||
1344 | } | ||
1345 | |||
1346 | if len(args) > 2 { | ||
1347 | return "", fmt.Errorf("bcrypt() takes no more than two arguments") | ||
1348 | } | ||
1349 | |||
1350 | input := args[0].(string) | ||
1351 | out, err := bcrypt.GenerateFromPassword([]byte(input), defaultCost) | ||
1352 | if err != nil { | ||
1353 | return "", fmt.Errorf("error occured generating password %s", err.Error()) | ||
1354 | } | ||
1355 | |||
1356 | return string(out), nil | ||
1357 | }, | ||
1358 | } | ||
1359 | } | ||
1360 | |||
1313 | func interpolationFuncUUID() ast.Function { | 1361 | func interpolationFuncUUID() ast.Function { |
1314 | return ast.Function{ | 1362 | return ast.Function{ |
1315 | ArgTypes: []ast.Type{}, | 1363 | ArgTypes: []ast.Type{}, |