From 2b622cf89313b780b1242a98603b31f57e0c2b0f Mon Sep 17 00:00:00 2001
From: Lubomir Dolezal <lubomir.bucek@eox.at>
Date: Thu, 3 Feb 2022 19:38:30 +0100
Subject: [PATCH] add custom quote function for !env tag vars

---
 .../vs-registrar/files/registrar-config.yaml  | 24 ++++++++++---------
 charts/vs-registrar/templates/_helpers.tpl    | 10 ++++++++
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/charts/vs-registrar/files/registrar-config.yaml b/charts/vs-registrar/files/registrar-config.yaml
index fd3280c..4b5f6f5 100644
--- a/charts/vs-registrar/files/registrar-config.yaml
+++ b/charts/vs-registrar/files/registrar-config.yaml
@@ -6,18 +6,20 @@ sources:
     filter: {{ .filter }}
     kwargs:
     {{- if eq $type "swift" }}
-      username: {{ $val.username | quote }}
-      password: {{ $val.password | quote }}
-      project_name: {{ $val.project_name | quote }}
-      project_id: {{ $val.project_id | quote }}
-      region_name: {{ $val.region_name | quote }}
-      auth_url: {{ $val.auth_url | quote }}
+      username: {{ template "vs-registrar.envVarQuote" $val.username }}
+      password: {{ template "vs-registrar.envVarQuote" $val.password }}
+      project_name: {{ template "vs-registrar.envVarQuote" $val.project_name }}
+      project_id: {{ template "vs-registrar.envVarQuote" $val.project_id }}
+      region_name: {{ template "vs-registrar.envVarQuote" $val.region_name }}
+      auth_url: {{ template "vs-registrar.envVarQuote" $val.auth_url }}
       auth_version: {{ $val.auth_version }}
-      user_domain_name: {{ $val.user_domain_name | quote }}
-      user_domain_id: {{ $val.user_domain_id | quote }}
-      project_domain_name: {{ $val.project_domain_name | quote }}
-      project_domain_id: {{ $val.project_domain_id | quote }}
-      container: {{ $val.container | quote }}
+      user_domain_name: {{ template "vs-registrar.envVarQuote" $val.user_domain_name }}
+      user_domain_id: {{ template "vs-registrar.envVarQuote" $val.user_domain_id }}
+      project_domain_name: {{ template "vs-registrar.envVarQuote" $val.project_domain_name }}
+      project_domain_id: {{ template "vs-registrar.envVarQuote" $val.project_domain_id }}
+      {{- if $val.container }}
+      container: {{ template "vs-registrar.envVarQuote" $val.container }}
+    {{- end }}
     {{- else if eq $type "s3" }}
       bucket_name: {{ $val.bucket | default "null" }}
       endpoint_url: {{ $val.endpoint_url | default "null" }}
diff --git a/charts/vs-registrar/templates/_helpers.tpl b/charts/vs-registrar/templates/_helpers.tpl
index 8053c96..961eea9 100644
--- a/charts/vs-registrar/templates/_helpers.tpl
+++ b/charts/vs-registrar/templates/_helpers.tpl
@@ -60,3 +60,13 @@ Create the name of the service account to use
 {{- default "default" .Values.serviceAccount.name }}
 {{- end }}
 {{- end }}
+
+{{/*
+Transforms "!env string" to !env "string" for env variable masking
+*/}}
+{{- define "vs-registrar.envVarQuote" -}}
+{{- if contains "!env " .}}!env {{( . | replace "!env " "") | quote }}
+{{- else if contains "!env" .}}!env {{( . | replace "!env" "") | quote }}
+{{- else}}{{ . | quote }}
+{{- end}}
+{{- end}}
-- 
GitLab