From e4a1a7fc8b75fe649dfde54f2d5116ebc981c730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 27 Aug 2018 22:32:45 +0200 Subject: [PATCH] Allow to set any default configuration value from environment issue7620 review74301002 --- CHANGELOG | 1 + doc/topics/configuration.rst | 3 +++ trytond/config.py | 13 +++++++++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index fd070ffdb0..3cd16eed77 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/doc/topics/configuration.rst b/doc/topics/configuration.rst index 62a2523081..1ea9bcecf0 100644 --- a/doc/topics/configuration.rst +++ b/doc/topics/configuration.rst @@ -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_
__`. + Sections ======== diff --git a/trytond/config.py b/trytond/config.py index 6422464292..0c7e820787 100644 --- a/trytond/config.py +++ b/trytond/config.py @@ -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]