From 1f8a263fc49a7e9d2c926079f8fa106cf31bcf48 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 23 Jan 2013 15:50:00 +0100 Subject: [PATCH] Factorize endpoint retrieval in access Change-Id: Iaace7020696b238e7829dbcae60f0bc7c74a79e4 Signed-off-by: Julien Danjou --- keystoneclient/access.py | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/keystoneclient/access.py b/keystoneclient/access.py index 3947b6f10..b5c2eb004 100644 --- a/keystoneclient/access.py +++ b/keystoneclient/access.py @@ -134,6 +134,17 @@ class AccessInfo(dict): """ Synonym for project_id """ return self.tenant_id + def _get_identity_endpoint(self, endpoint_type): + if not self.get('serviceCatalog'): + return + + identity_services = [x for x in self['serviceCatalog'] + if x['type'] == 'identity'] + return tuple(endpoint[endpoint_type] + for svc in identity_services + for endpoint in svc['endpoints'] + if endpoint_type in endpoint) + @property def auth_url(self): """ Returns a tuple of URLs from publicURL and adminURL for the service @@ -143,17 +154,7 @@ class AccessInfo(dict): :returns: tuple of urls """ - return_list = [] - if 'serviceCatalog' in self and self['serviceCatalog']: - identity_services = [x for x in self['serviceCatalog'] - if x['type'] == 'identity'] - for svc in identity_services: - for endpoint in svc['endpoints']: - if 'publicURL' in endpoint: - return_list.append(endpoint['publicURL']) - if len(return_list) > 0: - return tuple(return_list) - return None + return self._get_identity_endpoint('publicURL') @property def management_url(self): @@ -163,14 +164,4 @@ class AccessInfo(dict): :returns: tuple of urls """ - return_list = [] - if 'serviceCatalog' in self and self['serviceCatalog']: - identity_services = [x for x in self['serviceCatalog'] - if x['type'] == 'identity'] - for svc in identity_services: - for endpoint in svc['endpoints']: - if 'adminURL' in endpoint: - return_list.append(endpoint['adminURL']) - if len(return_list) > 0: - return tuple(return_list) - return None + return self._get_identity_endpoint('adminURL')