matrix-tools: add quote filter

This commit is contained in:
Gaël Goinvic committed 2025-01-29 16:28:07 +01:00
1 parent d347c0c3a5
commit fbe854c8d2
7 files changed
+19 -8

No files matched your search

@@ -13,7 +13,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
## The matrix-tools iamge, used in multiple components
matrixTools:
{{ image(registry="ghcr.io", repository="element-hq/ess-helm/matrix-tools", tag="0.1.0") | indent(2) }}
{{ image(registry="ghcr.io", repository="element-hq/ess-helm/matrix-tools", tag="0.1.1") | indent(2) }}
## The server name of the Matrix Stack. This gets embedded in user IDs & room IDs
## It can not change after the initial deployment.
@@ -105,13 +105,13 @@ We have an init container to render & merge the config for several reasons:
*/}}
- name: SYNAPSE_MACAROON
value: >-
{{ printf "{{ readfile \"/secrets/%s/%s\" }}" (tpl (.macaroon.secret | default (printf "%s-synapse" $.Release.Name)) $) (.macaroon.secretKey | default "MACAROON") }}
{{ printf "{{ readfile \"/secrets/%s/%s\" | quote }}" (tpl (.macaroon.secret | default (printf "%s-synapse" $.Release.Name)) $) (.macaroon.secretKey | default "MACAROON") }}
- name: SYNAPSE_POSTGRES_PASSWORD
value: >-
{{ printf "{{ readfile \"/secrets/%s/%s\" }}" (tpl (.postgres.password.secret | default (printf "%s-synapse" $.Release.Name)) $) (.postgres.password.secretKey | default "POSTGRES_PASSWORD") }}
{{ printf "{{ readfile \"/secrets/%s/%s\" | quote }}" (tpl (.postgres.password.secret | default (printf "%s-synapse" $.Release.Name)) $) (.postgres.password.secretKey | default "POSTGRES_PASSWORD") }}
- name: SYNAPSE_REGISTRATION_SHARED_SECRET
value: >-
{{ printf "{{ readfile \"/secrets/%s/%s\" }}" (tpl (.registrationSharedSecret.secret | default (printf "%s-synapse" $.Release.Name)) $) (.registrationSharedSecret.secretKey | default "REGISTRATION_SHARED_SECRET") }}
{{ printf "{{ readfile \"/secrets/%s/%s\" | quote }}" (tpl (.registrationSharedSecret.secret | default (printf "%s-synapse" $.Release.Name)) $) (.registrationSharedSecret.secretKey | default "REGISTRATION_SHARED_SECRET") }}
- name: APPLICATION_NAME
value: >-
{{ printf "{{ hostname | replace \"-synapse-\" \"\" }}" }}
+1 -1
View File
@@ -20,7 +20,7 @@ matrixTools:
## The tag of the container image to use.
## Defaults to the Chart's appVersion if not set
tag: 0.1.0
tag: 0.1.1
## Container digest to use. Used to pull the image instead of the image tag / Chart appVersion if set
# digest:
+1
View File
@@ -62,6 +62,7 @@ Similarly to `envsubstr`, it supports the use of environment variables in config
- `hostname` returns the hostname of the machine.
- `readfile` reads a file and returns its content as string.
- `replace` replaces occurrences of a substring with another substring in the input string.
- `quote` quotes the input string with double quotes.
### TCP Wait
@@ -11,6 +11,7 @@ import (
"io"
"os"
"regexp"
"strconv"
"strings"
"text/template"
@@ -68,6 +69,10 @@ func replace(old, new, src string) string {
return strings.Replace(src, old, new, -1)
}
func quote(src string) string {
return strconv.Quote(src)
}
// RenderConfig takes a list of io.Reader objects representing yaml configuration files
// and returns a single map[string]any containing the deeply merged data as yaml format
// The files are merged in the order they are provided.
@@ -91,6 +96,7 @@ func RenderConfig(sourceConfigs []io.Reader) (map[string]any, error) {
"readfile": readfile,
"hostname": os.Hostname,
"replace": replace,
"quote": quote,
}
envVarNames := extractEnvVarNames(string(fileContent))
@@ -28,18 +28,21 @@ func TestRenderConfig(t *testing.T) {
name: "Single File",
readers: []io.Reader{
bytes.NewBuffer([]byte(`key: ${TEST_ENV}
quotedValue: ${SPECIAL_CHARS}
secretKey: ${SECRET_KEY}
hostname: ${THIS_HOSTNAME}`)),
},
env: map[string]string{
"TEST_ENV": "value",
"SPECIAL_CHARS": "{{ \"!ayamltype\" | quote }}",
"SECRET_KEY": "{{ readfile \"testdata/secret_key\" }}",
"THIS_HOSTNAME": fmt.Sprintf("{{ hostname | replace \"%s\" \"\" }}", droppedFromHostname),
},
expected: map[string]any{
"key": "value",
"secretKey": "secret_value",
"hostname": hostname[0:2] + hostname[4:],
"key": "value",
"secretKey": "secret_value",
"quotedValue": "!ayamltype",
"hostname": hostname[0:2] + hostname[4:],
},
err: false,
},
+1
View File
@@ -0,0 +1 @@
Add the possibility to quote substituted env variable from synapse config.