From: Casey Bodley Date: Sun, 14 Jan 2024 21:16:50 +0000 (-0500) Subject: rgw/iam: RGWUntagRole uses lower/upper bounds for iteration X-Git-Tag: v20.0.0~2159^2~101 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=fd96b15e478855e5950248fbdc9a7736488a6bf5;p=ceph.git rgw/iam: RGWUntagRole uses lower/upper bounds for iteration Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_rest_role.cc b/src/rgw/rgw_rest_role.cc index f3a17a8614606..620a1adc0d8fa 100644 --- a/src/rgw/rgw_rest_role.cc +++ b/src/rgw/rgw_rest_role.cc @@ -1,7 +1,9 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab ft=cpp +#include #include +#include #include #include "common/errno.h" @@ -874,11 +876,14 @@ int RGWUntagRole::get_params() return -EINVAL; } - auto val_map = s->info.args.get_params(); - for (auto& it : val_map) { - if (it.first.find("TagKeys.member.") != string::npos) { - tagKeys.emplace_back(it.second); - } + const auto& params = s->info.args.get_params(); + const std::string prefix = "TagKeys.member."; + if (auto l = params.lower_bound(prefix); l != params.end()) { + // copy matching values into untag vector + std::transform(l, params.upper_bound(prefix), std::back_inserter(untag), + [] (const std::pair& p) { + return p.second; + }); } return 0; } @@ -903,17 +908,11 @@ void RGWUntagRole::execute(optional_yield y) s->info.args.remove("RoleName"); s->info.args.remove("Action"); s->info.args.remove("Version"); - auto& val_map = s->info.args.get_params(); - std::vector::iterator> iters; - for (auto it = val_map.begin(); it!= val_map.end(); it++) { - if (it->first.find("Tags.member.") == 0) { - iters.emplace_back(it); - } + auto& params = s->info.args.get_params(); + if (auto l = params.lower_bound("TagKeys.member."); l != params.end()) { + params.erase(l, params.upper_bound("TagKeys.member.")); } - for (auto& it : iters) { - val_map.erase(it); - } op_ret = forward_iam_request_to_master(this, site, s->user->get_info(), bl_post_body, parser, s->info, y); if (op_ret < 0) { @@ -922,7 +921,7 @@ void RGWUntagRole::execute(optional_yield y) } } - _role->erase_tags(tagKeys); + _role->erase_tags(untag); op_ret = _role->update(this, y); if (op_ret == 0) { diff --git a/src/rgw/rgw_rest_role.h b/src/rgw/rgw_rest_role.h index acd8f6f94eef7..59a5cf79cdf20 100644 --- a/src/rgw/rgw_rest_role.h +++ b/src/rgw/rgw_rest_role.h @@ -18,7 +18,6 @@ protected: std::string path_prefix; std::string max_session_duration; std::multimap tags; - std::vector tagKeys; std::unique_ptr _role; int verify_permission(optional_yield y) override; int init_processing(optional_yield y) override; @@ -163,6 +162,7 @@ public: class RGWUntagRole : public RGWRoleWrite { bufferlist bl_post_body; + std::vector untag; public: RGWUntagRole(const bufferlist& bl_post_body) : bl_post_body(bl_post_body) {}; void execute(optional_yield y) override;