[REF] Server Environment: allow to define secret keys

New method defining which keys must be considered as secret keys and be hidden in other environments than DEV
This commit is contained in:
Thomas Binsfeld 2018-10-08 11:48:18 +02:00 committed by Yannick Vaucher
parent 041db8b97f
commit a5c0e7bc76
1 changed files with 13 additions and 4 deletions

View File

@ -24,7 +24,7 @@ import configparser
from lxml import etree from lxml import etree
from itertools import chain from itertools import chain
from odoo import api, fields, models from odoo import api, models, fields
from odoo.tools.config import config as system_base_config from odoo.tools.config import config as system_base_config
from .system_info import get_server_environment from .system_info import get_server_environment
@ -283,16 +283,25 @@ class ServerConfiguration(models.TransientModel):
res['fields'] = xfields res['fields'] = xfields
return res return res
@api.model
def _is_secret(self, key):
"""
This method is intended to be inherited to defined which keywords
should be secret.
:return: list of secret keywords
"""
secret_keys = ['passw', 'key', 'secret', 'token']
return any(secret_key in key for secret_key in secret_keys)
@api.model @api.model
def default_get(self, fields_list): def default_get(self, fields_list):
res = {} res = {}
current_user = self.pool['res.users'].browse( current_user = self.env.user
cr, uid, uid, context=context)
if not current_user.has_group( if not current_user.has_group(
'server_environment.has_server_configuration_access'): 'server_environment.has_server_configuration_access'):
return res return res
for key in self._conf_defaults: for key in self._conf_defaults:
if 'passw' in key and not self.show_passwords: if not self.show_passwords and self._is_secret(key=key):
res[key] = '**********' res[key] = '**********'
else: else:
res[key] = self._conf_defaults[key]() res[key] = self._conf_defaults[key]()