From 6ce6ebbc96ff5892c39aba2a91e660c300d0f512 Mon Sep 17 00:00:00 2001 From: termie Date: Wed, 7 Mar 2012 11:55:35 -0800 Subject: [PATCH] prevent keyerrors when accessing optional keys You used to have these in the token, why were they removed and then subsequently grabbed at? The change that added these doesn't work against keystone, btw, so I'm surprised it got in, these dict keys are not required to be in the return from service_catalog.get_token() and adding them as properties is only going to make matters worse as people rarely think about having None attributes. Change-Id: I695bbd6730d25d8db3a25cea81e3ffb0ef289bbb --- keystoneclient/v2_0/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/keystoneclient/v2_0/client.py b/keystoneclient/v2_0/client.py index fb59ffc27..2780b6d0c 100644 --- a/keystoneclient/v2_0/client.py +++ b/keystoneclient/v2_0/client.py @@ -116,8 +116,10 @@ class Client(client.HTTPClient): sc = self.service_catalog.get_token() self.auth_token = sc['id'] # Save these since we have them and they'll be useful later - self.auth_tenant_id = sc['tenant_id'] - self.auth_user_id = sc['user_id'] + # NOTE(termie): these used to be in the token and then were removed + # ... why? + self.auth_tenant_id = sc.get('tenant_id') + self.auth_user_id = sc.get('user_id') except KeyError: raise exceptions.AuthorizationFailure()