Merge #4704: sha256 interpolation function
This commit is contained in:
commit
e8006f1539
|
@ -18,6 +18,7 @@ FEATURES:
|
|||
|
||||
IMPROVEMENTS:
|
||||
|
||||
* core: Add `sha256()` interpolation function [GH-4704]
|
||||
* provider/aws: Add new parameters `az_mode` and `availability_zone(s)` in ElastiCache [GH-4631]
|
||||
* provider/aws: Allow ap-northeast-2 (Seoul) as valid region [GH-4637]
|
||||
* provider/aws: Limit SNS Topic Subscription protocols [GH-4639]
|
||||
|
|
|
@ -3,6 +3,7 @@ package config
|
|||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
|
@ -39,6 +40,7 @@ func Funcs() map[string]ast.Function {
|
|||
"replace": interpolationFuncReplace(),
|
||||
"split": interpolationFuncSplit(),
|
||||
"sha1": interpolationFuncSha1(),
|
||||
"sha256": interpolationFuncSha256(),
|
||||
"base64encode": interpolationFuncBase64Encode(),
|
||||
"base64decode": interpolationFuncBase64Decode(),
|
||||
"upper": interpolationFuncUpper(),
|
||||
|
@ -601,3 +603,17 @@ func interpolationFuncSha1() ast.Function {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
func interpolationFuncSha256() ast.Function {
|
||||
return ast.Function{
|
||||
ArgTypes: []ast.Type{ast.TypeString},
|
||||
ReturnType: ast.TypeString,
|
||||
Callback: func(args []interface{}) (interface{}, error) {
|
||||
s := args[0].(string)
|
||||
h := sha256.New()
|
||||
h.Write([]byte(s))
|
||||
hash := hex.EncodeToString(h.Sum(nil))
|
||||
return hash, nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -846,6 +846,18 @@ func TestInterpolateFuncSha1(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestInterpolateFuncSha256(t *testing.T) {
|
||||
testFunction(t, testFunctionConfig{
|
||||
Cases: []testFunctionCase{
|
||||
{
|
||||
`${sha256("test")}`,
|
||||
"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
|
||||
false,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type testFunctionConfig struct {
|
||||
Cases []testFunctionCase
|
||||
Vars map[string]ast.Variable
|
||||
|
|
|
@ -80,10 +80,14 @@ The supported built-in functions are:
|
|||
* `base64encode(string)` - Returns a base64-encoded representation of the
|
||||
given string.
|
||||
|
||||
* `sha1(string)` - Returns a sha1 hash representation of the
|
||||
* `sha1(string)` - Returns a SHA-1 hash representation of the
|
||||
given string.
|
||||
Example: `"${sha1(concat(aws_vpc.default.tags.customer, "-s3-bucket"))}"`
|
||||
|
||||
* `sha256(string)` - Returns a SHA-256 hash representation of the
|
||||
given string.
|
||||
Example: `"${sha256(concat(aws_vpc.default.tags.customer, "-s3-bucket"))}"`
|
||||
|
||||
* `cidrhost(iprange, hostnum)` - Takes an IP address range in CIDR notation
|
||||
and creates an IP address with the given host number. For example,
|
||||
``cidrhost("10.0.0.0/8", 2)`` returns ``10.0.0.2``.
|
||||
|
|
Loading…
Reference in New Issue