sprig
sprig copied to clipboard
Add url encode and decode functions
Helm is using sprig as a source of extended functions.
In helm url encode and decode functions would be useful i think. So it would be great to add them to sprig.
P.S. For example it would be extremely useful in gitlab chart MR - https://gitlab.com/gitlab-org/charts/gitlab/-/merge_requests/1234
Just here to +1 this, for anyone looking for a solution, remember you can always add your custom functions to the function map:
func urlDecode(str string) string { s, _ := url.QueryUnescape(str); return s }
func urlEncode(str string) string { return url.QueryEscape(str) }
fmap := sprig.TxtFuncMap()
fmap["urlEncode"] = urlEncode
fmap["urlDecode"] = urlDecode
// then use like:
template.New("").Funcs(fmap).Parse(yourTemplate)
In Apache Airflow, we need to build the URL from the values from the values.yaml file, but unfortunately this cannot be done because to build the URL with userinfo we need a function that percent-encode the usernaame/password.
More context: https://github.com/apache/airflow/pull/16004
I found a workaround. Go templaes supports urlquery function. It returns the escaped version of the value passed in as an argument so that it is suitable for embedding in the query portion of a URL.