From 34d4418840058592f5d5eff56651adb9940a0445 Mon Sep 17 00:00:00 2001 From: DIGVIJAY <144053736+digvijay-y@users.noreply.github.com> Date: Fri, 28 Nov 2025 02:39:50 +0530 Subject: [PATCH] docs: Documented cat and credential template functions (#739) --- docs/Templates.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/Templates.md b/docs/Templates.md index 35f10a0..3355112 100644 --- a/docs/Templates.md +++ b/docs/Templates.md @@ -73,5 +73,38 @@ Additionally, the result is piped through the built-in Go template function `js` ``` +## Template Functions + +In addition to the [built-in Go template functions and features][tt], `webhook` provides the following functions: + +### `getenv` + +The `getenv` template function can be used for inserting environment variables into a templated configuration file. + +Example: +``` +"Secret": "{{getenv TEST_secret | js}}" +``` + +### `cat` + +The `cat` template function can be used to read a file from the local filesystem. This is useful for reading secrets from files. If the file doesn't exist, it returns an empty string. + +Example: +``` +"secret": "{{ cat "/run/secrets/my-secret" | js }}" +``` + +### `credential` + +The `credential` template function provides a way to retrieve secrets using [systemd's LoadCredential mechanism](https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Credentials). It reads the file specified by the given name from the directory specified in the `CREDENTIALS_DIRECTORY` environment variable. + +If `CREDENTIALS_DIRECTORY` is not set, it will fall back to using `getenv` to read the secret from an environment variable of the given name. + +Example: +``` +"secret": "{{ credential "my-secret" | js }}" +``` + [w]: https://github.com/adnanh/webhook [tt]: https://golang.org/pkg/text/template/