From 603863a46e2f40d0c58b9bd4bec3d9196559aa82 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 31 Mar 2017 15:56:06 -0700 Subject: [PATCH] rgw: es: api to delete bucket mdsearch config DELETE /bucket?mdsearch Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_common.h | 1 + src/rgw/rgw_op.cc | 25 +++++++++++++++++++++++++ src/rgw/rgw_op.h | 14 ++++++++++++++ src/rgw/rgw_rest_s3.cc | 16 ++++++++++++++-- src/rgw/rgw_rest_s3.h | 8 ++++++++ 5 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index f754365648524..608b9fa6444e2 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -468,6 +468,7 @@ enum RGWOpType { RGW_OP_METADATA_SEARCH, RGW_OP_CONFIG_BUCKET_META_SEARCH, RGW_OP_GET_BUCKET_META_SEARCH, + RGW_OP_DEL_BUCKET_META_SEARCH, }; class RGWAccessControlPolicy; diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index fe6b7027a2b2a..d4a9326c3dd02 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -6353,6 +6353,31 @@ void RGWGetBucketMetaSearch::pre_exec() rgw_bucket_object_pre_exec(s); } +int RGWDelBucketMetaSearch::verify_permission() +{ + if (!s->auth.identity->is_owner_of(s->bucket_owner.get_id())) { + return -EACCES; + } + + return 0; +} + +void RGWDelBucketMetaSearch::pre_exec() +{ + rgw_bucket_object_pre_exec(s); +} + +void RGWDelBucketMetaSearch::execute() +{ + s->bucket_info.mdsearch_config.clear(); + + op_ret = store->put_bucket_instance_info(s->bucket_info, false, real_time(), &s->bucket_attrs); + if (op_ret < 0) { + ldout(s->cct, 0) << "NOTICE: put_bucket_info on bucket=" << s->bucket.name << " returned err=" << op_ret << dendl; + return; + } +} + RGWHandler::~RGWHandler() { diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index bbb0bdb0390ca..62c71fd98e794 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -2046,4 +2046,18 @@ public: virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; +class RGWDelBucketMetaSearch : public RGWOp { +public: + RGWDelBucketMetaSearch() {} + + int verify_permission(); + void pre_exec(); + void execute(); + + virtual void send_response() = 0; + virtual const string name() { return "delete_bucket_meta_search"; } + virtual RGWOpType delete_type() { return RGW_OP_DEL_BUCKET_META_SEARCH; } + virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } +}; + #endif /* CEPH_RGW_OP_H */ diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 8dd6ba6055bf2..a948cf1548f60 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -2794,8 +2794,8 @@ void RGWGetBucketMetaSearch_ObjStore_S3::send_response() Formatter *f = s->formatter; f->open_array_section("GetBucketMetaSearchResult"); - f->open_object_section("Entry"); for (auto& e : s->bucket_info.mdsearch_config) { + f->open_object_section("Entry"); string k = string("x-amz-meta-") + e.first; f->dump_string("Key", k.c_str()); const char *type; @@ -2810,12 +2810,20 @@ void RGWGetBucketMetaSearch_ObjStore_S3::send_response() type = "str"; } f->dump_string("Type", type); + f->close_section(); } f->close_section(); - f->close_section(); rgw_flush_formatter(s, f); } +void RGWDelBucketMetaSearch_ObjStore_S3::send_response() +{ + if (op_ret) + set_req_state_err(s, op_ret); + dump_errno(s); + end_header(s, this); +} + RGWOp *RGWHandler_REST_Service_S3::op_get() { @@ -2958,6 +2966,10 @@ RGWOp *RGWHandler_REST_Bucket_S3::op_delete() return new RGWDeleteBucketWebsite_ObjStore_S3; } + if (s->info.args.exists("mdsearch")) { + return new RGWDelBucketMetaSearch_ObjStore_S3; + } + return new RGWDeleteBucket_ObjStore_S3; } diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index d362d07bd65b3..d426b3d40caac 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -435,6 +435,14 @@ public: void send_response() override; }; +class RGWDelBucketMetaSearch_ObjStore_S3 : public RGWDelBucketMetaSearch { +public: + RGWDelBucketMetaSearch_ObjStore_S3() {} + ~RGWDelBucketMetaSearch_ObjStore_S3() {} + + void send_response() override; +}; + class RGW_Auth_S3 { private: static int authorize_v2(RGWRados *store, -- 2.39.5