Skip to content

Instantly share code, notes, and snippets.

@mill5james
Last active September 4, 2020 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mill5james/54c366207de891bcd24e25c7cc85b658 to your computer and use it in GitHub Desktop.
Save mill5james/54c366207de891bcd24e25c7cc85b658 to your computer and use it in GitHub Desktop.
{{/*
Convert YAML to envirment variables for .NET Core hosting environment naming
*/}}
{{- define "translateEnv" -}}
{{- range $key, $value := . }}
{{- if or (kindIs "map" $value) (kindIs "slice" $value) }}
{{- include "prefixItem" (dict $key $value) }}
{{- else }}
- name: {{ $key }}
value: {{ $value | squote }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Used by the translateEnv template.
Expects a dict as a parameter where the key is the prefix and the value is the map to iterate over
*/}}
{{- define "prefixItem" -}}
{{- range $prefix, $map := . }}
{{- range $key, $value := $map }}
{{- if or (kindIs "map" $value) (kindIs "slice" $value) }}
{{- include "prefixItem" (dict (printf "%v__%v" $prefix $key) $value) }}
{{- else }}
- name: {{printf "%v__%v" $prefix $key }}
value: {{ $value | squote }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment