Open hamishforbes opened 1 month ago
Ah of course, I think i've figured it out with the existing sprig functions, its not too pretty or easy to understand but... In case anyone else has a similar use case this seems to be working for me
{{- $s := dict }}
{{- $i := dict }}
{{- range $key, $value := .Secrets }}
{{- $splitkey := splitList "/" $key }}
{{- $i = $s -}}
{{- range $k, $v := $splitkey }}
{{- if eq $k ( sub (len $splitkey) 1) }}
{{- $_ := set $i $v $value }}
{{- else -}}
{{- if not (hasKey $i $v) }} {{- $_ := set $i $v (dict) }} {{- end }}
{{- $i = get $i $v }}
{{- end }}
{{- end }}
{{- end -}}
{{ $s | toPrettyJson }}
Is your feature request related to a problem? Please describe. I'm looking at migrating from a setup where I use consul-template to fetch and then template Vault secrets (via the Vault Agent sidecar) into my application pods before launching the actual application process.
My apps generally consume JSON formatted config files with deeply nested structures.
The solution we've got now is to create fields in the Vault secret with
/
separated names and use the consul template explodeMap function to expand these out to a nested map, which can then be converted to JSONe.g. Vault secret
template
json result
Describe the solution you'd like An equivalent function in VSO so that I can do something like
Describe alternatives you've considered If there's a way to do this with the available functions that'd be great too, especially if i can abstract it out into a shared
SecretTransformation
. I haven't been able to figure out a way though,splitn
maybe?