From 419da9d2242c30a136fbfc71c4f3ab86f1591a10 Mon Sep 17 00:00:00 2001 From: "Sumedh A. Kulkarni" Date: Thu, 28 Apr 2022 00:39:44 -0600 Subject: [PATCH] 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 --- src/rgw/rgw_rest_user_policy.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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; -- 2.47.3