kreuzwerker / envplate

Docker-friendly trivial templating for configuration files using environment keys
MIT License
331 stars 44 forks source link

Recursive substitution? #45

Open djarbz opened 2 years ago

djarbz commented 2 years ago

I would like to put substitutions on the right hand side of the :, or a better solution would be great too.

Expected Behavior

tunnel_host = "${SERVER_TUNNEL_HOST:-${SERVER_URL:-http://$(hostname)}}" would render in this precedence:

  1. SERVER_TUNNEL_HOST
  2. SERVER_URL
  3. http://hostname

Actual Behavior

tunnel_host = "${SERVER_URL:-http://$(hostname)}"

Steps to Reproduce (including precondition)

SERVER_TUNNEL_HOST is unset
SERVER_URL=http://my.server.com
tunnel_host = "${SERVER_TUNNEL_HOST:-${SERVER_URL:-http://$(hostname)}}"

renders tunnel_host = "${SERVER_URL:-http://$(hostname)}"

Your Environment

Another scenario

auth = "${SERVER_AUTH_USER:?${SERVER_AUTH_PASSWORD:?${SERVER_AUTH_USER}:${SERVER_AUTH_PASSWORD}}}" This should verify that SERVER_AUTH_USER & SERVER_AUTH_PASSWORD are both set, then set the line to the value of: auth = "${SERVER_AUTH_USER}:${SERVER_AUTH_PASSWORD"

di-rect commented 11 months ago

@djarbz Have you ever been able to find a solution for this ?

djarbz commented 11 months ago

Unfortunately I have not.

di-rect commented 11 months ago

@djarbz that's a pity, I'm looking for a workaround too. Have you tried escaping and such like the empty value needs as well ?

djarbz commented 11 months ago

I haven't touched this in quite some time, I don't even recall what project I was wanting this for.

di-rect commented 11 months ago

@djarbz OK understood; in other cases you need to go thought your files using AWK or SED so it's pretty useful!

di-rect commented 11 months ago

@mavogel Is this something you might can look into ?

enc commented 11 months ago

are you expecting hostname also to be substituted?

A single replacement in the default might be easy with a more complex regular expression and some logic. But multiple and especially nested ones are very difficult in regexp