]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: translate swift request to s3 when forwarding
authorYehuda Sadeh <yehuda@inktank.com>
Mon, 22 Jul 2013 20:33:33 +0000 (13:33 -0700)
committerGreg Farnum <greg@inktank.com>
Mon, 22 Jul 2013 21:24:53 +0000 (14:24 -0700)
When forwarding a swift request to a different region, we
need to use the effective uri, and not just send the one
we got since we use S3 authentication for the forwarded
requests. This is achieved through a new using 'effective_uri'
param on the request info (which in swift ponts to the
plain bucket/object uri without the swift/v1 prefix(.
Also, rename the old req_state::effective_uri to relative_uri
in order to prevent confusion.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
Reviewed-by: Greg Farnum <greg@inktank.com>
src/rgw/rgw_auth_s3.cc
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_rest.cc
src/rgw/rgw_rest_client.cc
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_swift.cc

index bdd458e68b6f6b549eefc71cd1293c6b28adedd8..c93de7cd58a3d8688454558e70740890bf4722e6 100644 (file)
@@ -190,8 +190,14 @@ bool rgw_create_s3_canonical_header(req_info& info, utime_t *header_time, string
   map<string, string>& meta_map = info.x_meta_map;
   map<string, string>& sub_resources = info.args.get_sub_resources();
 
+  string request_uri;
+  if (info.effective_uri.empty())
+    request_uri = info.request_uri;
+  else
+    request_uri = info.effective_uri;
+
   rgw_create_s3_canonical_header(info.method, content_md5, content_type, date.c_str(),
-                            meta_map, info.request_uri.c_str(), sub_resources,
+                            meta_map, request_uri.c_str(), sub_resources,
                             dest);
 
   return true;
index aea396bf3def15db187f7c93516e51b1c0d80b50..8a281775d0774d882cd6bcd7f98161f39425e386 100644 (file)
@@ -109,7 +109,12 @@ void req_info::rebuild_from(req_info& src)
 {
   method = src.method;
   script_uri = src.script_uri;
-  request_uri = src.request_uri;
+  if (src.effective_uri.empty()) {
+    request_uri = src.request_uri;
+  } else {
+    request_uri = src.effective_uri;
+  }
+  effective_uri.clear();
   host = src.host;
 
   x_meta_map = src.x_meta_map;
index 1d3596d44183f32fbcf5022d42c3cad07c7c3721..7f224a798f55c99f41c755baec20f10a05f5f4e6 100644 (file)
@@ -764,6 +764,7 @@ struct req_info {
   const char *method;
   string script_uri;
   string request_uri;
+  string effective_uri;
   string request_params;
 
   req_info(CephContext *cct, RGWEnv *_env);
@@ -780,7 +781,7 @@ struct req_state {
    int format;
    ceph::Formatter *formatter;
    string decoded_uri;
-   string effective_uri;
+   string relative_uri;
    const char *length;
    uint64_t content_length;
    map<string, string> generic_attrs;
index 0f9e61d1740ec5978787d8a713e43fcde9dc7143..e4933a67a3924c7c49ddba587b034c8bd67a4696 100644 (file)
@@ -1242,7 +1242,7 @@ RGWHandler *RGWREST::get_handler(RGWRados *store, struct req_state *s, RGWClient
   if (*init_error < 0)
     return NULL;
 
-  RGWRESTMgr *m = mgr.get_resource_mgr(s, s->decoded_uri, &s->effective_uri);
+  RGWRESTMgr *m = mgr.get_resource_mgr(s, s->decoded_uri, &s->relative_uri);
   if (!m) {
     *init_error = -ERR_METHOD_NOT_ALLOWED;
     return NULL;
index 2075e535525549e56918238f7b5f5f981dd04ada..ea80b5b84f86e8eb07422c8a93f8cf0af41d6da2 100644 (file)
@@ -403,6 +403,7 @@ int RGWRESTStreamWriteRequest::put_obj_init(RGWAccessKey& key, rgw_obj& obj, uin
   new_info.script_uri = "/";
   new_info.script_uri.append(resource);
   new_info.request_uri = new_info.script_uri;
+  new_info.effective_uri = new_info.effective_uri;
 
   map<string, string>& m = new_env.get_map();
   map<string, bufferlist>::iterator bliter;
@@ -568,6 +569,7 @@ int RGWRESTStreamReadRequest::get_obj(RGWAccessKey& key, map<string, string>& ex
   new_info.script_uri = "/";
   new_info.script_uri.append(resource);
   new_info.request_uri = new_info.script_uri;
+  new_info.effective_uri = new_info.effective_uri;
 
   new_info.init_meta_info(NULL);
 
index e131eeee28d0cc54a475059833a01e245aec9dae..6c1738218e6355b2defbf5e1bad8d76f0417ea28 100644 (file)
@@ -1819,7 +1819,7 @@ int RGWHandler_ObjStore_S3::init_from_header(struct req_state *s, int default_fo
   string req;
   string first;
 
-  const char *req_name = s->effective_uri.c_str();
+  const char *req_name = s->relative_uri.c_str();
   const char *p;
 
   if (*req_name == '?') {
index 80438a6556de553834a7c87576b5923ed3658512..877e3711a5e2c0de79aa3f6e93b54ba6e95be41c 100644 (file)
@@ -856,11 +856,16 @@ int RGWHandler_ObjStore_SWIFT::init_from_header(struct req_state *s)
 
   s->bucket_name_str = first;
   s->bucket_name = strdup(s->bucket_name_str.c_str());
+
    
+  s->info.effective_uri = "/" + s->bucket_name_str;
+
   if (req.size()) {
     s->object_str = req;
     s->object = strdup(s->object_str.c_str());
+    s->info.effective_uri.append("/" + s->object_str);
   }
+
   return 0;
 }