#13779 closed enhancement (duplicate)
Load environment variables in config file
| Reported by: | 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:
- https://github.com/marina-lab/docker-trac/blob/master/patches/001_read_env_vars.patch
 - https://github.com/marina-lab/docker-trac/blob/7f4d3196c5b080d74d99cafe57e19472c300604d/config.py.patch
 
( 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)
Change History (10)
by , 15 months ago
| Attachment: | 0001-Load-in-env-vars-to-be-used-in-config-file.patch added | 
|---|
comment:1 by , 15 months ago
comment:2 by , 15 months 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 , 15 months 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
comment:4 by , 15 months ago
by , 15 months ago
| Attachment: | 0001-Load-in-env-vars-to-be-used-in-config-file.2.patch added | 
|---|
Updated patch
comment:5 by , 15 months ago
| Milestone: | → undecided | 
|---|
follow-up: 7 comment:6 by , 15 months ago
comment:7 by , 15 months ago
| Milestone: | undecided | 
|---|---|
| Resolution: | → duplicate | 
| Status: | new → closed | 
paramsparameter ofConfiguration.__init__seems to be no longer used. So, I don't think the interpolation for%(envname)sworks, introduced in [10565] (#9674).
The changes have been reverted in [10640-10641].
Closing as a duplicate of #9674.



  
I don't absolutely think you've tried the patch to Trac 1.6.x.
UnicodeConfigParseris not a dictUnicodeConfigParserexplicitly disables the interpolation feature in order to prevent errors when a user set%(...)in trac.ini unintently.