From: Yehuda Sadeh Date: Fri, 31 Mar 2017 22:30:39 +0000 (-0700) Subject: rgw: es: api to retrieve bucket mdsearch config X-Git-Tag: ses5-milestone6~9^2~3^2~42 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=acba916125175bb895d29a41e9b23e49d053cbb7;p=ceph.git rgw: es: api to retrieve bucket mdsearch config GET /bucket?mdsearch Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index c1a6bed0807f..f75436564852 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -467,6 +467,7 @@ enum RGWOpType { RGW_OP_BULK_UPLOAD, RGW_OP_METADATA_SEARCH, RGW_OP_CONFIG_BUCKET_META_SEARCH, + RGW_OP_GET_BUCKET_META_SEARCH, }; class RGWAccessControlPolicy; diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 7656a0b60b22..fe6b7027a2b2 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -6339,6 +6339,20 @@ void RGWConfigBucketMetaSearch::execute() } } +int RGWGetBucketMetaSearch::verify_permission() +{ + if (!s->auth.identity->is_owner_of(s->bucket_owner.get_id())) { + return -EACCES; + } + + return 0; +} + +void RGWGetBucketMetaSearch::pre_exec() +{ + rgw_bucket_object_pre_exec(s); +} + RGWHandler::~RGWHandler() { diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 8debd7e2efea..bbb0bdb0390c 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -2032,4 +2032,18 @@ public: virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; +class RGWGetBucketMetaSearch : public RGWOp { +public: + RGWGetBucketMetaSearch() {} + + int verify_permission(); + void pre_exec(); + void execute() {} + + virtual void send_response() = 0; + virtual const string name() { return "get_bucket_meta_search"; } + virtual RGWOpType get_type() { return RGW_OP_GET_BUCKET_META_SEARCH; } + virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } +}; + #endif /* CEPH_RGW_OP_H */ diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index d73b4666e3a2..8dd6ba6055bf 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -2785,6 +2785,37 @@ void RGWConfigBucketMetaSearch_ObjStore_S3::send_response() end_header(s, this); } +void RGWGetBucketMetaSearch_ObjStore_S3::send_response() +{ + if (op_ret) + set_req_state_err(s, op_ret); + dump_errno(s); + end_header(s, NULL, "application/xml"); + + Formatter *f = s->formatter; + f->open_array_section("GetBucketMetaSearchResult"); + f->open_object_section("Entry"); + for (auto& e : s->bucket_info.mdsearch_config) { + string k = string("x-amz-meta-") + e.first; + f->dump_string("Key", k.c_str()); + const char *type; + switch (e.second) { + case ESEntityTypeMap::ES_ENTITY_INT: + type = "int"; + break; + case ESEntityTypeMap::ES_ENTITY_DATE: + type = "date"; + break; + default: + type = "str"; + } + f->dump_string("Type", type); + } + f->close_section(); + f->close_section(); + rgw_flush_formatter(s, f); +} + RGWOp *RGWHandler_REST_Service_S3::op_get() { @@ -2854,6 +2885,10 @@ RGWOp *RGWHandler_REST_Bucket_S3::op_get() return new RGWGetBucketWebsite_ObjStore_S3; } + if (s->info.args.exists("mdsearch")) { + return new RGWGetBucketMetaSearch_ObjStore_S3; + } + if (is_acl_op()) { return new RGWGetACLs_ObjStore_S3; } else if (is_cors_op()) { diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index aad591aec5a4..d362d07bd65b 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -427,6 +427,14 @@ public: void send_response() override; }; +class RGWGetBucketMetaSearch_ObjStore_S3 : public RGWGetBucketMetaSearch { +public: + RGWGetBucketMetaSearch_ObjStore_S3() {} + ~RGWGetBucketMetaSearch_ObjStore_S3() {} + + void send_response() override; +}; + class RGW_Auth_S3 { private: static int authorize_v2(RGWRados *store,