diff options
author | Jamie Lennox <jamielennox@redhat.com> | 2014-10-30 15:12:05 +0100 |
---|---|---|
committer | Jamie Lennox <jamielennox@redhat.com> | 2015-01-23 10:41:07 +1000 |
commit | 496a0efc43c40fb030b62f3ed632ee50659a9b41 (patch) | |
tree | 1d2fce86dc5fbb5fc3b36c9ce643be2f332a752b /keystoneclient/adapter.py | |
parent | eaab62aca5f570bd119b4c602db7845a017c958e (diff) | |
download | python-keystoneclient-496a0efc43c40fb030b62f3ed632ee50659a9b41.tar.gz |
Surface the user_id and project_id beyond the plugin
Having the user_id and project_id exposed in the plugin is a good first
step however we don't really expect the user to be interacting with the
plugins directly often - particularly as you need to pass session to the
methods.
Exposing get_user_id and get_project_id on the session and the adapter
in this way is very similar to the way we expose get_token and
get_endpoint on the session and adapter for use higher up.
Related-Bug: #1364724
Change-Id: If2f868c3ddc19133f18446e74f8e1b560a4798fa
Diffstat (limited to 'keystoneclient/adapter.py')
-rw-r--r-- | keystoneclient/adapter.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/keystoneclient/adapter.py b/keystoneclient/adapter.py index ea0d342..e14ce7d 100644 --- a/keystoneclient/adapter.py +++ b/keystoneclient/adapter.py @@ -126,6 +126,40 @@ class Adapter(object): """Invalidate an authentication plugin.""" return self.session.invalidate(auth or self.auth) + def get_user_id(self, auth=None): + """Return the authenticated user_id as provided by the auth plugin. + + :param auth: The auth plugin to use for token. Overrides the plugin + on the session. (optional) + :type auth: keystoneclient.auth.base.BaseAuthPlugin + + :raises keystoneclient.exceptions.AuthorizationFailure: + if a new token fetch fails. + :raises keystoneclient.exceptions.MissingAuthPlugin: + if a plugin is not available. + + :returns: Current `user_id` or None if not supported by plugin. + :rtype: string + """ + return self.session.get_user_id(auth or self.auth) + + def get_project_id(self, auth=None): + """Return the authenticated project_id as provided by the auth plugin. + + :param auth: The auth plugin to use for token. Overrides the plugin + on the session. (optional) + :type auth: keystoneclient.auth.base.BaseAuthPlugin + + :raises keystoneclient.exceptions.AuthorizationFailure: + if a new token fetch fails. + :raises keystoneclient.exceptions.MissingAuthPlugin: + if a plugin is not available. + + :returns: Current `project_id` or None if not supported by plugin. + :rtype: string + """ + return self.session.get_project_id(auth or self.auth) + def get(self, url, **kwargs): return self.request(url, 'GET', **kwargs) |