From 9d46c21bc6e522b1d85056e1e545125743aace65 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Mon, 12 Feb 2024 16:44:00 -0500 Subject: [PATCH] rgw/pubsub: topic apis forward post body Signed-off-by: Casey Bodley --- src/rgw/driver/rados/rgw_rest_pubsub.h | 6 ++- src/rgw/rgw_rest_pubsub.cc | 56 ++++++++++++++------------ src/rgw/rgw_rest_s3.cc | 2 +- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/rgw/driver/rados/rgw_rest_pubsub.h b/src/rgw/driver/rados/rgw_rest_pubsub.h index 8b37992b918..91c39ac1008 100644 --- a/src/rgw/driver/rados/rgw_rest_pubsub.h +++ b/src/rgw/driver/rados/rgw_rest_pubsub.h @@ -25,11 +25,13 @@ public: // AWS compliant topics handler factory class RGWHandler_REST_PSTopic_AWS : public RGWHandler_REST { const rgw::auth::StrategyRegistry& auth_registry; + bufferlist bl_post_body; protected: RGWOp* op_post() override; public: - RGWHandler_REST_PSTopic_AWS(const rgw::auth::StrategyRegistry& _auth_registry) : - auth_registry(_auth_registry) {} + RGWHandler_REST_PSTopic_AWS(const rgw::auth::StrategyRegistry& _auth_registry, + bufferlist bl_post_body) + : auth_registry(_auth_registry), bl_post_body(std::move(bl_post_body)) {} virtual ~RGWHandler_REST_PSTopic_AWS() = default; int postauth_init(optional_yield) override { return 0; } int authorize(const DoutPrefixProvider* dpp, optional_yield y) override; diff --git a/src/rgw/rgw_rest_pubsub.cc b/src/rgw/rgw_rest_pubsub.cc index 66574cc8272..1ba234f9d41 100644 --- a/src/rgw/rgw_rest_pubsub.cc +++ b/src/rgw/rgw_rest_pubsub.cc @@ -126,6 +126,7 @@ int verify_topic_owner_or_policy(req_state* const s, // Action=CreateTopic&Name=[&OpaqueData=data][&push-endpoint=[&persistent][&=]] class RGWPSCreateTopicOp : public RGWOp { private: + bufferlist bl_post_body; std::string topic_name; rgw_pubsub_dest dest; std::string topic_arn; @@ -190,8 +191,11 @@ class RGWPSCreateTopicOp : public RGWOp { return 0; } - public: - int verify_permission(optional_yield y) override { + public: + explicit RGWPSCreateTopicOp(bufferlist bl_post_body) + : bl_post_body(std::move(bl_post_body)) {} + + int verify_permission(optional_yield y) override { auto ret = get_params(); if (ret < 0) { return ret; @@ -257,10 +261,9 @@ class RGWPSCreateTopicOp : public RGWOp { void RGWPSCreateTopicOp::execute(optional_yield y) { // master request will replicate the topic creation. - bufferlist indata; if (!driver->is_meta_master()) { op_ret = rgw_forward_request_to_master( - this, *s->penv.site, s->user->get_id(), &indata, nullptr, s->info, y); + this, *s->penv.site, s->user->get_id(), &bl_post_body, nullptr, s->info, y); if (op_ret < 0) { ldpp_dout(this, 1) << "CreateTopic forward_request_to_master returned ret = " << op_ret @@ -537,6 +540,7 @@ void RGWPSGetTopicAttributesOp::execute(optional_yield y) { // Action=SetTopicAttributes&TopicArn=&AttributeName=&AttributeValue= class RGWPSSetTopicAttributesOp : public RGWOp { private: + bufferlist bl_post_body; std::string topic_name; std::string topic_arn; std::string opaque_data; @@ -632,6 +636,9 @@ class RGWPSSetTopicAttributesOp : public RGWOp { } public: + explicit RGWPSSetTopicAttributesOp(bufferlist bl_post_body) + : bl_post_body(std::move(bl_post_body)) {} + int verify_permission(optional_yield y) override { auto ret = get_params(); if (ret < 0) { @@ -688,9 +695,8 @@ class RGWPSSetTopicAttributesOp : public RGWOp { void RGWPSSetTopicAttributesOp::execute(optional_yield y) { if (!driver->is_meta_master()) { - bufferlist indata; op_ret = rgw_forward_request_to_master( - this, *s->penv.site, s->user->get_id(), &indata, nullptr, s->info, y); + this, *s->penv.site, s->user->get_id(), &bl_post_body, nullptr, s->info, y); if (op_ret < 0) { ldpp_dout(this, 1) << "SetTopicAttributes forward_request_to_master returned ret = " @@ -733,6 +739,7 @@ void RGWPSSetTopicAttributesOp::execute(optional_yield y) { // Action=DeleteTopic&TopicArn= class RGWPSDeleteTopicOp : public RGWOp { private: + bufferlist bl_post_body; std::string topic_name; int get_params() { @@ -747,7 +754,10 @@ class RGWPSDeleteTopicOp : public RGWOp { return 0; } - public: + public: + explicit RGWPSDeleteTopicOp(bufferlist bl_post_body) + : bl_post_body(std::move(bl_post_body)) {} + int verify_permission(optional_yield) override { return 0; } @@ -787,9 +797,8 @@ void RGWPSDeleteTopicOp::execute(optional_yield y) { return; } if (!driver->is_meta_master()) { - bufferlist indata; op_ret = rgw_forward_request_to_master( - this, *s->penv.site, s->user->get_id(), &indata, nullptr, s->info, y); + this, *s->penv.site, s->user->get_id(), &bl_post_body, nullptr, s->info, y); if (op_ret < 0) { ldpp_dout(this, 1) << "DeleteTopic forward_request_to_master returned ret = " << op_ret @@ -836,32 +845,29 @@ void RGWPSDeleteTopicOp::execute(optional_yield y) { ldpp_dout(this, 1) << "successfully removed topic '" << topic_name << "'" << dendl; } -using op_generator = RGWOp*(*)(); +using op_generator = RGWOp*(*)(bufferlist); static const std::unordered_map op_generators = { - {"CreateTopic", []() -> RGWOp* { return new RGWPSCreateTopicOp; }}, - {"DeleteTopic", []() -> RGWOp* { return new RGWPSDeleteTopicOp; }}, - {"ListTopics", []() -> RGWOp* { return new RGWPSListTopicsOp; }}, - {"GetTopic", []() -> RGWOp* { return new RGWPSGetTopicOp; }}, + {"CreateTopic", [](bufferlist bl) -> RGWOp* { return new RGWPSCreateTopicOp(std::move(bl)); }}, + {"DeleteTopic", [](bufferlist bl) -> RGWOp* { return new RGWPSDeleteTopicOp(std::move(bl)); }}, + {"ListTopics", [](bufferlist bl) -> RGWOp* { return new RGWPSListTopicsOp; }}, + {"GetTopic", [](bufferlist bl) -> RGWOp* { return new RGWPSGetTopicOp; }}, {"GetTopicAttributes", - []() -> RGWOp* { return new RGWPSGetTopicAttributesOp; }}, + [](bufferlist bl) -> RGWOp* { return new RGWPSGetTopicAttributesOp; }}, {"SetTopicAttributes", - []() -> RGWOp* { return new RGWPSSetTopicAttributesOp; }}}; + [](bufferlist bl) -> RGWOp* { return new RGWPSSetTopicAttributesOp(std::move(bl)); }}}; -bool RGWHandler_REST_PSTopic_AWS::action_exists(const req_state* s) +bool RGWHandler_REST_PSTopic_AWS::action_exists(const req_info& info) { - if (s->info.args.exists("Action")) { - const std::string action_name = s->info.args.get("Action"); - return op_generators.contains(action_name); - } - return false; -} -bool RGWHandler_REST_PSTopic_AWS::action_exists(const req_info& info) { if (info.args.exists("Action")) { const std::string action_name = info.args.get("Action"); return op_generators.contains(action_name); } return false; } +bool RGWHandler_REST_PSTopic_AWS::action_exists(const req_state* s) +{ + return action_exists(s->info); +} RGWOp *RGWHandler_REST_PSTopic_AWS::op_post() { @@ -872,7 +878,7 @@ RGWOp *RGWHandler_REST_PSTopic_AWS::op_post() const std::string action_name = s->info.args.get("Action"); const auto action_it = op_generators.find(action_name); if (action_it != op_generators.end()) { - return action_it->second(); + return action_it->second(std::move(bl_post_body)); } ldpp_dout(s, 10) << "unknown action '" << action_name << "' for Topic handler" << dendl; } else { diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 186fb109c2f..d27131c83d6 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -5257,7 +5257,7 @@ RGWHandler_REST* RGWRESTMgr_S3::get_handler(rgw::sal::Driver* driver, return new RGWHandler_REST_IAM(auth_registry, data); } if (enable_pubsub && RGWHandler_REST_PSTopic_AWS::action_exists(s)) { - return new RGWHandler_REST_PSTopic_AWS(auth_registry); + return new RGWHandler_REST_PSTopic_AWS(auth_registry, std::move(data)); } return nullptr; } -- 2.39.5