From 5a999db4da8b30bd325890960b7be3021ce2f693 Mon Sep 17 00:00:00 2001 From: Joseph Kordish Date: Sun, 27 Dec 2015 16:29:20 -0600 Subject: [PATCH] add sha1 interpolation --- config/interpolate_funcs.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config/interpolate_funcs.go b/config/interpolate_funcs.go index 5538763c0ced..0ca16b56cd6a 100644 --- a/config/interpolate_funcs.go +++ b/config/interpolate_funcs.go @@ -2,7 +2,9 @@ package config import ( "bytes" + "crypto/sha1" "encoding/base64" + "encoding/hex" "errors" "fmt" "io/ioutil" @@ -38,6 +40,7 @@ func init() { "lower": interpolationFuncLower(), "replace": interpolationFuncReplace(), "split": interpolationFuncSplit(), + "sha1": interpolationFuncSha1(), "base64encode": interpolationFuncBase64Encode(), "base64decode": interpolationFuncBase64Decode(), "upper": interpolationFuncUpper(), @@ -586,3 +589,17 @@ func interpolationFuncUpper() ast.Function { }, } } + +func interpolationFuncSha1() ast.Function { + return ast.Function{ + ArgTypes: []ast.Type{ast.TypeString}, + ReturnType: ast.TypeString, + Callback: func(args []interface{}) (interface{}, error) { + s := args[0].(string) + h := sha1.New() + h.Write([]byte(s)) + hash := hex.EncodeToString(h.Sum(nil)) + return hash, nil + }, + } +}