]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Implementation for S3 Get Bucket Location 2329/head
authorAbhishek Lekshmanan <abhishek.lekshmanan@ril.com>
Mon, 25 Aug 2014 08:31:54 +0000 (14:01 +0530)
committerAbhishek Lekshmanan <abhishek.lekshmanan@ril.com>
Fri, 5 Sep 2014 03:36:27 +0000 (09:06 +0530)
S3 API supports getting the location for a bucket, which gives out one
of those geographic zones (US-WEST-1, EU for eg). Also it returns an
empty string for the default region.
(http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGETlocation.html)

Since LocationConstraint corresponds to regions in our case, this API
returns the region, for the "default" region empty string is returned

Signed-off-by: Abhishek Lekshmanan <abhishek.lekshmanan@ril.com>
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_s3.h

index a6389c960c2e25b69814ce35bd983d7a3f067573..6340fb14fb4e2449722280408a82c22bf6564c38 100644 (file)
@@ -1118,6 +1118,14 @@ int RGWGetBucketLogging::verify_permission()
   return 0;
 }
 
+int RGWGetBucketLocation::verify_permission()
+{
+  if (s->user.user_id.compare(s->bucket_owner.get_id()) != 0)
+    return -EACCES;
+
+  return 0;
+}
+
 int RGWCreateBucket::verify_permission()
 {
   if (!rgw_user_is_authenticated(s->user))
index b141ed5bd1bcdfbb6f17e4c9ce4af38af20ca741..44994f37dff46ecd1eb5af4cfd486a1e7f26bf8d 100644 (file)
@@ -243,6 +243,19 @@ public:
   virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; }
 };
 
+class RGWGetBucketLocation : public RGWOp {
+public:
+  RGWGetBucketLocation() {}
+  ~RGWGetBucketLocation() {}
+  int verify_permission();
+  void execute() {}
+
+  virtual void send_response() = 0;
+  virtual const string name() { return "get_bucket_location"; }
+  virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; }
+};
+
+
 class RGWStatBucket : public RGWOp {
 protected:
   int ret;
index 79de0732a2affadea6f2e40064e3a06213ad3352..bfd88ec747b5b7cc8691165c99818cea666cd117 100644 (file)
@@ -302,6 +302,23 @@ void RGWGetBucketLogging_ObjStore_S3::send_response()
   rgw_flush_formatter_and_reset(s, s->formatter);
 }
 
+void RGWGetBucketLocation_ObjStore_S3::send_response()
+{
+  dump_errno(s);
+  end_header(s, this);
+  dump_start(s);
+
+  string location_constraint(s->bucket_info.region);
+  if (s->bucket_info.region == "default")
+    location_constraint.clear();
+
+  s->formatter->dump_format_ns("LocationConstraint",
+                              "http://doc.s3.amazonaws.com/doc/2006-03-01/",
+                              "%s",location_constraint.c_str());
+
+  rgw_flush_formatter_and_reset(s, s->formatter);
+}
+
 static void dump_bucket_metadata(struct req_state *s, RGWBucketEnt& bucket)
 {
   char buf[32];
@@ -1716,6 +1733,8 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_get()
 {
   if (s->info.args.sub_resource_exists("logging"))
     return new RGWGetBucketLogging_ObjStore_S3;
+  else if (s->info.args.sub_resource_exists("location"))
+    return new RGWGetBucketLocation_ObjStore_S3;
   if (is_acl_op()) {
     return new RGWGetACLs_ObjStore_S3;
   } else if (is_cors_op()) {
index 642a41102ed331413f3de26eea77028351df6786..d983a6ba625f3ead011e8f9a9ce462547e960e05 100644 (file)
@@ -57,6 +57,14 @@ public:
   void send_response();
 };
 
+class RGWGetBucketLocation_ObjStore_S3 : public RGWGetBucketLocation {
+public:
+  RGWGetBucketLocation_ObjStore_S3() {}
+  ~RGWGetBucketLocation_ObjStore_S3() {}
+
+  void send_response();
+};
+
 class RGWStatBucket_ObjStore_S3 : public RGWStatBucket_ObjStore {
 public:
   RGWStatBucket_ObjStore_S3() {}