Skip to content

Commit 90fc317

Browse files
template: add sha256 function
Signed-off-by: Alexander Yastrebov <[email protected]>
1 parent ebc2a81 commit 90fc317

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

provisioner/template.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,15 @@ func renderSingleTemplate(manifest channel.Manifest, cluster *api.Cluster, nodeP
9999
// returns the transformed template or an error if not successful
100100
func renderTemplate(context *templateContext, file string) (string, error) {
101101
funcMap := template.FuncMap{
102-
"getAWSAccountID": getAWSAccountID,
103-
"base64": base64Encode,
104-
"base64Decode": base64Decode,
105-
"manifestHash": func(template string) (string, error) { return manifestHash(context, file, template) },
102+
"getAWSAccountID": getAWSAccountID,
103+
"base64": base64Encode,
104+
"base64Decode": base64Decode,
105+
"manifestHash": func(template string) (string, error) {
106+
return manifestHash(context, file, template)
107+
},
108+
"sha256": func(value string) (string, error) {
109+
return fmt.Sprintf("%x", sha256.Sum256([]byte(value))), nil
110+
},
106111
"asgSize": asgSize,
107112
"azID": azID,
108113
"azCount": azCount,

provisioner/template_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ func TestManifestHashRecursiveInclude(t *testing.T) {
104104
require.Error(t, err)
105105
}
106106

107+
func TestSha256(t *testing.T) {
108+
result, err := renderSingle(
109+
t,
110+
`{{ printf "%.32s" (.Values.data | sha256) }}`,
111+
"hello")
112+
113+
require.NoError(t, err)
114+
require.EqualValues(t, "2cf24dba5fb0a30e26e83b2ac5b9e29e", result)
115+
}
116+
107117
func TestASGSize(t *testing.T) {
108118
result, err := renderSingle(
109119
t,

0 commit comments

Comments
 (0)