Merge "Allow fetching user_id/project_id from auth"

This commit is contained in:
Jenkins
2015-01-11 14:14:57 +00:00
committed by Gerrit Code Review
2 changed files with 36 additions and 0 deletions

View File

@@ -108,6 +108,36 @@ class BaseAuthPlugin(object):
"""
return False
def get_user_id(self, session, **kwargs):
"""Return a unique user identifier of the plugin.
Wherever possible the user id should be inferred from the token however
there are certain URLs and other places that require access to the
currently authenticated user id.
:param session: A session object so the plugin can make HTTP calls.
:type session: keystoneclient.session.Session
:returns: A user identifier or None if one is not available.
:rtype: str
"""
return None
def get_project_id(self, session, **kwargs):
"""Return the project id that we are authenticated to.
Wherever possible the project id should be inferred from the token
however there are certain URLs and other places that require access to
the currently authenticated project id.
:param session: A session object so the plugin can make HTTP calls.
:type session: keystoneclient.session.Session
:returns: A project identifier or None if one is not available.
:rtype: str
"""
return None
@classmethod
def get_options(cls):
"""Return the list of parameters associated with the auth plugin.

View File

@@ -236,6 +236,12 @@ class BaseIdentityPlugin(base.BaseAuthPlugin):
return url
def get_user_id(self, session, **kwargs):
return self.get_access(session).user_id
def get_project_id(self, session, **kwargs):
return self.get_access(session).project_id
@utils.positional()
def get_discovery(self, session, url, authenticated=None):
"""Return the discovery object for a URL.