Allow to set any default configuration value from environment

issue7620
review74301002
This commit is contained in:
Cédric Krier
2018-08-27 22:32:45 +02:00
parent c37f12834e
commit e4a1a7fc8b
3 changed files with 17 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Allow to set any default configuration value from environment
* Clear existing session when password is changed
* Manage session with max_age and timeout
* Use passlib to hash and update password
+3
View File
@@ -20,6 +20,9 @@ For more information see ConfigParser_.
.. _ConfigParser: http://docs.python.org/2/library/configparser.html
The default value of any option can be changed using environment variables
with names using this syntax: `TRYTOND_<SECTION>__<NAME>`.
Sections
========
+13
View File
@@ -77,8 +77,21 @@ class TrytonConfigParser(configparser.RawConfigParser):
self.set('password', 'length', 8)
self.set('password', 'entropy', 0.75)
self.set('password', 'reset_timeout', 24 * 60 * 60)
self.update_environ()
self.update_etc()
def update_environ(self):
for key, value in os.environ.items():
if not key.startswith('TRYTOND_'):
continue
try:
section, option = key[len('TRYTOND_'):].lower().split('__', 1)
except ValueError:
continue
if not self.has_section(section):
self.add_section(section)
self.set(section, option, value)
def update_etc(self, configfile=os.environ.get('TRYTOND_CONFIG')):
if isinstance(configfile, str):
configfile = [configfile]