From f88c8522287b0bb4e8eed627f79646a8f7bcf4b5 Mon Sep 17 00:00:00 2001 From: Pete Zaitcev Date: Thu, 11 Feb 2016 18:01:06 -0700 Subject: [PATCH] rgw: Fix subuser harder with tenants We have several ways to set the tenant and user in the operation state now: radosgw-admin --uid=user # default empty tenant radosgw-admin --tenant=ten --uid=user radosgw-admin --uid='ten$user' radosgw-admin --subuser='ten$user:sub' The previous commit a51fbf2d fixed some of these but broke the others. The root of the difficulty is that rgw_op.set_subuser() has a magical side effect of setting rgw_op.user_id, but the code pretends that it's one of many other setters. Unfortunately, getting rid of the side effect is not easy here. It is exactly what we want for historic compatibility, so killing the magic requires a pile of code elsewhere, or worse, implicit ordering requirements (invoke set_subuser before set_user or else). For now we doubled down on the magic. This way at least it is all in one place and you do not have to flip pages of code to understand what is going on. Signed-off-by: Pete Zaitcev --- src/rgw/rgw_user.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index bff4a52912e..93af86a3b34 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -268,7 +268,13 @@ struct RGWUserAdminOpState { size_t pos = _subuser.find(":"); if (pos != string::npos) { - user_id.from_str(_subuser.substr(0, pos)); + rgw_user tmp_id; + tmp_id.from_str(_subuser.substr(0, pos)); + if (tmp_id.tenant.empty()) { + user_id.id = tmp_id.id; + } else { + user_id = tmp_id; + } subuser = _subuser.substr(pos+1); } else { subuser = _subuser; -- 2.47.3