Skip to content

Commit

Permalink
add sha1 interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
jkordish committed Dec 27, 2015
1 parent 4b6cda9 commit 5a999db
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions config/interpolate_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package config

import (
"bytes"
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -38,6 +40,7 @@ func init() {
"lower": interpolationFuncLower(),
"replace": interpolationFuncReplace(),
"split": interpolationFuncSplit(),
"sha1": interpolationFuncSha1(),
"base64encode": interpolationFuncBase64Encode(),
"base64decode": interpolationFuncBase64Decode(),
"upper": interpolationFuncUpper(),
Expand Down Expand Up @@ -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
},
}
}

0 comments on commit 5a999db

Please sign in to comment.