Add SERVER_ENV_CONFIG to configure vars from env. variable

This commit is contained in:
Guewen Baconnier 2018-07-19 08:35:43 +02:00
parent b0bcc2d699
commit 8a075db418
2 changed files with 17 additions and 2 deletions

View File

@ -47,8 +47,12 @@ You should then edit the settings you need in the
`default/` directory using the .ini file syntax; `default/` directory using the .ini file syntax;
* each environment you need to define is stored in its own directory * each environment you need to define is stored in its own directory
and can override or extend default values; and can override or extend default values;
* finally, you can override or extend values in the main configuration * you can override or extend values in the main configuration
file of you instance. 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 Values associated to keys
containing 'passw' are only displayed in the 'dev' environment. containing 'passw' are only displayed in the 'dev' environment.

View File

@ -97,9 +97,20 @@ def _load_config():
config_p.read(conf_files) config_p.read(conf_files)
except Exception as e: except Exception as e:
raise Exception('Cannot read config files "%s": %s' % (conf_files, e)) raise Exception('Cannot read config files "%s": %s' % (conf_files, e))
config_p.read(system_base_config.rcfile) config_p.read(system_base_config.rcfile)
config_p.remove_section('options') 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 return config_p