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
This commit is contained in:
@@ -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
|
||||
|
@@ -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):
|
||||
|
||||
|
@@ -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": {
|
||||
|
Reference in New Issue
Block a user