You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 JSON
e.g.
Vault secret
> vault kv get secret/foobar
...snip
============== Data ==============
Key Value
--- -----
foo/bar/baz qux
foo/a/b c
template
{{- with secret "secret/foobar" -}}
{{- range $k, $v := .Data.data -}}
{{- scratch.MapSet "vars" $k $v -}}
{{- end -}}
{{- end -}}
{{ scratch.Get "vars" | explodeMap | toJSONPretty }}
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?
The text was updated successfully, but these errors were encountered:
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?The text was updated successfully, but these errors were encountered: