Remove UUID

This commit is contained in:
binwiederhier
2025-07-19 15:44:49 +02:00
parent ae62e0d955
commit 57df16dd62
7 changed files with 4 additions and 50 deletions

View File

@@ -1248,7 +1248,6 @@ Below are the functions that are available to use inside your message/title temp
* [Path and Filepath Functions](publish/template-functions.md#path-and-filepath-functions): `base`, `dir`, `ext`, `clean`, `isAbs`, `osBase`, `osDir`, `osExt`, `osClean`, `osIsAbs` * [Path and Filepath Functions](publish/template-functions.md#path-and-filepath-functions): `base`, `dir`, `ext`, `clean`, `isAbs`, `osBase`, `osDir`, `osExt`, `osClean`, `osIsAbs`
* [Flow Control Functions](publish/template-functions.md#flow-control-functions): `fail` * [Flow Control Functions](publish/template-functions.md#flow-control-functions): `fail`
* Advanced Functions * Advanced Functions
* [UUID Functions](publish/template-functions.md#uuid-functions): `uuidv4`
* [Reflection](publish/template-functions.md#reflection-functions): `typeOf`, `kindIs`, `typeIsLike`, etc. * [Reflection](publish/template-functions.md#reflection-functions): `typeOf`, `kindIs`, `typeIsLike`, etc.
* [Cryptographic and Security Functions](publish/template-functions.md#cryptographic-and-security-functions): `sha256sum`, etc. * [Cryptographic and Security Functions](publish/template-functions.md#cryptographic-and-security-functions): `sha256sum`, etc.
* [URL](publish/template-functions.md#url-functions): `urlParse`, `urlJoin` * [URL](publish/template-functions.md#url-functions): `urlParse`, `urlJoin`

View File

@@ -18,7 +18,6 @@ The original set of template functions is based on the [Sprig library](https://m
- [Type Conversion Functions](#type-conversion-functions) - [Type Conversion Functions](#type-conversion-functions)
- [Path and Filepath Functions](#path-and-filepath-functions) - [Path and Filepath Functions](#path-and-filepath-functions)
- [Flow Control Functions](#flow-control-functions) - [Flow Control Functions](#flow-control-functions)
- [UUID Functions](#uuid-functions)
- [Reflection Functions](#reflection-functions) - [Reflection Functions](#reflection-functions)
- [Cryptographic and Security Functions](#cryptographic-and-security-functions) - [Cryptographic and Security Functions](#cryptographic-and-security-functions)
- [URL Functions](#url-functions) - [URL Functions](#url-functions)
@@ -1357,16 +1356,6 @@ template rendering should fail.
fail "Please accept the end user license agreement" fail "Please accept the end user license agreement"
``` ```
## UUID Functions
Sprig can generate UUID v4 universally unique IDs.
```
uuidv4
```
The above returns a new UUID of the v4 (randomly generated) type.
## Reflection Functions ## Reflection Functions
Sprig provides rudimentary reflection tools. These help advanced template Sprig provides rudimentary reflection tools. These help advanced template

2
go.mod
View File

@@ -32,7 +32,6 @@ require github.com/pkg/errors v0.9.1 // indirect
require ( require (
firebase.google.com/go/v4 v4.16.1 firebase.google.com/go/v4 v4.16.1
github.com/SherClockHolmes/webpush-go v1.4.0 github.com/SherClockHolmes/webpush-go v1.4.0
github.com/google/uuid v1.6.0
github.com/microcosm-cc/bluemonday v1.0.27 github.com/microcosm-cc/bluemonday v1.0.27
github.com/prometheus/client_golang v1.22.0 github.com/prometheus/client_golang v1.22.0
github.com/stripe/stripe-go/v74 v74.30.0 github.com/stripe/stripe-go/v74 v74.30.0
@@ -69,6 +68,7 @@ require (
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.9 // indirect github.com/google/s2a-go v0.1.9 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
github.com/googleapis/gax-go/v2 v2.14.2 // indirect github.com/googleapis/gax-go/v2 v2.14.2 // indirect
github.com/gorilla/css v1.0.1 // indirect github.com/gorilla/css v1.0.1 // indirect

View File

@@ -3083,7 +3083,7 @@ func TestServer_MessageTemplate_FromNamedTemplate_GitHubCommentCreated(t *testin
response := request(t, s, "POST", "/mytopic?template=github", githubCommentCreatedJSON, nil) response := request(t, s, "POST", "/mytopic?template=github", githubCommentCreatedJSON, nil)
require.Equal(t, 200, response.Code) require.Equal(t, 200, response.Code)
m := toMessage(t, response.Body.String()) m := toMessage(t, response.Body.String())
require.Equal(t, "💬 [ntfy] New comment on issue #1389 instant alerts without Pull to refresh", m.Title) require.Equal(t, "💬 New comment on issue #1389 instant alerts without Pull to refresh", m.Title)
require.Equal(t, `Commenter: https://github.com/wunter8 require.Equal(t, `Commenter: https://github.com/wunter8
Repository: https://github.com/binwiederhier/ntfy Repository: https://github.com/binwiederhier/ntfy
Comment link: https://github.com/binwiederhier/ntfy/issues/1389#issuecomment-3078214289 Comment link: https://github.com/binwiederhier/ntfy/issues/1389#issuecomment-3078214289
@@ -3102,7 +3102,7 @@ func TestServer_MessageTemplate_FromNamedTemplate_GitHubIssueOpened(t *testing.T
response := request(t, s, "POST", "/mytopic?template=github", githubIssueOpenedJSON, nil) response := request(t, s, "POST", "/mytopic?template=github", githubIssueOpenedJSON, nil)
require.Equal(t, 200, response.Code) require.Equal(t, 200, response.Code)
m := toMessage(t, response.Body.String()) m := toMessage(t, response.Body.String())
require.Equal(t, "🐛 [ntfy] Issue opened: #1391 http 500 error (ntfy error 50001)", m.Title) require.Equal(t, "🐛 Issue opened: #1391 http 500 error (ntfy error 50001)", m.Title)
require.Equal(t, `Opened by: https://github.com/TheUser-dev require.Equal(t, `Opened by: https://github.com/TheUser-dev
Repository: https://github.com/binwiederhier/ntfy Repository: https://github.com/binwiederhier/ntfy
Issue link: https://github.com/binwiederhier/ntfy/issues/1391 Issue link: https://github.com/binwiederhier/ntfy/issues/1391

View File

@@ -7,8 +7,6 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"hash/adler32" "hash/adler32"
"github.com/google/uuid"
) )
func sha512sum(input string) string { func sha512sum(input string) string {
@@ -30,8 +28,3 @@ func adler32sum(input string) string {
hash := adler32.Checksum([]byte(input)) hash := adler32.Checksum([]byte(input))
return fmt.Sprintf("%d", hash) return fmt.Sprintf("%d", hash)
} }
// uuidv4 provides a safe and secure UUID v4 implementation
func uuidv4() string {
return uuid.New().String()
}

View File

@@ -31,24 +31,3 @@ func TestAdler32Sum(t *testing.T) {
t.Error(err) t.Error(err)
} }
} }
func TestUUIDGeneration(t *testing.T) {
tpl := `{{uuidv4}}`
out, err := runRaw(tpl, nil)
if err != nil {
t.Error(err)
}
if len(out) != 36 {
t.Error("Expected UUID of length 36")
}
out2, err := runRaw(tpl, nil)
if err != nil {
t.Error(err)
}
if out == out2 {
t.Error("Expected subsequent UUID generations to be different")
}
}

View File

@@ -58,10 +58,7 @@ var genericMap = map[string]any{
}, },
"substr": substring, "substr": substring,
// Switch order so that "foo" | repeat 5 // Switch order so that "foo" | repeat 5
"repeat": func(count int, str string) string { return strings.Repeat(str, count) }, "repeat": func(count int, str string) string { return strings.Repeat(str, count) },
// Deprecated: Use trimAll.
"trimall": func(a, b string) string { return strings.Trim(b, a) },
// Switch order so that "$foo" | trimall "$"
"trimAll": func(a, b string) string { return strings.Trim(b, a) }, "trimAll": func(a, b string) string { return strings.Trim(b, a) },
"trimSuffix": func(a, b string) string { return strings.TrimSuffix(b, a) }, "trimSuffix": func(a, b string) string { return strings.TrimSuffix(b, a) },
"trimPrefix": func(a, b string) string { return strings.TrimPrefix(b, a) }, "trimPrefix": func(a, b string) string { return strings.TrimPrefix(b, a) },
@@ -220,9 +217,6 @@ var genericMap = map[string]any{
"chunk": chunk, "chunk": chunk,
"mustChunk": mustChunk, "mustChunk": mustChunk,
// UUIDs:
"uuidv4": uuidv4,
// Flow Control: // Flow Control:
"fail": func(msg string) (string, error) { return "", errors.New(msg) }, "fail": func(msg string) (string, error) { return "", errors.New(msg) },