From ec14e3da0a44ddbdab64b19d10d7f299a14c0453 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Thu, 19 Jul 2018 08:35:43 +0200 Subject: [PATCH] Add SERVER_ENV_CONFIG to configure vars from env. variable --- server_environment/README.rst | 8 ++++++-- server_environment/serv_config.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/server_environment/README.rst b/server_environment/README.rst index fdf8816..a68bc25 100644 --- a/server_environment/README.rst +++ b/server_environment/README.rst @@ -47,8 +47,12 @@ You should then edit the settings you need in the `default/` directory using the .ini file syntax; * each environment you need to define is stored in its own directory and can override or extend default values; -* finally, you can override or extend values in the main configuration - file of you instance. +* you can override or extend values in the main configuration + file of you instance; +* additional configuration can be passed in the environment variable + ``SERVER_ENV_CONFIG``, overriding any values set in the configuration files. + This is a multi-line environment variable in the same configparser format than + the files. Values associated to keys containing 'passw' are only displayed in the 'dev' environment. diff --git a/server_environment/serv_config.py b/server_environment/serv_config.py index e07a173..5bc3500 100644 --- a/server_environment/serv_config.py +++ b/server_environment/serv_config.py @@ -97,9 +97,20 @@ def _load_config(): config_p.read(conf_files) except Exception as e: raise Exception('Cannot read config files "%s": %s' % (conf_files, e)) + config_p.read(system_base_config.rcfile) config_p.remove_section('options') + env_config = os.getenv('SERVER_ENV_CONFIG') + if env_config: + try: + config_p.read_string(env_config) + except configparser.Error as err: + raise Exception( + 'SERVER_ENV_CONFIG content could not be parsed: %s' + % (err,) + ) + return config_p