diff options
| author | Qiu Yu <qiuyu@ebaysf.com> | 2014-01-29 22:54:01 +0800 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2014-06-13 15:20:42 -0500 |
| commit | f78a3f1653c634e40071fb96750b9ca64865c058 (patch) | |
| tree | 2417adb17de522485924cc0adc90cce796006ceb /openstackclient/identity/v3/user.py | |
| parent | 7f6a901d011ae366a5dea6fa7e532ab941125e9e (diff) | |
| download | python-openstackclient-f78a3f1653c634e40071fb96750b9ca64865c058.tar.gz | |
Refactor role list subcommand for identity v3 api
Currently parts of user list and group list command are actually
functioning as role listing, which is quite counter intuitive and
misleading.
This refactor change move role related logic to a single place of role
list command. It now allows role grants listing for user/group +
domain/project combinations.
If no user or group specified, it will list all roles in the system,
which is the default behaviour.
Change-Id: I4ced6df4b76f018d01000d28b4281ad9f252ffcc
Diffstat (limited to 'openstackclient/identity/v3/user.py')
| -rw-r--r-- | openstackclient/identity/v3/user.py | 87 |
1 files changed, 7 insertions, 80 deletions
diff --git a/openstackclient/identity/v3/user.py b/openstackclient/identity/v3/user.py index e628e884..c4adb225 100644 --- a/openstackclient/identity/v3/user.py +++ b/openstackclient/identity/v3/user.py @@ -17,7 +17,6 @@ import logging import six -import sys from cliff import command from cliff import lister @@ -162,23 +161,6 @@ class ListUser(lister.Lister): help='Name or ID of user to list [required with --role]', ) parser.add_argument( - '--role', - action='store_true', - default=False, - help='List the roles assigned to <user>', - ) - domain_or_project = parser.add_mutually_exclusive_group() - domain_or_project.add_argument( - '--domain', - metavar='<domain>', - help='Filter list by <domain> [Only valid with --role]', - ) - domain_or_project.add_argument( - '--project', - metavar='<project>', - help='Filter list by <project> [Only valid with --role]', - ) - parser.add_argument( '--long', action='store_true', default=False, @@ -187,70 +169,15 @@ class ListUser(lister.Lister): return parser def take_action(self, parsed_args): - self.log.debug('take_action(%s)', parsed_args) - identity_client = self.app.client_manager.identity + self.log.debug('take_action(%s)' % parsed_args) - if parsed_args.role: - # List roles belonging to user - - # User is required here, bail if it is not supplied - if not parsed_args.user: - sys.stderr.write('Error: User must be specified') - return ([], []) - - user = utils.find_resource( - identity_client.users, - parsed_args.user, - ) - - # List a user's roles - if not parsed_args.domain and not parsed_args.project: - columns = ('ID', 'Name') - data = identity_client.roles.list( - user=user, - domain='default', - ) - # List a user's roles on a domain - elif parsed_args.user and parsed_args.domain: - columns = ('ID', 'Name', 'Domain', 'User') - domain = utils.find_resource( - identity_client.domains, - parsed_args.domain, - ) - data = identity_client.roles.list( - user=user, - domain=domain, - ) - for user_role in data: - user_role.user = user.name - user_role.domain = domain.name - # List a user's roles on a project - elif parsed_args.user and parsed_args.project: - columns = ('ID', 'Name', 'Project', 'User') - project = utils.find_resource( - identity_client.projects, - parsed_args.project, - ) - data = identity_client.roles.list( - user=user, - project=project, - ) - for user_role in data: - user_role.user = user.name - user_role.project = project.name - else: - # TODO(dtroyer): raise exception here, this really is an error - sys.stderr.write("Error: Must specify --domain or --project " - "with --role\n") - return ([], []) + # List users + if parsed_args.long: + columns = ('ID', 'Name', 'Project Id', 'Domain Id', + 'Description', 'Email', 'Enabled') else: - # List users - if parsed_args.long: - columns = ('ID', 'Name', 'Project Id', 'Domain Id', - 'Description', 'Email', 'Enabled') - else: - columns = ('ID', 'Name') - data = self.app.client_manager.identity.users.list() + columns = ('ID', 'Name') + data = self.app.client_manager.identity.users.list() return (columns, (utils.get_item_properties( |
