Function for locally generating ETag

This commit is contained in:
Daniel Hougaard
2024-08-27 19:36:02 +04:00
parent 03cc71cfed
commit fe11b8e57e
+14
View File
@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"encoding/hex"
"fmt" "fmt"
"math/rand" "math/rand"
"os" "os"
@@ -298,3 +299,16 @@ func GenerateRandomString(length int) string {
} }
return string(b) return string(b)
} }
func GenerateETagFromSecrets(secrets []models.SingleEnvironmentVariable) string {
sortedSecrets := SortSecretsByKeys(secrets)
content := []byte{}
for _, secret := range sortedSecrets {
content = append(content, []byte(secret.Key)...)
content = append(content, []byte(secret.Value)...)
}
hash := sha256.Sum256(content)
return fmt.Sprintf(`"%s"`, hex.EncodeToString(hash[:]))
}