Implement caching for the generic plugins.
When caching was implemented it was added to the v2 and v3 plugins but for some reason the generic plugins were missed. To do generic plugin caching we'll skip even trying to figure out the inner plugin for now and just load the authentication for the generic. Closes-Bug: #1616261 Change-Id: Icbb8acde0dca084f4a221f8ebff5503d5bdc219a
This commit is contained in:
parent
1004db07b7
commit
01b7c87285
@ -98,17 +98,30 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
|
||||
@property
|
||||
def _v3_params(self):
|
||||
"""Return the parameters that are common to v3 plugins."""
|
||||
pr_domain_id = self._project_domain_id or self._default_domain_id
|
||||
pr_domain_name = self._project_domain_name or self._default_domain_name
|
||||
|
||||
return {'trust_id': self._trust_id,
|
||||
'project_id': self._project_id,
|
||||
'project_name': self._project_name,
|
||||
'project_domain_id': pr_domain_id,
|
||||
'project_domain_name': pr_domain_name,
|
||||
'project_domain_id': self.project_domain_id,
|
||||
'project_domain_name': self.project_domain_name,
|
||||
'domain_id': self._domain_id,
|
||||
'domain_name': self._domain_name}
|
||||
|
||||
@property
|
||||
def project_domain_id(self):
|
||||
return self._project_domain_id or self._default_domain_id
|
||||
|
||||
@project_domain_id.setter
|
||||
def project_domain_id(self, value):
|
||||
self._project_domain_id = value
|
||||
|
||||
@property
|
||||
def project_domain_name(self):
|
||||
return self._project_domain_name or self._default_domain_name
|
||||
|
||||
@project_domain_name.setter
|
||||
def project_domain_name(self, value):
|
||||
self._project_domain_name = value
|
||||
|
||||
def _do_create_plugin(self, session):
|
||||
plugin = None
|
||||
|
||||
@ -179,3 +192,20 @@ class BaseGenericPlugin(base.BaseIdentityPlugin):
|
||||
self._plugin = self._do_create_plugin(session)
|
||||
|
||||
return self._plugin.get_auth_ref(session, **kwargs)
|
||||
|
||||
def get_cache_id_elements(self, _implemented=False):
|
||||
# NOTE(jamielennox): implemented here is just a way to make sure that
|
||||
# something overrides this method. We don't want the base
|
||||
# implementation to respond with a dict without the subclass modifying
|
||||
# it to add their own data in case the subclass doesn't support caching
|
||||
if not _implemented:
|
||||
raise NotImplemented()
|
||||
|
||||
return {'auth_url': self.auth_url,
|
||||
'project_id': self._project_id,
|
||||
'project_name': self._project_name,
|
||||
'project_domain_id': self.project_domain_id,
|
||||
'project_domain_name': self.project_domain_name,
|
||||
'domain_id': self._domain_id,
|
||||
'domain_name': self._domain_name,
|
||||
'trust_id': self._trust_id}
|
||||
|
@ -62,3 +62,29 @@ class Password(base.BaseGenericPlugin):
|
||||
user_domain_name=u_domain_name,
|
||||
password=self._password,
|
||||
**self._v3_params)
|
||||
|
||||
@property
|
||||
def user_domain_id(self):
|
||||
return self._user_domain_id or self._default_domain_id
|
||||
|
||||
@user_domain_id.setter
|
||||
def user_domain_id(self, value):
|
||||
self._user_domain_id = value
|
||||
|
||||
@property
|
||||
def user_domain_name(self):
|
||||
return self._user_domain_name or self._default_domain_name
|
||||
|
||||
@user_domain_name.setter
|
||||
def user_domain_name(self, value):
|
||||
self._user_domain_name = value
|
||||
|
||||
def get_cache_id_elements(self):
|
||||
elements = super(Password, self).get_cache_id_elements(
|
||||
_implemented=True)
|
||||
elements['username'] = self._username
|
||||
elements['user_id'] = self._user_id
|
||||
elements['password'] = self._password
|
||||
elements['user_domain_id'] = self.user_domain_id
|
||||
elements['user_domain_name'] = self.user_domain_name
|
||||
return elements
|
||||
|
@ -32,3 +32,8 @@ class Token(base.BaseGenericPlugin):
|
||||
|
||||
elif discover.version_match((3,), version):
|
||||
return v3.Token(url, self._token, **self._v3_params)
|
||||
|
||||
def get_cache_id_elements(self):
|
||||
elements = super(Token, self).get_cache_id_elements(_implemented=True)
|
||||
elements['token'] = self._token
|
||||
return elements
|
||||
|
@ -71,3 +71,36 @@ class PasswordTests(utils.GenericPluginTestCase):
|
||||
|
||||
self.assertEqual(default_domain_name,
|
||||
p._plugin.auth_methods[0].user_domain_name)
|
||||
|
||||
def test_password_cache_id(self):
|
||||
username = uuid.uuid4().hex
|
||||
the_password = uuid.uuid4().hex
|
||||
project_name = uuid.uuid4().hex
|
||||
default_domain_id = uuid.uuid4().hex
|
||||
|
||||
a = password.Password(self.TEST_URL,
|
||||
username=username,
|
||||
password=the_password,
|
||||
project_name=project_name,
|
||||
default_domain_id=default_domain_id)
|
||||
|
||||
b = password.Password(self.TEST_URL,
|
||||
username=username,
|
||||
password=the_password,
|
||||
project_name=project_name,
|
||||
default_domain_id=default_domain_id)
|
||||
|
||||
a_id = a.get_cache_id()
|
||||
b_id = b.get_cache_id()
|
||||
|
||||
self.assertEqual(a_id, b_id)
|
||||
|
||||
c = password.Password(self.TEST_URL,
|
||||
username=username,
|
||||
password=uuid.uuid4().hex, # different
|
||||
project_name=project_name,
|
||||
default_domain_id=default_domain_id)
|
||||
|
||||
c_id = c.get_cache_id()
|
||||
|
||||
self.assertNotEqual(a_id, c_id)
|
||||
|
@ -32,3 +32,32 @@ class TokenTests(utils.GenericPluginTestCase):
|
||||
def test_symbols(self):
|
||||
self.assertIs(v3.Token, v3_token.Token)
|
||||
self.assertIs(v3.TokenMethod, v3_token.TokenMethod)
|
||||
|
||||
def test_token_cache_id(self):
|
||||
the_token = uuid.uuid4().hex
|
||||
project_name = uuid.uuid4().hex
|
||||
default_domain_id = uuid.uuid4().hex
|
||||
|
||||
a = token.Token(self.TEST_URL,
|
||||
token=the_token,
|
||||
project_name=project_name,
|
||||
default_domain_id=default_domain_id)
|
||||
|
||||
b = token.Token(self.TEST_URL,
|
||||
token=the_token,
|
||||
project_name=project_name,
|
||||
default_domain_id=default_domain_id)
|
||||
|
||||
a_id = a.get_cache_id()
|
||||
b_id = b.get_cache_id()
|
||||
|
||||
self.assertEqual(a_id, b_id)
|
||||
|
||||
c = token.Token(self.TEST_URL,
|
||||
token=the_token,
|
||||
project_name=uuid.uuid4().hex, # different
|
||||
default_domain_id=default_domain_id)
|
||||
|
||||
c_id = c.get_cache_id()
|
||||
|
||||
self.assertNotEqual(a_id, c_id)
|
||||
|
Loading…
Reference in New Issue
Block a user