Add SERVER_ENV_CONFIG_SECRET alongside SERVER_ENV_CONFIG

Allows to isolate the secrets in your deployment
This commit is contained in:
Guewen Baconnier 2018-07-20 11:53:54 +02:00
parent 8a075db418
commit 3b074b1061
2 changed files with 18 additions and 13 deletions

View File

@ -27,6 +27,8 @@ the incoming and outgoing mail servers depending on the environment.
To install this module, you need to provide a companion module called To install this module, you need to provide a companion module called
`server_environment_files`. You can copy and customize the provided `server_environment_files`. You can copy and customize the provided
`server_environment_files_sample` module for this purpose. `server_environment_files_sample` module for this purpose.
You can provide additional options in environment variables
``SERVER_ENV_CONFIG`` and ``SERVER_ENV_CONFIG_SECRET``.
Configuration Configuration
@ -48,11 +50,11 @@ You should then edit the settings you need in the
* 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;
* 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 your instance;
* additional configuration can be passed in the environment variable * additional configuration can be passed in the environment variable
``SERVER_ENV_CONFIG``, overriding any values set in the configuration files. ``SERVER_ENV_CONFIG`` and/or ``SERVER_ENV_CONFIG_SECRET``, overriding any
This is a multi-line environment variable in the same configparser format than values set in the configuration files. This is a multi-line environment
the files. 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

@ -31,6 +31,8 @@ from .system_info import get_server_environment
from odoo.addons import server_environment_files from odoo.addons import server_environment_files
_dir = os.path.dirname(server_environment_files.__file__) _dir = os.path.dirname(server_environment_files.__file__)
ENV_VAR_NAMES = ('SERVER_ENV_CONFIG', 'SERVER_ENV_CONFIG_SECRET')
# Same dict as RawConfigParser._boolean_states # Same dict as RawConfigParser._boolean_states
_boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True, _boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True,
'0': False, 'no': False, 'false': False, 'off': False} '0': False, 'no': False, 'false': False, 'off': False}
@ -101,15 +103,16 @@ def _load_config():
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') for varname in ENV_VAR_NAMES:
if env_config: env_config = os.getenv(varname)
try: if env_config:
config_p.read_string(env_config) try:
except configparser.Error as err: config_p.read_string(env_config)
raise Exception( except configparser.Error as err:
'SERVER_ENV_CONFIG content could not be parsed: %s' raise Exception(
% (err,) '%s content could not be parsed: %s'
) % (varname, err,)
)
return config_p return config_p