Mailing List Archive

Env var default value
I would like to be able to specify a default/fallback value for when
an environment variable is not defined while loading the
configuration, like the ${SOME_VAR-default} form in bash/shells.

In docker (mainly docker-compose) where quite some settings are passed
to the container through env vars, this would be really useful for an
httpd.conf "template" with default values for undefined vars.

I first thought of "<IfEnv [!]blah>" or alike, but it quickly becomes
hard to read/follow, while e.g:
LogLevel "${LOG_LEVEL-info}"
would be lovely :)

So would a patch like the attached be acceptable?
It uses '-' as separator but any other char would do (if the minus
sign is likely to break configuration where it shouldn't be
interpreted), though that would look less like a shell expansion..

Regards,
Yann.
Re: Env var default value [ In reply to ]
${LOG_LEVEL:-info}

would be even more shellish, or?


> Am 22.04.2020 um 11:38 schrieb Yann Ylavic <ylavic.dev@gmail.com>:
>
> I would like to be able to specify a default/fallback value for when
> an environment variable is not defined while loading the
> configuration, like the ${SOME_VAR-default} form in bash/shells.
>
> In docker (mainly docker-compose) where quite some settings are passed
> to the container through env vars, this would be really useful for an
> httpd.conf "template" with default values for undefined vars.
>
> I first thought of "<IfEnv [!]blah>" or alike, but it quickly becomes
> hard to read/follow, while e.g:
> LogLevel "${LOG_LEVEL-info}"
> would be lovely :)
>
> So would a patch like the attached be acceptable?
> It uses '-' as separator but any other char would do (if the minus
> sign is likely to break configuration where it shouldn't be
> interpreted), though that would look less like a shell expansion..
>
> Regards,
> Yann.
> <ap_resolve_env.diff>
Re: Env var default value [ In reply to ]
On 4/22/20 11:38 AM, Yann Ylavic wrote:
> I would like to be able to specify a default/fallback value for when
> an environment variable is not defined while loading the
> configuration, like the ${SOME_VAR-default} form in bash/shells.
>
> In docker (mainly docker-compose) where quite some settings are passed
> to the container through env vars, this would be really useful for an
> httpd.conf "template" with default values for undefined vars.
>
> I first thought of "<IfEnv [!]blah>" or alike, but it quickly becomes
> hard to read/follow, while e.g:
> LogLevel "${LOG_LEVEL-info}"
> would be lovely :)
>
> So would a patch like the attached be acceptable?
> It uses '-' as separator but any other char would do (if the minus
> sign is likely to break configuration where it shouldn't be
> interpreted), though that would look less like a shell expansion..

In general I am fine, but keep in mind that this also affects defines done via Define in the configuration file and people might
have used '-' in names there. So I guess another character should be used here.
And here we are in some sort of fun name discussion :-).

I open with

'@'
':'


Regards

RĂ¼diger
Re: Env var default value [ In reply to ]
On Wed, Apr 22, 2020 at 11:47 AM Stefan Eissing
<stefan.eissing@greenbytes.de> wrote:
>
> ${LOG_LEVEL:-info}
>
> would be even more shellish, or?

In shells, with the ':' it means undefined or empty, while '-' alone
is only undefined.
Re: Env var default value [ In reply to ]
> Am 22.04.2020 um 11:57 schrieb Yann Ylavic <ylavic.dev@gmail.com>:
>
> On Wed, Apr 22, 2020 at 11:47 AM Stefan Eissing
> <stefan.eissing@greenbytes.de> wrote:
>>
>> ${LOG_LEVEL:-info}
>>
>> would be even more shellish, or?
>
> In shells, with the ':' it means undefined or empty, while '-' alone
> is only undefined.

Ah, thanks! If I ever knew that, it had been forgotten...
Re: Env var default value [ In reply to ]
On Wed, Apr 22, 2020 at 11:55 AM Ruediger Pluem <rpluem@apache.org> wrote:
>
> On 4/22/20 11:38 AM, Yann Ylavic wrote:
> >
> > It uses '-' as separator but any other char would do (if the minus
> > sign is likely to break configuration where it shouldn't be
> > interpreted), though that would look less like a shell expansion..
>
> In general I am fine, but keep in mind that this also affects defines done via Define in the configuration file and people might
> have used '-' in names there. So I guess another character should be used here.
> And here we are in some sort of fun name discussion :-).

That was the hidden purpose of this discussion somehow :)

>
> I open with
>
> '@'

Yeah, or '|' ?

> ':'

This one looks special already in ap_resolve_env(), though it's
forbidden in Define so that may be it.
It was made special from the start (in commit [1]) that allowed Define
vars to be interpreted like env vars, but I don't really understand
the point..

[1] http://svn.apache.org/viewvc?view=revision&revision=1061465
Re: Env var default value [ In reply to ]
On Wed, Apr 22, 2020 at 12:09 PM Stefan Eissing
<stefan.eissing@greenbytes.de> wrote:
>
> > Am 22.04.2020 um 11:57 schrieb Yann Ylavic <ylavic.dev@gmail.com>:
> >
> > On Wed, Apr 22, 2020 at 11:47 AM Stefan Eissing
> > <stefan.eissing@greenbytes.de> wrote:
> >>
> >> ${LOG_LEVEL:-info}
> >>
> >> would be even more shellish, or?
> >
> > In shells, with the ':' it means undefined or empty, while '-' alone
> > is only undefined.
>
> Ah, thanks! If I ever knew that, it had been forgotten...

