]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
radosgw-admin: add send_to_remote_or_url() helper
authorCasey Bodley <cbodley@redhat.com>
Thu, 22 Oct 2015 15:22:02 +0000 (11:22 -0400)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:20 +0000 (16:13 -0800)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_admin.cc

index fdec1d8ddc7e3130d81f76c21a63815122bc8b50..e4c5c0b40eff25af96b2f04a023db6080a6148c5 100644 (file)
@@ -1270,8 +1270,8 @@ int do_check_object_locator(const string& tenant_name, const string& bucket_name
 }
 
 #define MAX_REST_RESPONSE (128 * 1024) // we expect a very small response
-int send_to_remote_gateway(const string& remote, req_info& info, JSONParser& p,
-                           bufferlist &in_data)
+static int send_to_remote_gateway(const string& remote, req_info& info,
+                                  bufferlist& in_data, JSONParser& parser)
 {
   bufferlist response;
   RGWRESTConn *conn;
@@ -1282,7 +1282,7 @@ int send_to_remote_gateway(const string& remote, req_info& info, JSONParser& p,
     }
     conn = store->rest_master_conn;
   } else {
-    map<string, RGWRESTConn *>::iterator iter = store->zonegroup_conn_map.find(remote);
+    auto iter = store->zonegroup_conn_map.find(remote);
     if (iter == store->zonegroup_conn_map.end()) {
       cerr << "could not find connection to: " << remote << std::endl;
       return -ENOENT;
@@ -1293,16 +1293,16 @@ int send_to_remote_gateway(const string& remote, req_info& info, JSONParser& p,
   if (ret < 0) {
     return ret;
   }
-  ret = p.parse(response.c_str(), response.length());
+  ret = parser.parse(response.c_str(), response.length());
   if (ret < 0) {
-    cout << "failed to parse response" << std::endl;
+    cerr << "failed to parse response" << std::endl;
     return ret;
   }
   return 0;
 }
 
-int send_to_url(const string& url, RGWAccessKey& key, req_info& info,
-                JSONParser& p, bufferlist &in_data)
+static int send_to_url(const string& url, RGWAccessKey& key, req_info& info,
+                       bufferlist& in_data, JSONParser& parser)
 {
   list<pair<string, string> > params;
   RGWRESTSimpleRequest req(g_ceph_context, url, NULL, &params);
@@ -1312,7 +1312,7 @@ int send_to_url(const string& url, RGWAccessKey& key, req_info& info,
   if (ret < 0) {
     return ret;
   }
-  ret = p.parse(response.c_str(), response.length());
+  ret = parser.parse(response.c_str(), response.length());
   if (ret < 0) {
     cout << "failed to parse response" << std::endl;
     return ret;
@@ -1320,6 +1320,25 @@ int send_to_url(const string& url, RGWAccessKey& key, req_info& info,
   return 0;
 }
 
+static int send_to_remote_or_url(const string& remote, const string& url,
+                                 const string& access, const string& secret,
+                                 req_info& info, bufferlist& in_data,
+                                 JSONParser& parser)
+{
+  if (url.empty()) {
+    return send_to_remote_gateway(remote, info, in_data, parser);
+  }
+
+  if (access.empty() || secret.empty()) {
+    cerr << "An --access-key and --secret must be provided with --url." << std::endl;
+    return -EINVAL;
+  }
+  RGWAccessKey key;
+  key.id = access;
+  key.key = secret;
+  return send_to_url(url, key, info, in_data, parser);
+}
+
 static int init_bucket_for_sync(const string& bucket_name, string& bucket_id)
 {
   RGWBucketInfo bucket_info;
@@ -3040,22 +3059,10 @@ int main(int argc, char **argv)
       if (!period_epoch.empty())
         params["epoch"] = period_epoch;
 
-      int ret = 0;
-
       bufferlist bl;
       JSONParser p;
-      if (!url.empty()) {
-        if (access_key.empty() || secret_key.empty()) {
-          cerr << "An --access-key and --secret must be provided with --url." << std::endl;
-          return -EINVAL;
-        }
-        RGWAccessKey key;
-        key.id = access_key;
-        key.key = secret_key;
-        ret = send_to_url(url, key, info, p, bl);
-      } else {
-        ret = send_to_remote_gateway(remote, info, p, bl);
-      }
+      int ret = send_to_remote_or_url(remote, url, access_key, secret_key,
+                                      info, bl, p);
       if (ret < 0) {
         cerr << "request failed: " << cpp_strerror(-ret) << std::endl;
         return ret;