mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
add sha1 interpolation
This commit is contained in:
parent
88c3933356
commit
e1b62c76ad
@ -2,7 +2,9 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/sha1"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -38,6 +40,7 @@ func init() {
|
|||||||
"lower": interpolationFuncLower(),
|
"lower": interpolationFuncLower(),
|
||||||
"replace": interpolationFuncReplace(),
|
"replace": interpolationFuncReplace(),
|
||||||
"split": interpolationFuncSplit(),
|
"split": interpolationFuncSplit(),
|
||||||
|
"sha1": interpolationFuncSha1(),
|
||||||
"base64encode": interpolationFuncBase64Encode(),
|
"base64encode": interpolationFuncBase64Encode(),
|
||||||
"base64decode": interpolationFuncBase64Decode(),
|
"base64decode": interpolationFuncBase64Decode(),
|
||||||
"upper": interpolationFuncUpper(),
|
"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
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -834,6 +834,18 @@ func TestInterpolateFuncUpper(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInterpolateFuncSha1(t *testing.T) {
|
||||||
|
testFunction(t, testFunctionConfig{
|
||||||
|
Cases: []testFunctionCase{
|
||||||
|
{
|
||||||
|
`${sha1("test")}`,
|
||||||
|
"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type testFunctionConfig struct {
|
type testFunctionConfig struct {
|
||||||
Cases []testFunctionCase
|
Cases []testFunctionCase
|
||||||
Vars map[string]ast.Variable
|
Vars map[string]ast.Variable
|
||||||
|
Loading…
Reference in New Issue
Block a user