Ignore all failures removing catalog when logging token

Operations could fail if the response was logged and had a 'token'
field that's not a dict. The fix is to ignore all errors when
trying to remove the service catalog from the response.

Also, enhanced the service catalog removal code to support V2
tokens.

Closes-Bug: 1420080
Change-Id: I35b971415744825e8e5f00f30dcf193d04ee699a
This commit is contained in:
Brant Knudson 2015-02-12 20:18:07 -06:00
parent f82f274f6b
commit 9ceb44c612
1 changed files with 13 additions and 8 deletions

View File

@ -57,16 +57,21 @@ def request(url, method='GET', **kwargs):
def remove_service_catalog(body): def remove_service_catalog(body):
try: try:
data = jsonutils.loads(body) data = jsonutils.loads(body)
except ValueError:
return body # V3 token
try: if 'token' in data and 'catalog' in data['token']:
if 'catalog' in data['token']:
data['token']['catalog'] = '<removed>' data['token']['catalog'] = '<removed>'
return jsonutils.dumps(data) return jsonutils.dumps(data)
else:
return body # V2 token
except KeyError: if 'serviceCatalog' in data['access']:
return body data['access']['serviceCatalog'] = '<removed>'
return jsonutils.dumps(data)
except Exception:
# Don't fail trying to clean up the request body.
pass
return body
class Session(object): class Session(object):