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
|
:rtype: string or None
|
||||||
"""
|
"""
|
||||||
# NOTE(jamielennox): if you specifically ask for requests to be sent to
|
# 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
|
# the auth url then we can ignore many of the checks. Typically if you
|
||||||
# you are asking for the auth endpoint it means that there is no
|
# are asking for the auth endpoint it means that there is no catalog to
|
||||||
# catalog to query anyway.
|
# 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:
|
if interface is base.AUTH_INTERFACE:
|
||||||
return self.auth_url
|
url = self.auth_url
|
||||||
|
service_type = service_type or 'identity'
|
||||||
|
|
||||||
if not service_type:
|
else:
|
||||||
LOG.warn(_LW('Plugin cannot return an endpoint without knowing '
|
if not service_type:
|
||||||
'the service type that is required. Add service_type '
|
LOG.warn(_LW('Plugin cannot return an endpoint without '
|
||||||
'to endpoint filtering data.'))
|
'knowing the service type that is required. Add '
|
||||||
return None
|
'service_type to endpoint filtering data.'))
|
||||||
|
return None
|
||||||
|
|
||||||
if not interface:
|
if not interface:
|
||||||
interface = 'public'
|
interface = 'public'
|
||||||
|
|
||||||
service_catalog = self.get_access(session).service_catalog
|
service_catalog = self.get_access(session).service_catalog
|
||||||
url = service_catalog.url_for(service_type=service_type,
|
url = service_catalog.url_for(service_type=service_type,
|
||||||
endpoint_type=interface,
|
endpoint_type=interface,
|
||||||
region_name=region_name,
|
region_name=region_name,
|
||||||
service_name=service_name)
|
service_name=service_name)
|
||||||
|
|
||||||
if not version:
|
if not version:
|
||||||
# NOTE(jamielennox): This may not be the best thing to default to
|
# 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)
|
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):
|
class GenericPlugin(base.BaseAuthPlugin):
|
||||||
|
|
||||||
|
@@ -114,9 +114,8 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(V3IdentityPlugin, self).setUp()
|
super(V3IdentityPlugin, self).setUp()
|
||||||
|
|
||||||
V3_URL = "%sv3" % self.TEST_URL
|
|
||||||
self.TEST_DISCOVERY_RESPONSE = {
|
self.TEST_DISCOVERY_RESPONSE = {
|
||||||
'versions': {'values': [fixture.V3Discovery(V3_URL)]}}
|
'versions': {'values': [fixture.V3Discovery(self.TEST_URL)]}}
|
||||||
|
|
||||||
self.TEST_RESPONSE_DICT = {
|
self.TEST_RESPONSE_DICT = {
|
||||||
"token": {
|
"token": {
|
||||||
|
Reference in New Issue
Block a user