Edgewall Software
Modify

Opened 3 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#13779 closed enhancement (duplicate)

Load environment variables in config file

Reported by: m@… Owned by:
Priority: normal Milestone:
Component: general Version:
Severity: normal Keywords: patch
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Hi,

We're deploying trac in a containerized environment and it would be useful to pass parts of the configuration file as environment variables, specifically the db string / db credentials.

I've found prior art doing this:

( with information about why the change here: https://github.com/marina-lab/docker-trac/commit/054a2d820856abc8d7b78a727a4c706f9917332d#diff-7f3552a4131e0f60dfffa919511f1660ab995c4c9c92ef10591c9003033fbfb5).

The attached patch allows for embedding eg %(DATABASE_URL)s in the config file using configparser's machinery.

Attachments (2)

0001-Load-in-env-vars-to-be-used-in-config-file.patch (940 bytes ) - added by m@… 3 weeks ago.
0001-Load-in-env-vars-to-be-used-in-config-file.2.patch (3.2 KB ) - added by m@… 3 weeks ago.
Updated patch

Download all attachments as: .zip

Change History (10)

comment:1 by Jun Omae, 3 weeks ago

I don't absolutely think you've tried the patch to Trac 1.6.x.

  • First parameter of the UnicodeConfigParser is not a dict
  • The UnicodeConfigParser explicitly disables the interpolation feature in order to prevent errors when a user set %(...) in trac.ini unintently.
class UnicodeConfigParser(ConfigParser):
    """A Unicode-aware version of ConfigParser. Arguments are encoded to
    UTF-8 and return values are decoded from UTF-8.
    """

    # All of the methods of ConfigParser are overridden except
    # `getboolean`, `getint`, `getfloat`, `defaults`, `read`, `readfp`,
    # `optionxform` and `write`. `getboolean`, `getint` and `getfloat`
    # call `get`, so it isn't necessary to reimplement them.
    # The base class `RawConfigParser` doesn't inherit from `object`
    # so we can't use `super`.

    def __init__(self, ignorecase_option=True, **kwargs):
        self._ignorecase_option = ignorecase_option
        kwargs.setdefault('interpolation', None)
        ConfigParser.__init__(self, **kwargs)

in reply to:  description comment:2 by Jun Omae, 3 weeks ago

Keywords: patch removed
Milestone: undecided

We're deploying trac in a containerized environment and it would be useful to pass parts of the configuration file as environment variables, specifically the db string / db credentials.

BTW, I don't think storing DB credentials to environment variables is secure….

comment:3 by m@…, 3 weeks ago

Keywords: patch added
Milestone: undecided

Looking further into this, in git commit 5e93df6be0742b4d039544580da12efa695792fb / [10565], the option was added to interpolate a subset of params based on the params= argument,

this was undone in git commit 4485bc76dc29e038ad3aef5fa2bbace27b1735c3 / 4485bc76dc29e038ad3aef5fa2bbace27b1735c3 referring to ticket #10640

git commit 3e0aa1338100bdf1b3b757f57b033906071f3207 / [17483] for unknown reasons removes interpolation

Last edited 3 weeks ago by Jun Omae (previous) (diff)

comment:5 by Jun Omae, 3 weeks ago

Milestone: undecided

comment:6 by Jun Omae, 3 weeks ago

params parameter of Configuration.__init__ seems to be no longer used. So, I don't think the interpolation for %(envname)s works, introduced in [10565] (#9674).

P.S. Please stop changing the milestone.

in reply to:  6 comment:7 by Jun Omae, 3 weeks ago

Milestone: undecided
Resolution: duplicate
Status: newclosed

params parameter of Configuration.__init__ seems to be no longer used. So, I don't think the interpolation for %(envname)s works, introduced in [10565] (#9674).

The changes have been reverted in [10640-10641].

Closing as a duplicate of #9674.

comment:8 by m@…, 3 weeks ago

Closing as a duplicate of #9674.

While the behaviour of this ticket/patch does overlap #9674, what's being asked here is much more exhaustive than what's being asked in that ticket, asking for ALL environment variables being parameterized as opposed to a single computed envname.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The ticket will remain with no owner.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from (none) to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.