Skip to content

Commit

Permalink
dashboard/rgw: changes to use 'full_user_id' from rgw
Browse files Browse the repository at this point in the history
user info as 'uid' in dashboard. 'full_user_id' includes
tenant and user id, and also namespace wherever it is non
empty.

Signed-off-by: Pritha Srivastava <[email protected]>
Reviewed-by: Nizamudeen A <[email protected]>
  • Loading branch information
pritha-srivastava committed Feb 13, 2024
1 parent 9b31e93 commit 7a31137
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/pybind/mgr/dashboard/controllers/rgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,21 +500,6 @@ def buckets_and_users_count(self, daemon_name=None):
@APIRouter('/rgw/user', Scope.RGW)
@APIDoc("RGW User Management API", "RgwUser")
class RgwUser(RgwRESTController):
def _append_uid(self, user):
"""
Append the user identifier that looks like [<tenant>$]<user>.
See http://docs.ceph.com/docs/jewel/radosgw/multitenancy/ for
more information.
:param user: The user parameters.
:type user: dict
:return: The modified user parameters including the 'uid' parameter.
:rtype: dict
"""
if isinstance(user, dict):
user['uid'] = '{}${}'.format(user['tenant'], user['user_id']) \
if user['tenant'] else user['user_id']
return user

@staticmethod
def _keys_allowed():
permissions = AuthManager.get_user(JwtManager.get_username()).permissions_dict()
Expand Down Expand Up @@ -550,7 +535,8 @@ def get(self, uid, daemon_name=None, stats=True) -> dict:
if not self._keys_allowed():
del result['keys']
del result['swift_keys']
return self._append_uid(result)
result['uid'] = result['full_user_id']
return result

@Endpoint()
@ReadPermission
Expand Down Expand Up @@ -583,7 +569,8 @@ def create(self, uid, display_name, email=None, max_buckets=None,
if secret_key is not None:
params['secret-key'] = secret_key
result = self.proxy(daemon_name, 'PUT', 'user', params)
return self._append_uid(result)
result['uid'] = result['full_user_id']
return result

@allow_empty_body
def set(self, uid, display_name=None, email=None, max_buckets=None,
Expand All @@ -598,7 +585,8 @@ def set(self, uid, display_name=None, email=None, max_buckets=None,
if suspended is not None:
params['suspended'] = suspended
result = self.proxy(daemon_name, 'POST', 'user', params)
return self._append_uid(result)
result['uid'] = result['full_user_id']
return result

def delete(self, uid, daemon_name=None):
try:
Expand Down
2 changes: 2 additions & 0 deletions src/pybind/mgr/dashboard/tests/test_rgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def test_user_get_with_keys(self, keys_allowed, mock_proxy):
mock_proxy.return_value = {
'tenant': '',
'user_id': 'my_user_id',
'full_user_id': 'my_user_id',
'keys': [],
'swift_keys': []
}
Expand All @@ -297,6 +298,7 @@ def test_user_get_without_keys(self, keys_allowed, mock_proxy):
mock_proxy.return_value = {
'tenant': '',
'user_id': 'my_user_id',
'full_user_id': 'my_user_id',
'keys': [],
'swift_keys': []
}
Expand Down

0 comments on commit 7a31137

Please sign in to comment.