Merge "Password Mask for debug logs."

This commit is contained in:
Jenkins 2016-08-11 02:24:30 +00:00 committed by Gerrit Code Review
commit d9a5833938
4 changed files with 18 additions and 3 deletions

View File

@ -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},

View File

@ -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)

View File

@ -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())

View File

@ -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)