From: Casey Bodley Date: Wed, 8 Jan 2025 19:50:33 +0000 (-0500) Subject: rgw/s3: CreateBucket's LocationConstraint is optional X-Git-Tag: v20.0.0~43^2~6 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=184da0a83bcd2051469101769c89ced78d834326;p=ceph.git rgw/s3: CreateBucket's LocationConstraint is optional clean up the parsing and make the LocationConstraint optional Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index d2ce7ca6afe21..4548fd92583a5 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -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( + 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(':');