Honestly I had forgotten too, but this proposal made me look at it :)
Re: Env var default value [ In reply to ]
On Wed, Apr 22, 2020 at 12:10 PM Yann Ylavic <ylavic.dev@gmail.com> wrote:
>
> > ':'
>
> This one looks special already in ap_resolve_env(), though it's
> forbidden in Define so that may be it.

I'm afraid ':' will collide with mod_rewrite's
"${mapname:key|default}" syntax for RewriteMap.
Same goes for '|' it seems, naming discussion still open :)

bash uses '=' for the default value too, looks quite readable/meaningful to me..
Re: Env var default value [ In reply to ]
On 4/22/20 12:50 PM, Yann Ylavic wrote:
> On Wed, Apr 22, 2020 at 12:10 PM Yann Ylavic <ylavic.dev@gmail.com> wrote:
>>
>>> ':'
>>
>> This one looks special already in ap_resolve_env(), though it's
>> forbidden in Define so that may be it.
>
> I'm afraid ':' will collide with mod_rewrite's
> "${mapname:key|default}" syntax for RewriteMap.
> Same goes for '|' it seems, naming discussion still open :)
>
> bash uses '=' for the default value too, looks quite readable/meaningful to me..

'=' seems to be a good candidate as I would suppose that it is rarely used in variable names.

Regards

RĂ¼diger
Re: Env var default value [ In reply to ]
On Wed, Apr 22, 2020 at 12:50:36PM +0200, Yann Ylavic wrote:
> On Wed, Apr 22, 2020 at 12:10 PM Yann Ylavic <ylavic.dev@gmail.com> wrote:
> >
> > > ':'
> >
> > This one looks special already in ap_resolve_env(), though it's
> > forbidden in Define so that may be it.
>
> I'm afraid ':' will collide with mod_rewrite's
> "${mapname:key|default}" syntax for RewriteMap.
> Same goes for '|' it seems, naming discussion still open :)
>
> bash uses '=' for the default value too, looks quite readable/meaningful to me..

+1 to the idea, and '=' seems like a good choice.

Regards, Joe
Re: Env var default value [ In reply to ]
On 4/22/20 1:13 PM, Ruediger Pluem wrote:
>
>
> On 4/22/20 12:50 PM, Yann Ylavic wrote:
>> On Wed, Apr 22, 2020 at 12:10 PM Yann Ylavic <ylavic.dev@gmail.com> wrote:
>>>
>>>> ':'
>>>
>>> This one looks special already in ap_resolve_env(), though it's
>>> forbidden in Define so that may be it.
>>
>> I'm afraid ':' will collide with mod_rewrite's
>> "${mapname:key|default}" syntax for RewriteMap.
>> Same goes for '|' it seems, naming discussion still open :)
>>
>> bash uses '=' for the default value too, looks quite readable/meaningful to me..
>
> '=' seems to be a good candidate as I would suppose that it is rarely used in variable names.
>
I like both the idea and the '=' choice, +1.
Giovanni
Re: Env var default value [ In reply to ]
On Wed, Apr 22, 2020 at 6:50 AM Yann Ylavic <ylavic.dev@gmail.com> wrote:
>
> On Wed, Apr 22, 2020 at 12:10 PM Yann Ylavic <ylavic.dev@gmail.com> wrote:
> >
> > > ':'
> >
> > This one looks special already in ap_resolve_env(), though it's
> > forbidden in Define so that may be it.
>
> I'm afraid ':' will collide with mod_rewrite's
> "${mapname:key|default}" syntax for RewriteMap.
> Same goes for '|' it seems, naming discussion still open :)
>
> bash uses '=' for the default value too, looks quite readable/meaningful to me..

Bikeshedding but what about "?="
It does not align with bash (which I don't find so intuitive and power
users will not recognize w/o the ':' anyway) but looks less like
assignment and drives home that it's kind of a conditional

--
Eric Covener
covener@gmail.com
Re: Env var default value [ In reply to ]
On Wed, Apr 22, 2020 at 3:03 PM Eric Covener <covener@gmail.com> wrote:
>
> On Wed, Apr 22, 2020 at 6:50 AM Yann Ylavic <ylavic.dev@gmail.com> wrote:
> >
> > On Wed, Apr 22, 2020 at 12:10 PM Yann Ylavic <ylavic.dev@gmail.com> wrote:
> > >
> > > > ':'
> > >
> > > This one looks special already in ap_resolve_env(), though it's
> > > forbidden in Define so that may be it.
> >
> > I'm afraid ':' will collide with mod_rewrite's
> > "${mapname:key|default}" syntax for RewriteMap.
> > Same goes for '|' it seems, naming discussion still open :)
> >
> > bash uses '=' for the default value too, looks quite readable/meaningful to me..
>
> Bikeshedding but what about "?="

Damn, I like it, but three +1s for '=' already..
Well, I used that in r1876835, let's see if others shout :)

Thanks to all for feedbacks!