From 008500197a82a0ec15822bf17a35c5a283c50910 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Wed, 2 Jan 2013 20:21:28 +1100 Subject: Sanitize cells calls. Cells puts the data to be sanitized deeper into the message. We should get this into oslo ready for when cells lands. Change-Id: Ic5d111f11c979a179e0edcb314feb3f9d93f66ce --- openstack/common/rpc/common.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'openstack') diff --git a/openstack/common/rpc/common.py b/openstack/common/rpc/common.py index a3a3699..7434a2d 100644 --- a/openstack/common/rpc/common.py +++ b/openstack/common/rpc/common.py @@ -212,8 +212,12 @@ class Connection(object): def _safe_log(log_func, msg, msg_data): """Sanitizes the msg_data field before logging.""" - SANITIZE = {'set_admin_password': ('new_pass',), - 'run_instance': ('admin_password',), } + SANITIZE = {'set_admin_password': [('args', 'new_pass')], + 'run_instance': [('args', 'admin_password')], + 'route_message': [('args', 'message', 'args', 'method_info', + 'method_kwargs', 'password'), + ('args', 'message', 'args', 'method_info', + 'method_kwargs', 'admin_password')]} has_method = 'method' in msg_data and msg_data['method'] in SANITIZE has_context_token = '_context_auth_token' in msg_data @@ -225,14 +229,16 @@ def _safe_log(log_func, msg, msg_data): msg_data = copy.deepcopy(msg_data) if has_method: - method = msg_data['method'] - if method in SANITIZE: - args_to_sanitize = SANITIZE[method] - for arg in args_to_sanitize: - try: - msg_data['args'][arg] = "" - except KeyError: - pass + for arg in SANITIZE.get(msg_data['method'], []): + try: + d = msg_data + for elem in arg[:-1]: + d = d[elem] + d[arg[-1]] = '' + except KeyError, e: + LOG.info(_('Failed to sanitize %(item)s. Key error %(err)s'), + {'item': arg, + 'err': e}) if has_context_token: msg_data['_context_auth_token'] = '' -- cgit