From db795e20ed202ca45c136b5aa3286537c0804f4e Mon Sep 17 00:00:00 2001 From: Dale Smith Date: Thu, 4 May 2023 15:53:22 +1200 Subject: [PATCH] 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 --- adjutantclient/common/base.py | 6 ++++-- adjutantclient/osc/v1/users.py | 6 ++---- adjutantclient/v1/roles.py | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/adjutantclient/common/base.py b/adjutantclient/common/base.py index a60bfeb..2f3d834 100644 --- a/adjutantclient/common/base.py +++ b/adjutantclient/common/base.py @@ -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): diff --git a/adjutantclient/osc/v1/users.py b/adjutantclient/osc/v1/users.py index 520e83b..5493778 100644 --- a/adjutantclient/osc/v1/users.py +++ b/adjutantclient/osc/v1/users.py @@ -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): diff --git a/adjutantclient/v1/roles.py b/adjutantclient/v1/roles.py index 3a95887..a113747 100644 --- a/adjutantclient/v1/roles.py +++ b/adjutantclient/v1/roles.py @@ -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