sprig icon indicating copy to clipboard operation
sprig copied to clipboard

[FEATURE REQUEST] Add urlencode template function

Open DrissiReda opened this issue 2 years ago • 2 comments

Hello, I had this requirement while using sprig in Helm.

My use case is simple, on multiple occasions, I have to supply a username/password on a uri with basic authentication, but sometimes the passwords have special characters. I'd like a way to url encode the supplied passwords.

Example:

With this values.yaml file:

username: postgres
password: $@cr4d
endpoint: psql.ns:5432
database: test

This template:

name: psqlUri
value: "--backend-store-uri=postgresql://{{ .Values.username }}:{{ .Values.password | urlenc }}@{{ .Values.endpoint }}/{{ .Values.database }}

Should render:

name: psqlUri
value: "--backend-store-uri=postgresql://postgres:%24%40cr4d%[email protected]:5432/test

The solution to supply it already encoded is impractical because it might be annoying for some users, and I might need to supply it in its raw form elsewhere on the helm. In this particular example I might also need it to create the postgresql secret with the env var PGPASSWORD .

Is there any difficulty to include this feature?

DrissiReda avatar Apr 22 '22 07:04 DrissiReda

In 2017 someone already prepared a PR https://github.com/Masterminds/sprig/pull/62 that could be reused.

gw0 avatar Oct 26 '22 12:10 gw0