From: Javier M. Mellid Date: Wed, 30 Sep 2015 09:31:18 +0000 (+0200) Subject: rgw: Add requestPayment retrieval X-Git-Tag: v10.0.1~125^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f2a31ab8473c3b88237b20e578e53500838e0885;p=ceph.git rgw: Add requestPayment retrieval Implement requestPayment retrieval to find out who is paying when accessing a resource (BucketOwner or Requester) Fixes: #13427 Signed-off-by: Javier M. Mellid --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 132fd9e809f8..279dca2e4f79 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -613,6 +613,7 @@ int RGWHTTPArgs::parse() (name.compare("versionId") == 0) || (name.compare("versions") == 0) || (name.compare("versioning") == 0) || + (name.compare("requestPayment") == 0) || (name.compare("torrent") == 0)) { sub_resources[name] = val; } else if (name[0] == 'r') { // root of all evil diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 8ad0733a9a65..28c59c3c0495 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -792,8 +792,10 @@ struct RGWBucketInfo // Represents the shard number for blind bucket. const static uint32_t NUM_SHARDS_BLIND_BUCKET; + bool requester_pays; + void encode(bufferlist& bl) const { - ENCODE_START(11, 4, bl); + ENCODE_START(12, 4, bl); ::encode(bucket, bl); ::encode(owner, bl); ::encode(flags, bl); @@ -805,6 +807,7 @@ struct RGWBucketInfo ::encode(quota, bl); ::encode(num_shards, bl); ::encode(bucket_index_shard_hash_type, bl); + ::encode(requester_pays, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { @@ -831,6 +834,8 @@ struct RGWBucketInfo ::decode(num_shards, bl); if (struct_v >= 11) ::decode(bucket_index_shard_hash_type, bl); + if (struct_v >= 12) + ::decode(requester_pays, bl); DECODE_FINISH(bl); } void dump(Formatter *f) const; @@ -842,7 +847,7 @@ struct RGWBucketInfo int versioning_status() { return flags & (BUCKET_VERSIONED | BUCKET_VERSIONS_SUSPENDED); } bool versioning_enabled() { return versioning_status() == BUCKET_VERSIONED; } - RGWBucketInfo() : flags(0), creation_time(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD) {} + RGWBucketInfo() : flags(0), creation_time(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD), requester_pays(false) {} }; WRITE_CLASS_ENCODER(RGWBucketInfo) diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index d09fa65e7c2e..6236ed92f640 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -549,6 +549,7 @@ void RGWBucketInfo::dump(Formatter *f) const encode_json("quota", quota, f); encode_json("num_shards", num_shards, f); encode_json("bi_shard_hash_type", (uint32_t)bucket_index_shard_hash_type, f); + encode_json("requester_pays", requester_pays, f); } void RGWBucketInfo::decode_json(JSONObj *obj) { @@ -564,6 +565,7 @@ void RGWBucketInfo::decode_json(JSONObj *obj) { uint32_t hash_type; JSONDecoder::decode_json("bi_shard_hash_type", hash_type, obj); bucket_index_shard_hash_type = (uint8_t)hash_type; + JSONDecoder::decode_json("requester_pays", requester_pays, obj); } void RGWObjEnt::dump(Formatter *f) const diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 722f39d2b7ec..91b600e63b4d 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2961,6 +2961,21 @@ void RGWOptionsCORS::execute() return; } +int RGWGetRequestPayment::verify_permission() +{ + return 0; +} + +void RGWGetRequestPayment::pre_exec() +{ + rgw_bucket_object_pre_exec(s); +} + +void RGWGetRequestPayment::execute() +{ + requester_pays = s->bucket_info.requester_pays; +} + int RGWInitMultipart::verify_permission() { if (!verify_bucket_permission(s, RGW_PERM_WRITE)) diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 7a196a3d6ce2..c5e90f5275fa 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -56,6 +56,7 @@ enum RGWOpType { RGW_OP_PUT_CORS, RGW_OP_DELETE_CORS, RGW_OP_OPTIONS_CORS, + RGW_OP_GET_REQUEST_PAYMENT, RGW_OP_INIT_MULTIPART, RGW_OP_COMPLETE_MULTIPART, RGW_OP_ABORT_MULTIPART, @@ -829,6 +830,23 @@ public: virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; +class RGWGetRequestPayment : public RGWOp { +protected: + bool requester_pays; + +public: + RGWGetRequestPayment() : requester_pays(0) {} + + int verify_permission(); + void pre_exec(); + void execute(); + + virtual void send_response() = 0; + virtual const string name() { return "get_request_payment"; } + virtual RGWOpType get_type() { return RGW_OP_GET_REQUEST_PAYMENT; } + virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } +}; + class RGWInitMultipart : public RGWOp { protected: int ret; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index f8531840d5e4..9889f884cf2d 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -2831,6 +2831,7 @@ int RGWRados::create_bucket(RGWUserInfo& owner, rgw_bucket& bucket, info.placement_rule = selected_placement_rule; info.num_shards = bucket_index_max_shards; info.bucket_index_shard_hash_type = RGWBucketInfo::MOD; + info.requester_pays = false; if (!creation_time) time(&info.creation_time); else diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 570b00c0e9b1..766772d2142e 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -1692,6 +1692,20 @@ void RGWOptionsCORS_ObjStore_S3::send_response() end_header(s, NULL); } +void RGWGetRequestPayment_ObjStore_S3::send_response() +{ + dump_errno(s); + end_header(s, this, "application/xml"); + dump_start(s); + + s->formatter->open_object_section_in_ns("RequestPaymentConfiguration", + "http://s3.amazonaws.com/doc/2006-03-01/"); + const char *payer = requester_pays ? "Requester" : "BucketOwner"; + s->formatter->dump_string("Payer", payer); + s->formatter->close_section(); + rgw_flush_formatter_and_reset(s, s->formatter); +} + int RGWInitMultipart_ObjStore_S3::get_params() { RGWAccessControlPolicy_S3 s3policy(s->cct); @@ -1968,6 +1982,8 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_get() return new RGWGetACLs_ObjStore_S3; } else if (is_cors_op()) { return new RGWGetCORS_ObjStore_S3; + } else if (is_request_payment_op()) { + return new RGWGetRequestPayment_ObjStore_S3; } else if (s->info.args.exists("uploads")) { return new RGWListBucketMultiparts_ObjStore_S3; } diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 5db03dadc950..804fab42f759 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -234,6 +234,14 @@ public: void send_response(); }; +class RGWGetRequestPayment_ObjStore_S3 : public RGWGetRequestPayment { +public: + RGWGetRequestPayment_ObjStore_S3() {} + ~RGWGetRequestPayment_ObjStore_S3() {} + + void send_response(); +}; + class RGWInitMultipart_ObjStore_S3 : public RGWInitMultipart_ObjStore { public: RGWInitMultipart_ObjStore_S3() {} @@ -400,6 +408,9 @@ protected: bool is_obj_update_op() { return is_acl_op() || is_cors_op(); } + bool is_request_payment_op() { + return s->info.args.exists("requestPayment"); + } RGWOp *get_obj_op(bool get_data); RGWOp *op_get();