瀏覽代碼

Merge pull request #1058 from auyer/main

Adds string replacement usage and test in Template
paul-the-alien[bot] 4 年之前
父節點
當前提交
cb5d8414f6
共有 2 個文件被更改,包括 17 次插入0 次删除
  1. 5 0
      docs/snippets/multiline-template-v2-external-secret.yaml
  2. 12 0
      pkg/template/v2/template_test.go

+ 5 - 0
docs/snippets/multiline-template-v2-external-secret.yaml

@@ -21,6 +21,8 @@ spec:
             url: http://localhost:8080
             password: "{{ .password }}"
             user: "{{ .user }}"
+        # using replace function to rewrite secret
+        connection: '{{ .dburl | replace "postgres://" "postgresql://" }}'
 
   data:
   - secretKey: user
@@ -29,4 +31,7 @@ spec:
   - secretKey: password
     remoteRef:
       key: /grafana/password
+  - secretKey: dburl
+    remoteRef:
+      key: /database/url
 {% endraw %}

+ 12 - 0
pkg/template/v2/template_test.go

@@ -195,6 +195,18 @@ func TestExecute(t *testing.T) {
 			},
 		},
 		{
+			name: "use replace function",
+			tpl: map[string][]byte{
+				"foo": []byte(`{{ .conn | replace "postgres://" "db+postgresql://"}}`),
+			},
+			data: map[string][]byte{
+				"conn": []byte(`postgres://user:pass@db.host:5432/dbname`),
+			},
+			expetedData: map[string][]byte{
+				"foo": []byte(`db+postgresql://user:pass@db.host:5432/dbname`),
+			},
+		},
+		{
 			name: "multiline template",
 			tpl: map[string][]byte{
 				"cfg": []byte(`