From fd16240be482b4841dfafeee404f3a8e2678333e Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Mon, 30 Mar 2015 15:51:49 +1100 Subject: [PATCH] Support discovery on the AUTH_INTERFACE We need to allow get_endpoint(interface=auth.AUTH_INTERFACE, version=X) to support the same version negotiation that the service catalog goes through. This is required to support generic plugins where you often provide an unversioned auth_url to the plugin but need a versioned URL to query for available projects. Change-Id: Id423a538c169264a81c5714e6a9eff9b33912a55 Closes-Bug: #1438013 --- keystoneclient/auth/identity/base.py | 35 ++++++++++--------- .../tests/unit/auth/test_identity_common.py | 30 ++++++++++++++++ .../tests/unit/auth/test_identity_v3.py | 3 +- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/keystoneclient/auth/identity/base.py b/keystoneclient/auth/identity/base.py index d8cd2a6a..d50463d5 100644 --- a/keystoneclient/auth/identity/base.py +++ b/keystoneclient/auth/identity/base.py @@ -197,26 +197,29 @@ class BaseIdentityPlugin(base.BaseAuthPlugin): :rtype: string or None """ # NOTE(jamielennox): if you specifically ask for requests to be sent to - # the auth url then we can ignore the rest of the checks. Typically if - # you are asking for the auth endpoint it means that there is no - # catalog to query anyway. + # the auth url then we can ignore many of the checks. Typically if you + # are asking for the auth endpoint it means that there is no catalog to + # query however we still need to support asking for a specific version + # of the auth_url for generic plugins. if interface is base.AUTH_INTERFACE: - return self.auth_url + url = self.auth_url + service_type = service_type or 'identity' - if not service_type: - LOG.warn(_LW('Plugin cannot return an endpoint without knowing ' - 'the service type that is required. Add service_type ' - 'to endpoint filtering data.')) - return None + else: + if not service_type: + LOG.warn(_LW('Plugin cannot return an endpoint without ' + 'knowing the service type that is required. Add ' + 'service_type to endpoint filtering data.')) + return None - if not interface: - interface = 'public' + if not interface: + interface = 'public' - service_catalog = self.get_access(session).service_catalog - url = service_catalog.url_for(service_type=service_type, - endpoint_type=interface, - region_name=region_name, - service_name=service_name) + service_catalog = self.get_access(session).service_catalog + url = service_catalog.url_for(service_type=service_type, + endpoint_type=interface, + region_name=region_name, + service_name=service_name) if not version: # NOTE(jamielennox): This may not be the best thing to default to diff --git a/keystoneclient/tests/unit/auth/test_identity_common.py b/keystoneclient/tests/unit/auth/test_identity_common.py index 3bf04c79..1f88250c 100644 --- a/keystoneclient/tests/unit/auth/test_identity_common.py +++ b/keystoneclient/tests/unit/auth/test_identity_common.py @@ -368,6 +368,36 @@ class CatalogHackTests(utils.TestCase): self.assertEqual(self.V2_URL, endpoint) + def test_getting_endpoints_on_auth_interface(self): + disc = fixture.DiscoveryList(href=self.BASE_URL) + self.stub_url('GET', + ['/'], + base_url=self.BASE_URL, + status_code=300, + json=disc) + + token = fixture.V2Token() + service = token.add_service(self.IDENTITY) + service.add_endpoint(public=self.V2_URL, + admin=self.V2_URL, + internal=self.V2_URL) + + self.stub_url('POST', + ['tokens'], + base_url=self.V2_URL, + json=token) + + v2_auth = identity.V2Password(self.V2_URL, + username=uuid.uuid4().hex, + password=uuid.uuid4().hex) + + sess = session.Session(auth=v2_auth) + + endpoint = sess.get_endpoint(interface=base.AUTH_INTERFACE, + version=(3, 0)) + + self.assertEqual(self.V3_URL, endpoint) + class GenericPlugin(base.BaseAuthPlugin): diff --git a/keystoneclient/tests/unit/auth/test_identity_v3.py b/keystoneclient/tests/unit/auth/test_identity_v3.py index c01b39f1..932090d8 100644 --- a/keystoneclient/tests/unit/auth/test_identity_v3.py +++ b/keystoneclient/tests/unit/auth/test_identity_v3.py @@ -114,9 +114,8 @@ class V3IdentityPlugin(utils.TestCase): def setUp(self): super(V3IdentityPlugin, self).setUp() - V3_URL = "%sv3" % self.TEST_URL self.TEST_DISCOVERY_RESPONSE = { - 'versions': {'values': [fixture.V3Discovery(V3_URL)]}} + 'versions': {'values': [fixture.V3Discovery(self.TEST_URL)]}} self.TEST_RESPONSE_DICT = { "token": {