]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/s3: CreateBucket's LocationConstraint is optional
authorCasey Bodley <cbodley@redhat.com>
Wed, 8 Jan 2025 19:50:33 +0000 (14:50 -0500)
committerCasey Bodley <cbodley@redhat.com>
Tue, 25 Feb 2025 16:15:57 +0000 (11:15 -0500)
clean up the parsing and make the LocationConstraint optional

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

index d2ce7ca6afe210f386433e8abdd071294016c7db..4548fd92583a533c3929b84f874906e5cec2cc56 100644 (file)
@@ -2485,36 +2485,24 @@ public:
   string location_constraint;
 };
 
-class RGWCreateBucketConfig : public XMLObj
-{
-public:
-  RGWCreateBucketConfig() {}
-  ~RGWCreateBucketConfig() override {}
+// CreateBucketConfiguration
+struct RGWCreateBucketConfig : XMLObj {
+  XMLObj* location_constraint = nullptr;
+
+  bool xml_end(const char*) override {
+    location_constraint = find_first("LocationConstraint");
+    return true;
+  }
 };
 
-class RGWCreateBucketParser : public RGWXMLParser
-{
+class RGWCreateBucketParser : public RGWXMLParser {
   XMLObj *alloc_obj(const char *el) override {
+    using namespace std::string_view_literals;
+    if (el == "CreateBucketConfiguration"sv) {
+      return new RGWCreateBucketConfig;
+    }
     return new XMLObj;
   }
-
-public:
-  RGWCreateBucketParser() {}
-  ~RGWCreateBucketParser() override {}
-
-  bool get_location_constraint(string& zone_group) {
-    XMLObj *config = find_first("CreateBucketConfiguration");
-    if (!config)
-      return false;
-
-    XMLObj *constraint = config->find_first("LocationConstraint");
-    if (!constraint)
-      return false;
-
-    zone_group = constraint->get_data();
-
-    return true;
-  }
 };
 
 int RGWCreateBucket_ObjStore_S3::get_params(optional_yield y)
@@ -2561,13 +2549,19 @@ int RGWCreateBucket_ObjStore_S3::get_params(optional_yield y)
       return -EINVAL;
     }
 
-    if (!parser.get_location_constraint(location_constraint)) {
-      ldpp_dout(this, 0) << "provided input did not specify location constraint correctly" << dendl;
+    auto config = static_cast<RGWCreateBucketConfig*>(
+        parser.find_first("CreateBucketConfiguration"));
+    if (!config) {
+      s->err.message = "Missing required element CreateBucketConfiguration";
       return -EINVAL;
     }
 
-    ldpp_dout(this, 10) << "create bucket location constraint: "
-                     << location_constraint << dendl;
+    if (config->location_constraint) {
+      location_constraint = config->location_constraint->get_data();
+
+      ldpp_dout(this, 10) << "create bucket location constraint: "
+          << location_constraint << dendl;
+    }
   }
 
   size_t pos = location_constraint.find(':');