Add helper property to get the current user id

The data is available, but it's not the MOST straightforward thing to
find. We have helpers for project, add one for user.

Change-Id: I325d7f867796e9a24e02576a1363ea6b0fe7687b
This commit is contained in:
Monty Taylor 2017-11-13 18:13:02 -06:00
parent a446db5dce
commit 0b4ee33170
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 7 additions and 2 deletions

View File

@ -730,6 +730,12 @@ class OpenStackCloud(_normalize.Normalizer):
# We don't need to track validity here, just get_token() each time.
return self.keystone_session.get_token()
@property
def current_user_id(self):
"""Get the id of the currently logged-in user from the token."""
return self.keystone_session.auth.get_access(
self.keystone_session).user_id
@property
def current_project_id(self):
"""Get the current project ID.

View File

@ -62,8 +62,7 @@ class TestProject(base.KeystoneBaseFunctionalTestCase):
self.assertEqual(project_name, project['name'])
self.assertEqual('test_create_project', project['description'])
user_id = self.operator_cloud.keystone_session.auth.get_access(
self.operator_cloud.keystone_session).user_id
user_id = self.operator_cloud.current_user_id
# Grant the current user access to the project
self.assertTrue(self.operator_cloud.grant_role(