From: Abhishek Lekshmanan Date: Mon, 25 Aug 2014 08:31:54 +0000 (+0530) Subject: rgw: Implementation for S3 Get Bucket Location X-Git-Tag: v0.86~142^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d8e672f351e3f34a3e8aa06235c117e5b7d09736;p=ceph.git rgw: Implementation for S3 Get Bucket Location 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 --- diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index a6389c960c2e..6340fb14fb4e 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -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)) diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index b141ed5bd1bc..44994f37dff4 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -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; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 79de0732a2af..bfd88ec747b5 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -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()) { diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 642a41102ed3..d983a6ba625f 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -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() {}