diff options
author | Dolph Mathews <dolph.mathews@gmail.com> | 2012-09-06 08:15:06 -0500 |
---|---|---|
committer | Dolph Mathews <dolph.mathews@gmail.com> | 2012-09-06 11:12:05 -0500 |
commit | b6e568ede0d5e7abae69b28920f33f95be6190b5 (patch) | |
tree | 3643635b24e2b35786a95a71df7fa3d3a367a30d /keystone | |
parent | a9ee611c434556f1406255f4e002f894196301ff (diff) | |
download | keystone-b6e568ede0d5e7abae69b28920f33f95be6190b5.tar.gz keystone-b6e568ede0d5e7abae69b28920f33f95be6190b5.tar.xz keystone-b6e568ede0d5e7abae69b28920f33f95be6190b5.zip |
Implement token endpoint list (bug 1006777)
Change-Id: Ia7dad06ec763994ce0beb171c481ab01c20af6cb
Diffstat (limited to 'keystone')
-rw-r--r-- | keystone/catalog/backends/sql.py | 1 | ||||
-rw-r--r-- | keystone/service.py | 51 |
2 files changed, 51 insertions, 1 deletions
diff --git a/keystone/catalog/backends/sql.py b/keystone/catalog/backends/sql.py index c47d337a..bd0f687c 100644 --- a/keystone/catalog/backends/sql.py +++ b/keystone/catalog/backends/sql.py @@ -158,6 +158,7 @@ class Catalog(sql.Base, catalog.Driver): internal_url = ep['internalurl'].replace('$(', '%(') public_url = ep['publicurl'].replace('$(', '%(') admin_url = ep['adminurl'].replace('$(', '%(') + catalog[region][srv_type]['id'] = ep['id'] catalog[region][srv_type]['name'] = srv_name catalog[region][srv_type]['publicURL'] = public_url % d catalog[region][srv_type]['adminURL'] = admin_url % d diff --git a/keystone/service.py b/keystone/service.py index ddc9e4a7..59e9d434 100644 --- a/keystone/service.py +++ b/keystone/service.py @@ -543,7 +543,19 @@ class TokenController(wsgi.Application): def endpoints(self, context, token_id): """Return a list of endpoints available to the token.""" - raise exception.NotImplemented() + self.assert_admin(context) + + token_ref = self._get_token_ref(context, token_id) + + catalog_ref = None + if token_ref.get('tenant'): + catalog_ref = self.catalog_api.get_catalog( + context=context, + user_id=token_ref['user']['id'], + tenant_id=token_ref['tenant']['id'], + metadata=token_ref['metadata']) + + return self._format_endpoint_list(catalog_ref) def _format_authenticate(self, token_ref, roles_ref, catalog_ref): o = self._format_token(token_ref, roles_ref) @@ -629,6 +641,43 @@ class TokenController(wsgi.Application): return services.values() + def _format_endpoint_list(self, catalog_ref): + """Formats a list of endpoints according to Identity API v2. + + The v2.0 API wants an endpoint list to look like:: + + { + 'endpoints': [ + { + 'id': $endpoint_id, + 'name': $SERVICE[name], + 'type': $SERVICE, + 'tenantId': $tenant_id, + 'region': $REGION, + } + ], + 'endpoints_links': [], + } + + """ + if not catalog_ref: + return {} + + endpoints = [] + for region_name, region_ref in catalog_ref.iteritems(): + for service_type, service_ref in region_ref.iteritems(): + endpoints.append({ + 'id': service_ref.get('id'), + 'name': service_ref.get('name'), + 'type': service_type, + 'region': region_name, + 'publicURL': service_ref.get('publicURL'), + 'internalURL': service_ref.get('internalURL'), + 'adminURL': service_ref.get('adminURL'), + }) + + return {'endpoints': endpoints, 'endpoints_links': []} + class ExtensionsController(wsgi.Application): """Base extensions controller to be extended by public and admin API's.""" |