]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: replace RGWPostHTTPData with RGW[Keystone]HTTPTransceiver.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 6 Apr 2016 15:38:53 +0000 (17:38 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 2 Jun 2016 13:12:10 +0000 (15:12 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_http_client.cc
src/rgw/rgw_http_client.h
src/rgw/rgw_swift.cc

index 1d0872e5e979a3e19bc72aec9e4418e6be6c9a2f..90217ad087b832e7dafe2d5fb855dd830d654500 100644 (file)
@@ -399,7 +399,7 @@ int RGWHTTPHeadersCollector::receive_header(void * const ptr, const size_t len)
   return 0;
 }
 
-int RGWPostHTTPData::send_data(void* ptr, size_t len)
+int RGWHTTPTransceiver::send_data(void* ptr, size_t len)
 {
   int length_to_copy = 0;
   if (post_data_index < post_data.length()) {
@@ -410,41 +410,6 @@ int RGWPostHTTPData::send_data(void* ptr, size_t len)
   return length_to_copy;
 }
 
-int RGWPostHTTPData::receive_header(void *ptr, size_t len) {
-  char line[len + 1];
-
-  char *s = (char *)ptr, *end = (char *)ptr + len;
-  char *p = line;
-  ldout(cct, 20) << "RGWPostHTTPData::receive_header parsing HTTP headers" << dendl;
-
-  while (s != end) {
-    if (*s == '\r') {
-      s++;
-      continue;
-    }
-    if (*s == '\n') {
-      *p = '\0';
-      ldout(cct, 20) << "RGWPostHTTPData::receive_header: line="
-                     << line << dendl;
-      // TODO: fill whatever data required here
-      char *l = line;
-      char *tok = strsep(&l, " \t:");
-      if (tok) {
-        while (l && *l == ' ') {
-          l++;
-        }
-
-        if (strcasecmp(tok, "X-Subject-Token") == 0) {
-          subject_token = l;
-        }
-      }
-    }
-    if (s != end) {
-      *p++ = *s++;
-    }
-  }
-  return 0;
-}
 
 #if HAVE_CURL_MULTI_WAIT
 
index 3603c6cfde9c83e79e41dc549b58750932e9ab3c..f9b9e473b5ba77a6991989c20ea92d5189ebe05e 100644 (file)
@@ -84,14 +84,14 @@ public:
   static const long HTTP_STATUS_UNAUTHORIZED = 401;
 
   virtual ~RGWHTTPClient();
-  explicit RGWHTTPClient(CephContext *_cct)
+  explicit RGWHTTPClient(CephContext *cct)
     : send_len(0),
       has_send_len(false),
       http_status(HTTP_STATUS_NOSTATUS),
       req_data(nullptr),
       user_info(nullptr),
       verify_ssl(true),
-      cct(_cct) {
+      cct(cct) {
   }
 
   void set_user_info(void *info) {
@@ -178,14 +178,27 @@ private:
 };
 
 
-class RGWPostHTTPData : public RGWHTTPClient {
-  bufferlist *bl;
+class RGWHTTPTransceiver : public RGWHTTPHeadersCollector {
+  bufferlist * const read_bl;
   std::string post_data;
   size_t post_data_index;
-  std::string subject_token;
+
 public:
-  RGWPostHTTPData(CephContext *_cct, bufferlist *_bl) : RGWHTTPClient(_cct), bl(_bl), post_data_index(0) {}
-  RGWPostHTTPData(CephContext *_cct, bufferlist *_bl, bool verify_ssl) : RGWHTTPClient(_cct), bl(_bl), post_data_index(0){
+  RGWHTTPTransceiver(CephContext * const cct,
+                     bufferlist * const read_bl,
+                     const header_spec_t intercept_headers = {})
+    : RGWHTTPHeadersCollector(cct, intercept_headers),
+      read_bl(read_bl),
+      post_data_index(0) {
+  }
+
+  RGWHTTPTransceiver(CephContext * const cct,
+                     bufferlist * const read_bl,
+                     const bool verify_ssl,
+                     const header_spec_t intercept_headers = {})
+    : RGWHTTPHeadersCollector(cct, intercept_headers),
+      read_bl(read_bl),
+      post_data_index(0) {
     set_verify_ssl(verify_ssl);
   }
 
@@ -193,21 +206,17 @@ public:
     this->post_data = _post_data;
   }
 
-  std::string get_subject_token() {
-    return subject_token;
-  }
-
 protected:
-  int send_data(void* ptr, size_t len);
+  int send_data(void* ptr, size_t len) override;
 
-  int receive_data(void *ptr, size_t len) {
-    bl->append((char *)ptr, len);
+  int receive_data(void *ptr, size_t len) override {
+    read_bl->append((char *)ptr, len);
     return 0;
   }
-
-  int receive_header(void *ptr, size_t len);
 };
 
+typedef RGWHTTPTransceiver RGWPostHTTPData;
+
 
 class RGWCompletionManager;
 
index 204129926660b25ab7251e637e039ba164eb0eee..dae77b1f4996a6cb214cfdd5f42066e299be3d70 100644 (file)
@@ -105,17 +105,36 @@ int RGWSwift::validate_token(const char *token, struct rgw_swift_auth_info *info
 }
 
 
-typedef RGWPostHTTPData RGWValidateKeystoneToken;
-typedef RGWPostHTTPData RGWGetKeystoneAdminToken;
-typedef RGWPostHTTPData RGWGetRevokedTokens;
+class RGWKeystoneHTTPTransceiver : public RGWHTTPTransceiver {
+public:
+  RGWKeystoneHTTPTransceiver(CephContext * const cct,
+                             bufferlist * const token_body_bl)
+    : RGWHTTPTransceiver(cct, token_body_bl,
+                         cct->_conf->rgw_keystone_verify_ssl,
+                         { "X-Subject-Token" }) {
+  }
+
+  std::string get_subject_token() const {
+    try {
+      return get_header_value("X-Subject-Token");
+    } catch (std::out_of_range&) {
+      return header_value_t();
+    }
+  }
+};
+
+typedef RGWKeystoneHTTPTransceiver RGWValidateKeystoneToken;
+typedef RGWKeystoneHTTPTransceiver RGWGetKeystoneAdminToken;
+typedef RGWKeystoneHTTPTransceiver RGWGetRevokedTokens;
 
 static RGWKeystoneTokenCache *keystone_token_cache = NULL;
 
 int RGWSwift::get_keystone_url(CephContext * const cct,
                                std::string& url)
 {
+  // FIXME: it seems we don't need RGWGetRevokedToken here
   bufferlist bl;
-  RGWGetRevokedTokens req(cct, &bl, cct->_conf->rgw_keystone_verify_ssl);
+  RGWGetRevokedTokens req(cct, &bl);
 
   url = cct->_conf->rgw_keystone_url;
   if (url.empty()) {
@@ -161,7 +180,7 @@ int RGWSwift::get_keystone_admin_token(CephContext * const cct,
   }
 
   bufferlist token_bl;
-  RGWGetKeystoneAdminToken token_req(cct, &token_bl, cct->_conf->rgw_keystone_verify_ssl);
+  RGWGetKeystoneAdminToken token_req(cct, &token_bl);
   token_req.append_header("Content-Type", "application/json");
   JSONFormatter jf;
 
@@ -421,7 +440,7 @@ int RGWSwift::validate_keystone_token(RGWRados *store, const string& token,
 
     /* can't decode, just go to the keystone server for validation */
 
-    RGWValidateKeystoneToken validate(cct, &bl, cct->_conf->rgw_keystone_verify_ssl);
+    RGWValidateKeystoneToken validate(cct, &bl);
 
     string url = g_conf->rgw_keystone_url;
     if (url.empty()) {