From 1a4c6e83abbc407f291af8701c616cc9c1d92f03 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 19 Jan 2024 16:42:52 -0800 Subject: [PATCH] Add `sha256sum` template function This is intentionally named and implemented to match the one in Sprig: https://masterminds.github.io/sprig/crypto.html --- pkg/templatelib/lib.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/templatelib/lib.go b/pkg/templatelib/lib.go index 9e87531e..1ebedcd3 100644 --- a/pkg/templatelib/lib.go +++ b/pkg/templatelib/lib.go @@ -1,6 +1,8 @@ package templatelib import ( + "crypto/sha256" + "encoding/hex" "encoding/json" "fmt" "os" @@ -135,4 +137,10 @@ var FuncMap = template.FuncMap{ return unsetVal } }), + + // {{- sha256sum "hello world" -}} + "sha256sum": func(input string) string { + hash := sha256.Sum256([]byte(input)) + return hex.EncodeToString(hash[:]) + }, }