英文:
Loop through Vault secret
问题
我正在尝试使用Vault注释的模板来创建一个具有key: value
结构的秘密文件。
目前我正在尝试以下内容:
vault.hashicorp.com/agent-inject-template-credentials.txt: |
{{ with secret (print "secret/data/test/config/") }}{{ range $k, $v := .Data.data }}
{{ $k }}: {{ $v }}
{{ end }}
但是这导致了Vault的初始化容器错误。秘密本身的结构如下:
data map[test1:test1 test2:test2 test3:test3]
metadata map[created_time:2022-09-04T23:47:42.299009227Z custom_metadata:<nil> deletion_time: destroyed:false version:2]
输出的结构应该是这样的(key: value
):
test1: test1
test2: test2
test3: test3
我该如何实现这个目标?
[编辑]
vault.hashicorp.com/agent-inject-template-credentials.txt: |
{{- with secret (print "secret/data/test/config") }}{{- range $k, $v := .Data.data }}
{{ $k }}: {{ $v }}
{{- end }}{{- end }}
这个方法很好用,但是它在文件开头产生了一个空行:
// 文件开头有一个空行
test1: test1
test2: test2
test3: test3
英文:
I'm trying to use Vault annotation's template to create a secret file with key: value
structure.
Currently I'm trying with this:
vault.hashicorp.com/agent-inject-template-credentials.txt: |
{{ with secret (print "secret/data/test/config/") }}{{ range $k, $v := .Data.data }}
{{ $k }}: {{ $v }}
{{ end }}
But this results is Vault's init container error. The secret itself looks like this:
data map[test1:test1 test2:test2 test3:test3]
metadata map[created_time:2022-09-04T23:47:42.299009227Z custom_metadata:<nil> deletion_time: destroyed:false version:2]
And the output structure should look like that (key: value
):
test1: test1
test2: test2
test3: test3
How can I achieve that?
[EDIT]
vault.hashicorp.com/agent-inject-template-credentials.txt: |
{{- with secret (print "secret/data/test/config") }}{{- range $k, $v := .Data.data }}
{{ $k }}: {{ $v }}
{{- end }}{{- end }}
This works well but it produces new line at the beginning of the file:
// one empty line at the beginning
test1: test1
test2: test2
test3: test3
答案1
得分: 1
为了消除换行符,你需要直接在 |
后面开始文件。
vault.hashicorp.com/agent-inject-template-credentials.txt: | {{- with secret (print "secret/data/test/config") }}{{- range $k, $v := .Data.data }}
{{ $k }}: {{ $v }}
{{- end }}{{- end }}
我建议使用模板的 source
和 destination
。你可以在 这里 找到更多信息。
英文:
To eliminate the line break you have to start the file after the |
directly
vault.hashicorp.com/agent-inject-template-credentials.txt: | {{- with secret (print "secret/data/test/config") }}{{- range $k, $v := .Data.data }}
{{ $k }}: {{ $v }}
{{- end }}{{- end }}
i suggest using template source
and destination
src
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论