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):
try:
data = jsonutils.loads(body)
except ValueError:
return body
try:
if 'catalog' in data['token']:
# V3 token
if 'token' in data and 'catalog' in data['token']:
data['token']['catalog'] = '<removed>'
return jsonutils.dumps(data)
else:
return body
except KeyError:
return body
# V2 token
if 'serviceCatalog' in data['access']:
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):