Merge "Use oslo_utils to mask password in logs"

This commit is contained in:
Jenkins 2017-06-12 18:27:14 +00:00 committed by Gerrit Code Review
commit c8bc9b35c0

View File

@ -12,12 +12,12 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import re
import time import time
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import strutils
import six import six
import xml.etree.ElementTree as et import xml.etree.ElementTree as et
@ -124,27 +124,18 @@ class Vcns(object):
self._nsx_version = None self._nsx_version = None
self._normalized_scoping_objects = None self._normalized_scoping_objects = None
def _log_request(self, method, uri, body, format):
if format == 'json':
pattern = r'\"password\": [^,}]*'
body = re.sub(pattern,
'"password": "********"', body)
else:
pattern = r'<password>.*?</password>'
body = re.sub(pattern,
'<password>********</password>', body)
LOG.debug("VcnsApiHelper('%(method)s', '%(uri)s', '%(body)s')", {
'method': method,
'uri': uri,
'body': body})
@retry_upon_exception(exceptions.ServiceConflict) @retry_upon_exception(exceptions.ServiceConflict)
def _client_request(self, client, method, uri, def _client_request(self, client, method, uri,
params, headers, encodeParams): params, headers, encodeParams):
return client(method, uri, params, headers, encodeParams) return client(method, uri, params, headers, encodeParams)
def do_request(self, method, uri, params=None, format='json', **kwargs): def do_request(self, method, uri, params=None, format='json', **kwargs):
self._log_request(method, uri, jsonutils.dumps(params), format) msg = ("VcnsApiHelper('%(method)s', '%(uri)s', '%(body)s')" %
{'method': method,
'uri': uri,
'body': jsonutils.dumps(params)})
LOG.debug(strutils.mask_password(msg))
headers = kwargs.get('headers') headers = kwargs.get('headers')
encodeParams = kwargs.get('encode', True) encodeParams = kwargs.get('encode', True)
if format == 'json': if format == 'json':