From: Sumedh A. Kulkarni Date: Thu, 28 Apr 2022 06:39:44 +0000 (-0600) Subject: rgw_rest_user_policy: [55603] Fix Get & List User Policy responses X-Git-Tag: v17.2.4~37^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=419da9d2242c30a136fbfc71c4f3ab86f1591a10;p=ceph.git rgw_rest_user_policy: [55603] Fix Get & List User Policy responses GetUserPolicy & ListUserPolicies responses has few mistakes/typos if compared with aws documentation of the API's. While using `aws iam` cli the mistakes in the response schema causes the blank/incorrect response output. Correcting the same with the patch. Fixes: https://tracker.ceph.com/issues/55603 Signed-off-by: Sumedh A. Kulkarni (cherry picked from commit 4b8c66a074f3491129e1864388f980b812f47752) Conflicts: src/rgw/rgw_rest_user_policy.cc Cherry-pick notes: - Conflict due to try/catch block in RGWListUserPolicies::execute not present in Quincy --- diff --git a/src/rgw/rgw_rest_user_policy.cc b/src/rgw/rgw_rest_user_policy.cc index a552f3b2b2a2..f6c7d2314dc0 100644 --- a/src/rgw/rgw_rest_user_policy.cc +++ b/src/rgw/rgw_rest_user_policy.cc @@ -25,9 +25,9 @@ using rgw::IAM::Policy; void RGWRestUserPolicy::dump(Formatter *f) const { - encode_json("Policyname", policy_name , f); - encode_json("Username", user_name , f); - encode_json("Policydocument", policy, f); + encode_json("PolicyName", policy_name , f); + encode_json("UserName", user_name , f); + encode_json("PolicyDocument", policy, f); } void RGWRestUserPolicy::send_response() @@ -276,14 +276,20 @@ void RGWListUserPolicies::execute(optional_yield y) s->formatter->close_section(); s->formatter->open_object_section("ListUserPoliciesResult"); bufferlist bl = it->second; - decode(policies, bl); + try { + decode(policies, bl); + } catch (buffer::error& err) { + ldpp_dout(this, 0) << "ERROR: failed to decode user policies" << dendl; + op_ret = -EIO; + return; + } + s->formatter->open_object_section("PolicyNames"); for (const auto& p : policies) { - s->formatter->open_object_section("PolicyNames"); s->formatter->dump_string("member", p.first); - s->formatter->close_section(); } s->formatter->close_section(); s->formatter->close_section(); + s->formatter->close_section(); } else { ldpp_dout(this, 0) << "ERROR: RGW_ATTR_USER_POLICY not found" << dendl; op_ret = -ERR_NO_SUCH_ENTITY;