From 16c5478680b1ae562b8bb58c1b824d25ca8156c2 Mon Sep 17 00:00:00 2001 From: DIGVIJAY <144053736+digvijay-y@users.noreply.github.com> Date: Sat, 4 Oct 2025 12:03:55 +0000 Subject: [PATCH 1/3] Documented cat and credential template functions in Templates.md --- docs/Templates.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/Templates.md b/docs/Templates.md index 35f10a0..90ebb24 100644 --- a/docs/Templates.md +++ b/docs/Templates.md @@ -73,5 +73,33 @@ 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. + +### `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: +```json +"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: +```json +"secret": "{{ credential "my-secret" | js }}" +``` + [w]: https://github.com/adnanh/webhook [tt]: https://golang.org/pkg/text/template/ From b3268410761ec329ae2e9b80397d834f81bac0f2 Mon Sep 17 00:00:00 2001 From: DIGVIJAY <144053736+digvijay-y@users.noreply.github.com> Date: Thu, 9 Oct 2025 04:59:42 +0000 Subject: [PATCH 2/3] docs: Example for getenv --- docs/Templates.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/Templates.md b/docs/Templates.md index 90ebb24..4eadec6 100644 --- a/docs/Templates.md +++ b/docs/Templates.md @@ -81,6 +81,11 @@ In addition to the [built-in Go template functions and features][tt], `webhook` The `getenv` template function can be used for inserting environment variables into a templated configuration file. +Example: +```json +"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. From 7e51784d8152086cf151ce28c7c3968c6627aaa8 Mon Sep 17 00:00:00 2001 From: DIGVIJAY <144053736+digvijay-y@users.noreply.github.com> Date: Thu, 9 Oct 2025 17:43:51 +0000 Subject: [PATCH 3/3] update! --- docs/Templates.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/Templates.md b/docs/Templates.md index 4eadec6..3355112 100644 --- a/docs/Templates.md +++ b/docs/Templates.md @@ -82,8 +82,8 @@ In addition to the [built-in Go template functions and features][tt], `webhook` The `getenv` template function can be used for inserting environment variables into a templated configuration file. Example: -```json -"Secret": "{{getenv \"TEST_secret\" | js}}" +``` +"Secret": "{{getenv TEST_secret | js}}" ``` ### `cat` @@ -91,7 +91,7 @@ Example: 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: -```json +``` "secret": "{{ cat "/run/secrets/my-secret" | js }}" ``` @@ -102,7 +102,7 @@ The `credential` template function provides a way to retrieve secrets using [sys 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: -```json +``` "secret": "{{ credential "my-secret" | js }}" ```