Allow to set any default configuration value from environment
issue7620 review74301002
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
========
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user