List roles for user on CLI (bug 932282)

Change-Id: I947d2ff74b0a131e4ecc7d696877aea4d994fe71
This commit is contained in:
Dolph Mathews
2012-03-09 09:59:34 -06:00
parent 6ce6ebbc96
commit 93d07cc793

View File

@@ -180,9 +180,21 @@ def do_service_delete(kc, args):
kc.services.delete(args.id) kc.services.delete(args.id)
@utils.arg('--user', metavar='<user-id>',
help='List roles granted to a user')
@utils.arg('--tenant_id', metavar='<tenant-id>',
help='List roles granted on a tenant')
def do_role_list(kc, args): def do_role_list(kc, args):
"""List all available roles""" """List all roles, or only those granted to a user."""
if bool(args.tenant_id) ^ bool(args.user):
print 'User ID and Tenant ID are both required to list granted roles.'
return
if args.tenant_id and args.user:
roles = kc.roles.roles_for_user(user=args.user, tenant=args.tenant_id)
else:
roles = kc.roles.list() roles = kc.roles.list()
utils.print_list(roles, ['id', 'name']) utils.print_list(roles, ['id', 'name'])