Factorize endpoint retrieval in access

Change-Id: Iaace7020696b238e7829dbcae60f0bc7c74a79e4
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-01-23 15:50:00 +01:00
parent 2641c42117
commit e515eaad2b

View File

@ -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')