Merge "Password Mask for debug logs."
This commit is contained in:
commit
d9a5833938
@ -18,6 +18,7 @@ from six import iteritems
|
||||
import webob.exc
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import strutils
|
||||
|
||||
from tacker.api import api_common
|
||||
from tacker.api.v1 import attributes
|
||||
@ -505,7 +506,8 @@ class Controller(object):
|
||||
if not body:
|
||||
raise webob.exc.HTTPBadRequest(_("Resource body required"))
|
||||
|
||||
LOG.debug(_("Request body: %(body)s"), {'body': body})
|
||||
LOG.debug(_("Request body: %(body)s"), {'body':
|
||||
strutils.mask_password(body)})
|
||||
prep_req_body = lambda x: Controller.prepare_request_body(
|
||||
context,
|
||||
x if resource in x else {resource: x},
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""Log helper functions."""
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import strutils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -27,7 +28,8 @@ def log(method):
|
||||
data = {"class_name": (instance.__class__.__module__ + '.'
|
||||
+ instance.__class__.__name__),
|
||||
"method_name": method.__name__,
|
||||
"args": args[1:], "kwargs": kwargs}
|
||||
"args": strutils.mask_password(args[1:]),
|
||||
"kwargs": strutils.mask_password(kwargs)}
|
||||
LOG.debug(_('%(class_name)s method %(method_name)s'
|
||||
' called with arguments %(args)s %(kwargs)s'), data)
|
||||
return method(*args, **kwargs)
|
||||
|
@ -21,6 +21,7 @@ import uuid
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import strutils
|
||||
|
||||
from tacker.common import driver_manager
|
||||
from tacker.common import log
|
||||
@ -77,7 +78,8 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb):
|
||||
|
||||
@log.log
|
||||
def create_vim(self, context, vim):
|
||||
LOG.debug(_('Create vim called with parameters %s'), vim)
|
||||
LOG.debug(_('Create vim called with parameters %s'),
|
||||
strutils.mask_password(vim))
|
||||
vim_obj = vim['vim']
|
||||
vim_type = vim_obj['type']
|
||||
vim_obj['id'] = str(uuid.uuid4())
|
||||
|
@ -68,3 +68,12 @@ class TestCallLog(base.BaseTestCase):
|
||||
self.klass.test_method(10, arg2=20, arg3=30, arg4=40)
|
||||
log_debug.assert_called_once_with(self.expected_format,
|
||||
self.expected_data)
|
||||
|
||||
def test_call_log_password_mask_args_kwargs(self):
|
||||
auth_cred = {'userame': 'demo', 'password': 'changeit'}
|
||||
self.expected_data['kwargs'] = {'password': '***'}
|
||||
self.expected_data['args'] = ({'userame': 'demo', 'password': '***'})
|
||||
with mock.patch.object(call_log.LOG, 'debug') as log_debug:
|
||||
self.klass.test_method(auth_cred, password='guessme')
|
||||
log_debug.assert_called_once_with(self.expected_format,
|
||||
self.expected_data)
|
||||
|
Loading…
Reference in New Issue
Block a user