From: Casey Bodley Date: Thu, 22 Oct 2015 15:22:02 +0000 (-0400) Subject: radosgw-admin: add send_to_remote_or_url() helper X-Git-Tag: v10.1.0~354^2~299 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ee6d76f487b345b539cdcaccbb21ad23cabcd905;p=ceph.git radosgw-admin: add send_to_remote_or_url() helper Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index fdec1d8ddc7e..e4c5c0b40eff 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -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::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 > params; RGWRESTSimpleRequest req(g_ceph_context, url, NULL, ¶ms); @@ -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;