]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw/rest: add RGWRESTMgr_S3Website
authorCasey Bodley <cbodley@redhat.com>
Wed, 2 Jul 2025 21:01:15 +0000 (17:01 -0400)
committerCasey Bodley <cbodley@redhat.com>
Tue, 21 Oct 2025 15:42:25 +0000 (11:42 -0400)
move some s3website stuff out of RGWRESTMgr_S3::get_handler() into its
own nested RGWRESTMgr

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_s3.h
src/rgw/rgw_rest_s3website.h

index 5679e1ca73d6aa655c7079eacd5164e17b6c1bca..fd5b584fb80f5a67dab9dd37d4c4bedd73b6a193 100644 (file)
@@ -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_S3Website>();
+  }
+}
+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())) {
index 4d42facdcd8d8760d6112c9d744fbeeca8d5f687..5d9a722e5b0352d9cdb4a9db2c380e7364ea9c59 100644 (file)
@@ -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<RGWRESTMgr_S3Website> 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;
index 3842cdb9556d57082882590c12d9cb95318eccb8..ef5d9a18b7a33ed9ae8ff60b6311010e0f0fab52 100644 (file)
@@ -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
 {