Skip output when no env is set

This commit is contained in:
Daniel Berteaud 2024-03-11 23:33:14 +01:00
parent 8f75a170dd
commit 50f0293e05
1 changed files with 16 additions and 13 deletions

View File

@ -10,31 +10,34 @@
[[- $env = . ]]
[[- end -]]
[[- if gt (keys $env | len) 0 ]]
# Use a template block instead of env {} so we can fetch values from vault
template {
data = <<_EOT
[[- range $k, $v := $env ]]
[[- if or (isKind "string" $v) (isKind "number" $v) (isKind "bool" $v) ]]
[[ $k ]]=[[ $v ]]
[[- else if isKind "map" $v ]]
[[- if and (has $v "source") (eq $v.source "vault") ]]
[[- range $k, $v := $env ]]
[[- if or (isKind "string" $v) (isKind "number" $v) (isKind "bool" $v) ]]
[[ $k ]]=[[ $v ]]
[[- else if isKind "map" $v ]]
[[- if and (has $v "source") (eq $v.source "vault") ]]
[[ $k ]]={{ with secret "[[ if has $v "path" ]][[ $v.path ]][[ else ]][[ $.vault.kv.path ]][[ end ]]" }}{{ [[ $v.key ]] }}{{ end }}
[[- end ]]
[[- end ]]
[[- end ]]
[[- end ]]
[[- if and (has . "proxy") .proxy.enabled ]]
[[- if not (has $env "HTTP_PROXY") ]]
[[- if and (has . "proxy") .proxy.enabled ]]
[[- if not (has $env "HTTP_PROXY") ]]
HTTP_PROXY=[[ .proxy.address ]]
[[- end ]]
[[- if not (has $env "HTTPS_PROXY") ]]
[[- end ]]
[[- if not (has $env "HTTPS_PROXY") ]]
HTTPS_PROXY=[[ .proxy.address ]]
[[- end ]]
[[- if and (has .proxy "no_proxy") (not (has $env "NO_PROXY")) ]]
[[- end ]]
[[- if and (has .proxy "no_proxy") (not (has $env "NO_PROXY")) ]]
NO_PROXY=[[ join .proxy.no_proxy "," ]]
[[- end ]]
[[- end ]]
[[- end ]]
_EOT
destination = "secrets/.env"
perms = 400
env = true
}
[[- end ]]