From 7efad045fbb07d669e835232ffb473a16a8a0b50 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Wed, 3 Sep 2014 12:51:26 +1000 Subject: [PATCH] Allow fetching user_id/project_id from auth This would ideally not be required however when building certain URLs the current user_id is needed. And when communicating with certain services we need to have access to the current project id. It seems better to allow plugins to give up the information if they have it than do various hacks to try and get it from them. Change-Id: Ib61b0628702806268be623a9987a922a60b04165 Closes-Bug: #1364724 --- keystoneclient/auth/base.py | 30 ++++++++++++++++++++++++++++ keystoneclient/auth/identity/base.py | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/keystoneclient/auth/base.py b/keystoneclient/auth/base.py index 4c743d9..ecbcf96 100644 --- a/keystoneclient/auth/base.py +++ b/keystoneclient/auth/base.py @@ -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. diff --git a/keystoneclient/auth/identity/base.py b/keystoneclient/auth/identity/base.py index 94b0712..610039a 100644 --- a/keystoneclient/auth/identity/base.py +++ b/keystoneclient/auth/identity/base.py @@ -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.