Fix listing and removing roles from users.

* Listing roles was failing due to a mismatch in returned data
and how it was being processed. Removed role id lookup for now,
so output only shows role names.
* Delete required json data, and this argument was missing.

Change-Id: I7b4ca739ae03443c0b2a885872f4b557a9998efb
This commit is contained in:
Dale Smith 2023-05-04 15:53:22 +12:00
parent 7af8c21284
commit db795e20ed
3 changed files with 8 additions and 7 deletions

View File

@ -198,12 +198,14 @@ class BaseManager(HookableMixin):
else:
return self.resource_class(self, body)
def _delete(self, url):
def _delete(self, url, json=None):
"""Delete an object.
:param url: a partial URL, e.g., '/servers/my-server'
:param json: data that will be encoded as JSON and sent with the
DELETE request.
"""
return self.client.delete(url)
return self.client.delete(url, json=json)
class ManagerWithFind(BaseManager, metaclass=abc.ABCMeta):

View File

@ -171,10 +171,8 @@ class UserRoleList(command.Lister):
client = self.app.client_manager.admin_logic
user = utils.find_resource(client.users, parsed_args.user)
kwargs = {'user': user.id}
roles = [[role.id, role.name] for role
in client.user_roles.list(**kwargs)]
return ['id', 'name'], roles
return ['name'], [[role] for role in user.roles]
class ManageableRolesList(command.Lister):

View File

@ -87,6 +87,7 @@ class UserRoleManager(base.BaseManager):
def remove(self, user_id, role=None, roles=None):
"""Remove a role or roles from a user"""
if role:
params = {
'roles': [role]
@ -99,7 +100,7 @@ class UserRoleManager(base.BaseManager):
route = '/openstack/users/%s/roles'
url = route % (user_id)
try:
self._delete(url, json=params, response_key=None)
self._delete(url, json=params)
except exc.HTTPBadRequest as e:
print(e.message)
return False