From 16c4fd7d5647d86482c57bb60d3ea00dde16fadf Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 2 Jul 2025 17:01:15 -0400 Subject: [PATCH] rgw/rest: add RGWRESTMgr_S3Website move some s3website stuff out of RGWRESTMgr_S3::get_handler() into its own nested RGWRESTMgr Signed-off-by: Casey Bodley --- src/rgw/rgw_rest_s3.cc | 63 +++++++++++++++++++++++++++--------- src/rgw/rgw_rest_s3.h | 18 +++++------ src/rgw/rgw_rest_s3website.h | 9 ++++++ 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 5679e1ca73d..fd5b584fb80 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -5968,30 +5968,43 @@ void parse_post_action(const std::string& post_body, req_state* s) } } +RGWRESTMgr_S3::RGWRESTMgr_S3(bool _enable_s3website, + bool _enable_sts, + bool _enable_iam, + bool _enable_pubsub) + : enable_sts(_enable_sts), + enable_iam(_enable_iam), + enable_pubsub(_enable_pubsub) +{ + if (_enable_s3website) { + s3website = std::make_unique(); + } +} +RGWRESTMgr_S3::~RGWRESTMgr_S3() = default; + +RGWRESTMgr* RGWRESTMgr_S3::get_resource_mgr_as_default(req_state* s, + const std::string& uri, + std::string* out_uri) +{ + // route matching requests to RGWRESTMgr_S3Website + const bool in_s3website_domain = (s->prot_flags & RGW_REST_WEBSITE); + if (s3website && in_s3website_domain) { + return s3website->get_resource_mgr(s, uri, out_uri); + } + + return RGWRESTMgr::get_resource_mgr(s, uri, out_uri); +} + RGWHandler_REST* RGWRESTMgr_S3::get_handler(rgw::sal::Driver* driver, req_state* const s, const rgw::auth::StrategyRegistry& auth_registry, const std::string& frontend_prefix) { - bool is_s3website = enable_s3website && (s->prot_flags & RGW_REST_WEBSITE); - int ret = - RGWHandler_REST_S3::init_from_header(driver, s, - is_s3website ? RGWFormat::HTML : - RGWFormat::XML, true); + int ret = RGWHandler_REST_S3::init_from_header(driver, s, RGWFormat::XML, true); if (ret < 0) { return nullptr; } - if (is_s3website) { - if (s->init_state.url_bucket.empty()) { - return new RGWHandler_REST_Service_S3Website(auth_registry); - } - if (rgw::sal::Object::empty(s->object.get())) { - return new RGWHandler_REST_Bucket_S3Website(auth_registry); - } - return new RGWHandler_REST_Obj_S3Website(auth_registry); - } - if (s->init_state.url_bucket.empty()) { // no bucket if (s->op == OP_POST) { @@ -6029,6 +6042,26 @@ RGWHandler_REST* RGWRESTMgr_S3::get_handler(rgw::sal::Driver* driver, return new RGWHandler_REST_Bucket_S3(auth_registry, enable_pubsub); } +RGWHandler_REST* RGWRESTMgr_S3Website::get_handler( + rgw::sal::Driver* driver, + req_state* const s, + const rgw::auth::StrategyRegistry& auth_registry, + const std::string& frontend_prefix) +{ + int ret = RGWHandler_REST_S3::init_from_header(driver, s, RGWFormat::HTML, true); + if (ret < 0) { + return nullptr; + } + + if (s->init_state.url_bucket.empty()) { + return new RGWHandler_REST_Service_S3Website(auth_registry); + } + if (rgw::sal::Object::empty(s->object)) { + return new RGWHandler_REST_Bucket_S3Website(auth_registry); + } + return new RGWHandler_REST_Obj_S3Website(auth_registry); +} + bool RGWHandler_REST_S3Website::web_dir() const { std::string subdir_name; if (!rgw::sal::Object::empty(s->object.get())) { diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 4d42facdcd8..5d9a722e5b0 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -818,26 +818,26 @@ public: ~RGWHandler_REST_Obj_S3() override = default; }; +class RGWRESTMgr_S3Website; + class RGWRESTMgr_S3 : public RGWRESTMgr { private: - const bool enable_s3website; + std::unique_ptr s3website; const bool enable_sts; const bool enable_iam; const bool enable_pubsub; public: - explicit RGWRESTMgr_S3(bool _enable_s3website=false, bool _enable_sts=false, bool _enable_iam=false, bool _enable_pubsub=false) - : enable_s3website(_enable_s3website), - enable_sts(_enable_sts), - enable_iam(_enable_iam), - enable_pubsub(_enable_pubsub) { - } - - ~RGWRESTMgr_S3() override = default; + explicit RGWRESTMgr_S3(bool _enable_s3website=false, bool _enable_sts=false, bool _enable_iam=false, bool _enable_pubsub=false); + ~RGWRESTMgr_S3() override; RGWHandler_REST *get_handler(rgw::sal::Driver* driver, req_state* s, const rgw::auth::StrategyRegistry& auth_registry, const std::string& frontend_prefix) override; + + RGWRESTMgr* get_resource_mgr_as_default(req_state* const s, + const std::string& uri, + std::string* our_uri) override; }; class RGWHandler_REST_Obj_S3Website; diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h index 3842cdb9556..ef5d9a18b7a 100644 --- a/src/rgw/rgw_rest_s3website.h +++ b/src/rgw/rgw_rest_s3website.h @@ -71,6 +71,15 @@ public: ~RGWHandler_REST_Bucket_S3Website() override = default; }; +class RGWRESTMgr_S3Website : public RGWRESTMgr { + friend class RGWRESTMgr_S3; // for protected get_resource_mgr() +public: + RGWHandler_REST *get_handler(rgw::sal::Driver* driver, + req_state* s, + const rgw::auth::StrategyRegistry& auth_registry, + const std::string& frontend_prefix) override; +}; + // TODO: do we actually need this? class RGWGetObj_ObjStore_S3Website : public RGWGetObj_ObjStore_S3 { -- 2.39.5