Merge "safe_log Sanitize Passwords in List of Dicts"
This commit is contained in:
commit
84f18e8167
@ -27,6 +27,7 @@ from oslo import messaging
|
|||||||
from oslo.messaging._i18n import _
|
from oslo.messaging._i18n import _
|
||||||
from oslo.messaging import _utils as utils
|
from oslo.messaging import _utils as utils
|
||||||
from oslo.serialization import jsonutils
|
from oslo.serialization import jsonutils
|
||||||
|
from oslo.utils import strutils
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -70,8 +71,6 @@ _MESSAGE_KEY = 'oslo.message'
|
|||||||
|
|
||||||
_REMOTE_POSTFIX = '_Remote'
|
_REMOTE_POSTFIX = '_Remote'
|
||||||
|
|
||||||
_SANITIZE = ['_context_auth_token', 'auth_token', 'new_pass']
|
|
||||||
|
|
||||||
|
|
||||||
class RPCException(Exception):
|
class RPCException(Exception):
|
||||||
msg_fmt = _("An unknown RPC related exception occurred.")
|
msg_fmt = _("An unknown RPC related exception occurred.")
|
||||||
@ -162,22 +161,9 @@ class Connection(object):
|
|||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
def _fix_passwords(d):
|
|
||||||
"""Sanitizes the password fields in the dictionary."""
|
|
||||||
for k in six.iterkeys(d):
|
|
||||||
if k.lower().find('password') != -1:
|
|
||||||
d[k] = '<SANITIZED>'
|
|
||||||
elif k.lower() in _SANITIZE:
|
|
||||||
d[k] = '<SANITIZED>'
|
|
||||||
elif isinstance(d[k], dict):
|
|
||||||
_fix_passwords(d[k])
|
|
||||||
|
|
||||||
return d
|
|
||||||
|
|
||||||
|
|
||||||
def _safe_log(log_func, msg, msg_data):
|
def _safe_log(log_func, msg, msg_data):
|
||||||
"""Sanitizes the msg_data field before logging."""
|
"""Sanitizes the msg_data field before logging."""
|
||||||
return log_func(msg, _fix_passwords(copy.deepcopy(msg_data)))
|
return log_func(msg, strutils.mask_password(six.text_type(msg_data)))
|
||||||
|
|
||||||
|
|
||||||
def serialize_remote_exception(failure_info, log_failure=True):
|
def serialize_remote_exception(failure_info, log_failure=True):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user