]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Add requestPayment retrieval
authorJavier M. Mellid <jmunhoz@igalia.com>
Wed, 30 Sep 2015 09:31:18 +0000 (11:31 +0200)
committerJavier M. Mellid <jmunhoz@igalia.com>
Fri, 9 Oct 2015 10:05:23 +0000 (12:05 +0200)
Implement requestPayment retrieval to find out who is paying when
accessing a resource (BucketOwner or Requester)

Fixes: #13427
Signed-off-by: Javier M. Mellid <jmunhoz@igalia.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_json_enc.cc
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_s3.h

index 132fd9e809f88f61fc0ffdefdb97c3fd8dee2b9b..279dca2e4f79e7285943b0bb5ab2a5da5a8c5ff7 100644 (file)
@@ -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
index 8ad0733a9a65a1c9e456f487215d2b33316c95e5..28c59c3c0495ed8bc907a825107a85fede57a17d 100644 (file)
@@ -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)
 
index d09fa65e7c2e51a36f02420f741c9f3150138b25..6236ed92f640910433d4148908aa846431b81022 100644 (file)
@@ -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
index 722f39d2b7ec80253b7bd1954d724bc363dc3d92..91b600e63b4db6f0d502bfd6c36b841d784a9f04 100644 (file)
@@ -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))
index 7a196a3d6ce22e3217c7dd66dce050aad1f78be8..c5e90f5275fa4d5d4bd2905daf7ddbf4e45be3cf 100644 (file)
@@ -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;
index f8531840d5e4646d10b9b1a24cc7c12d0b4bcce0..9889f884cf2d4e2246516009634942c7989be169 100644 (file)
@@ -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
index 570b00c0e9b106e23936fe706074ffa17e1d1a2c..766772d2142e20e244deb0f825fa99bd8b03854d 100644 (file)
@@ -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;
   }
index 5db03dadc95038ddefd621bb7b816f03cc64a65b..804fab42f759a752d5f641a75cc63ed78064fe61 100644 (file)
@@ -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();