RGWHTTPClient now holds the url and method.
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
key.key = secret;
param_vec_t params;
- RGWRESTSimpleRequest req(g_ceph_context, url, NULL, ¶ms);
+ RGWRESTSimpleRequest req(g_ceph_context, info.method, url, NULL, ¶ms);
bufferlist response;
int ret = req.forward_request(key, info, MAX_REST_RESPONSE, &in_data, &response);
/* The container for plain response obtained from Keystone. It will be
* parsed token_envelope_t::parse method. */
ceph::bufferlist token_body_bl;
- RGWValidateKeystoneToken validate(cct, &token_body_bl);
+ RGWValidateKeystoneToken validate(cct, "GET", "", &token_body_bl);
std::string url = config.get_endpoint_url();
if (url.empty()) {
validate.append_header("X-Auth-Token", admin_token);
validate.set_send_length(0);
- int ret = validate.process(url.c_str());
+ validate.set_url(url);
+
+ int ret = validate.process();
if (ret < 0) {
throw ret;
}
/* The container for plain response obtained from Keystone. It will be
* parsed token_envelope_t::parse method. */
ceph::bufferlist token_body_bl;
- RGWValidateKeystoneToken validate(cct, &token_body_bl);
+ RGWValidateKeystoneToken validate(cct, "POST", keystone_url, &token_body_bl);
/* set required headers for keystone request */
validate.append_header("X-Auth-Token", admin_token);
validate.set_send_length(os.str().length());
/* send request */
- ret = validate.process("POST", keystone_url.c_str());
+ ret = validate.process();
if (ret < 0) {
ldout(cct, 2) << "s3 keystone: token validation ERROR: "
<< token_body_bl.c_str() << dendl;
secret_url += "v1/secrets/" + std::string(key_id);
bufferlist secret_bl;
- RGWHTTPTransceiver secret_req(cct, &secret_bl);
+ RGWHTTPTransceiver secret_req(cct, "GET", secret_url, &secret_bl);
secret_req.append_header("Accept", "application/octet-stream");
secret_req.append_header("X-Auth-Token", barbican_token);
- res = secret_req.process("GET", secret_url.c_str());
+ res = secret_req.process();
if (res < 0) {
return res;
}
return h;
}
-static bool is_upload_request(const char *method)
+static bool is_upload_request(const string& method)
{
- if (method == nullptr) {
- return false;
- }
- return strcmp(method, "POST") == 0 || strcmp(method, "PUT") == 0;
+ return method == "POST" || method == "PUT";
}
/*
* process a single simple one off request, not going through RGWHTTPManager. Not using
* req_data.
*/
-int RGWHTTPClient::process(const char *method, const char *url)
+int RGWHTTPClient::process()
{
int ret = 0;
CURL *curl_handle;
char error_buf[CURL_ERROR_SIZE];
- last_method = (method ? method : "");
- last_url = (url ? url : "");
-
auto ca = handles->get_curl_handle();
curl_handle = **ca;
curl_slist *h = headers_to_slist(headers);
- curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, method);
- curl_easy_setopt(curl_handle, CURLOPT_URL, url);
+ curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, method.c_str());
+ curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, simple_receive_http_header);
string RGWHTTPClient::to_str()
{
- string method_str = (last_method.empty() ? "<no-method>" : last_method);
- string url_str = (last_url.empty() ? "<no-url>" : last_url);
+ string method_str = (method.empty() ? "<no-method>" : method);
+ string url_str = (url.empty() ? "<no-url>" : url);
return method_str + " " + url_str;
}
/*
* init request, will be used later with RGWHTTPManager
*/
-int RGWHTTPClient::init_request(const char *method, const char *url, rgw_http_req_data *_req_data, bool send_data_hint)
+int RGWHTTPClient::init_request(rgw_http_req_data *_req_data, bool send_data_hint)
{
assert(!req_data);
_req_data->get();
req_data->h = h;
- last_method = (method ? method : "");
- last_url = (url ? url : "");
-
- curl_easy_setopt(easy_handle, CURLOPT_CUSTOMREQUEST, method);
- curl_easy_setopt(easy_handle, CURLOPT_URL, url);
+ curl_easy_setopt(easy_handle, CURLOPT_CUSTOMREQUEST, method.c_str());
+ curl_easy_setopt(easy_handle, CURLOPT_URL, url.c_str());
curl_easy_setopt(easy_handle, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(easy_handle, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(easy_handle, CURLOPT_HEADERFUNCTION, receive_http_header);
}
}
-int RGWHTTPManager::add_request(RGWHTTPClient *client, const char *method, const char *url, bool send_data_hint)
+int RGWHTTPManager::add_request(RGWHTTPClient *client, bool send_data_hint)
{
rgw_http_req_data *req_data = new rgw_http_req_data;
- int ret = client->init_request(method, url, req_data, send_data_hint);
+ int ret = client->init_request(req_data, send_data_hint);
if (ret < 0) {
req_data->put();
req_data = NULL;
void *user_info;
- string last_method;
- string last_url;
bool verify_ssl; // Do not validate self signed certificates, default to false
std::atomic<unsigned> stopped { 0 };
protected:
CephContext *cct;
+
+ string method;
+ string url;
+
param_vec_t headers;
RGWHTTPManager *get_manager();
- int init_request(const char *method,
- const char *url,
- rgw_http_req_data *req_data,
+ int init_request(rgw_http_req_data *req_data,
bool send_data_hint = false);
virtual int receive_header(void *ptr, size_t len) {
static const long HTTP_STATUS_NOTFOUND = 404;
virtual ~RGWHTTPClient();
- explicit RGWHTTPClient(CephContext *cct)
+ explicit RGWHTTPClient(CephContext *cct,
+ const string& _method,
+ const string& _url)
: send_len(0),
has_send_len(false),
http_status(HTTP_STATUS_NOSTATUS),
req_data(nullptr),
user_info(nullptr),
verify_ssl(cct->_conf->rgw_verify_ssl),
- cct(cct) {
+ cct(cct),
+ method(_method),
+ url(_url) {
}
void set_user_info(void *info) {
verify_ssl = flag;
}
- int process(const char *method, const char *url);
- int process(const char *url) { return process("GET", url); }
+ int process();
int wait();
rgw_http_req_data *get_req_data() { return req_data; }
string to_str();
int get_req_retcode();
+
+ void set_url(const string& _url) {
+ url = _url;
+ }
+
+ void set_method(const string& _method) {
+ method = _method;
+ }
};
typedef std::set<header_name_t, ltstr_nocase> header_spec_t;
RGWHTTPHeadersCollector(CephContext * const cct,
+ const string& method,
+ const string& url,
const header_spec_t &relevant_headers)
- : RGWHTTPClient(cct),
+ : RGWHTTPClient(cct, method, url),
relevant_headers(relevant_headers) {
}
public:
RGWHTTPTransceiver(CephContext * const cct,
+ const string& method,
+ const string& url,
bufferlist * const read_bl,
const header_spec_t intercept_headers = {})
- : RGWHTTPHeadersCollector(cct, intercept_headers),
+ : RGWHTTPHeadersCollector(cct, method, url, intercept_headers),
read_bl(read_bl),
post_data_index(0) {
}
RGWHTTPTransceiver(CephContext * const cct,
+ const string& method,
+ const string& url,
bufferlist * const read_bl,
const bool verify_ssl,
const header_spec_t intercept_headers = {})
- : RGWHTTPHeadersCollector(cct, intercept_headers),
+ : RGWHTTPHeadersCollector(cct, method, url, intercept_headers),
read_bl(read_bl),
post_data_index(0) {
set_verify_ssl(verify_ssl);
int set_threaded();
void stop();
- int add_request(RGWHTTPClient *client, const char *method, const char *url,
- bool send_data_hint = false);
+ int add_request(RGWHTTPClient *client, bool send_data_hint = false);
int remove_request(RGWHTTPClient *client);
int set_request_state(RGWHTTPClient *client, RGWHTTPRequestSetState state);
}
bufferlist token_bl;
- RGWGetKeystoneAdminToken token_req(cct, &token_bl);
+ RGWGetKeystoneAdminToken token_req(cct, "POST", "", &token_bl);
token_req.append_header("Content-Type", "application/json");
JSONFormatter jf;
return -ENOTSUP;
}
- const int ret = token_req.process("POST", token_url.c_str());
+ token_req.set_url(token_url);
+
+ const int ret = token_req.process();
if (ret < 0) {
return ret;
}
}
bufferlist token_bl;
- RGWKeystoneHTTPTransceiver token_req(cct, &token_bl);
+ RGWKeystoneHTTPTransceiver token_req(cct, "POST", "", &token_bl);
token_req.append_header("Content-Type", "application/json");
JSONFormatter jf;
return -ENOTSUP;
}
+ token_req.set_url(token_url);
+
ldout(cct, 20) << "Requesting secret from barbican url=" << token_url << dendl;
- const int ret = token_req.process("POST", token_url.c_str());
+ const int ret = token_req.process();
if (ret < 0) {
ldout(cct, 20) << "Barbican process error:" << token_bl.c_str() << dendl;
return ret;
std::string token;
bufferlist bl;
- RGWGetRevokedTokens req(cct, &bl);
+ RGWGetRevokedTokens req(cct, "GET", "", &bl);
if (rgw::keystone::Service::get_admin_token(cct, *cache, config, token) < 0) {
return -EINVAL;
url.append("v3/auth/tokens/OS-PKI/revoked");
}
+ req.set_url(url);
+
req.set_send_length(0);
- int ret = req.process(url.c_str());
+ int ret = req.process();
if (ret < 0) {
return ret;
}
class RGWKeystoneHTTPTransceiver : public RGWHTTPTransceiver {
public:
RGWKeystoneHTTPTransceiver(CephContext * const cct,
+ const string& method,
+ const string& url,
bufferlist * const token_body_bl)
- : RGWHTTPTransceiver(cct, token_body_bl,
+ : RGWHTTPTransceiver(cct, method, url, token_body_bl,
cct->_conf->rgw_keystone_verify_ssl,
{ "X-Subject-Token" }) {
}
date_str = rgw_to_asctime(ceph_clock_now());
}
-int RGWRESTSimpleRequest::execute(RGWAccessKey& key, const char *method, const char *resource)
+int RGWRESTSimpleRequest::execute(RGWAccessKey& key, const char *_method, const char *resource)
{
+ method = _method;
string new_url = url;
string new_resource = resource;
new_resource.append(resource);
}
new_url.append(new_resource);
+ url = new_url;
string date_str;
get_new_date_str(date_str);
string canonical_header;
map<string, string> meta_map;
map<string, string> sub_resources;
- rgw_create_s3_canonical_header(method, NULL, NULL, date_str.c_str(),
- meta_map, new_url.c_str(), sub_resources,
+ rgw_create_s3_canonical_header(method.c_str(), NULL, NULL, date_str.c_str(),
+ meta_map, url.c_str(), sub_resources,
canonical_header);
string digest;
ldout(cct, 15) << "generated auth header: " << auth_hdr << dendl;
headers.push_back(pair<string, string>("AUTHORIZATION", auth_hdr));
- int r = process(method, new_url.c_str());
+ int r = process();
if (r < 0)
return r;
set_send_length(inbl->length());
}
- int r = process(new_info.method, new_url.c_str());
+ method = new_info.method;
+ url = new_url;
+
+ int r = process();
if (r < 0){
if (r == -EINVAL){
// curl_easy has errored, generally means the service is not available
set_send_length(obj_size);
- int r = http_manager.add_request(this, new_info.method, new_url.c_str());
+ method = new_info.method;
+ url = new_url;
+
+ int r = http_manager.add_request(this);
if (r < 0)
return r;
new_env.set(iter->first.c_str(), iter->second.c_str());
}
- new_info.method = method;
+ new_info.method = method.c_str();
new_info.script_uri = "/";
new_info.script_uri.append(new_resource);
bool send_data_hint = false;
if (send_data) {
- outbl.claim(*send_data);
+ set_outbl(*send_data);
send_data_hint = true;
}
set_send_length(send_size);
}
- int r = pmanager->add_request(this, new_info.method, new_url.c_str(), send_data_hint);
+ method = new_info.method;
+ url = new_url;
+
+ int r = pmanager->add_request(this, send_data_hint);
if (r < 0)
return r;
return status;
}
-int RGWRESTStreamRWRequest::handle_header(const string& name, const string& val)
+int RGWHTTPStreamRWRequest::handle_header(const string& name, const string& val)
{
if (name == "RGWX_EMBEDDED_METADATA_LEN") {
string err;
return 0;
}
-int RGWRESTStreamRWRequest::receive_data(void *ptr, size_t len)
+int RGWHTTPStreamRWRequest::receive_data(void *ptr, size_t len)
{
bufferptr bp((const char *)ptr, len);
bufferlist bl;
return len;
}
-void RGWRESTStreamRWRequest::set_stream_write(bool s) {
+void RGWHTTPStreamRWRequest::set_stream_write(bool s) {
Mutex::Locker wl(write_lock);
stream_writes = s;
}
-void RGWRESTStreamRWRequest::add_send_data(bufferlist& bl)
+void RGWHTTPStreamRWRequest::add_send_data(bufferlist& bl)
{
Mutex::Locker req_locker(get_req_lock());
Mutex::Locker wl(write_lock);
_set_write_paused(false);
}
-void RGWRESTStreamRWRequest::finish_write()
+void RGWHTTPStreamRWRequest::finish_write()
{
Mutex::Locker req_locker(get_req_lock());
Mutex::Locker wl(write_lock);
_set_write_paused(false);
}
-int RGWRESTStreamRWRequest::send_data(void *ptr, size_t len, bool *pause)
+int RGWHTTPStreamRWRequest::send_data(void *ptr, size_t len, bool *pause)
{
Mutex::Locker wl(write_lock);
int http_status;
int status;
- string url;
-
map<string, string> out_headers;
param_vec_t params;
int sign_request(RGWAccessKey& key, RGWEnv& env, req_info& info);
public:
- RGWRESTSimpleRequest(CephContext *_cct, const string& _url, param_vec_t *_headers,
- param_vec_t *_params) : RGWHTTPClient(_cct), http_status(0), status(0),
- url(_url), send_iter(NULL),
+ RGWRESTSimpleRequest(CephContext *_cct, const string& _method, const string& _url,
+ param_vec_t *_headers, param_vec_t *_params) : RGWHTTPClient(_cct, _method, _url),
+ http_status(0), status(0),
+ send_iter(NULL),
max_response(0) {
set_headers(_headers);
set_params(_params);
int add_output_data(bufferlist& bl);
int send_data(void *ptr, size_t len) override;
- RGWRESTStreamWriteRequest(CephContext *_cct, const string& _url, param_vec_t *_headers,
- param_vec_t *_params) : RGWRESTSimpleRequest(_cct, _url, _headers, _params),
+ RGWRESTStreamWriteRequest(CephContext *_cct, const string& _method, const string& _url, param_vec_t *_headers,
+ param_vec_t *_params) : RGWRESTSimpleRequest(_cct, _method, _url, _headers, _params),
lock("RGWRESTStreamWriteRequest"), cb(NULL), http_manager(_cct) {}
~RGWRESTStreamWriteRequest() override;
int put_obj_init(RGWAccessKey& key, rgw_obj& obj, uint64_t obj_size, map<string, bufferlist>& attrs);
RGWGetDataCB *get_out_cb() { return cb; }
};
-class RGWRESTStreamRWRequest : public RGWRESTSimpleRequest {
+class RGWHTTPStreamRWRequest : public RGWRESTSimpleRequest {
Mutex lock;
Mutex write_lock;
RGWGetDataCB *cb;
bufferlist in_data;
size_t chunk_ofs{0};
size_t ofs{0};
- RGWHTTPManager http_manager;
- const char *method;
uint64_t write_ofs{0};
bool send_paused{false};
bool stream_writes{false};
int send_data(void *ptr, size_t len, bool *pause) override;
int receive_data(void *ptr, size_t len) override;
- RGWRESTStreamRWRequest(CephContext *_cct, const char *_method, const string& _url, RGWGetDataCB *_cb,
- param_vec_t *_headers, param_vec_t *_params) : RGWRESTSimpleRequest(_cct, _url, _headers, _params),
- lock("RGWRESTStreamRWRequest"), write_lock("RGWRESTStreamRWRequest::write_lock"), cb(_cb),
- http_manager(_cct), method(_method) {
+ RGWHTTPStreamRWRequest(CephContext *_cct, const string& _method, const string& _url, RGWGetDataCB *_cb,
+ param_vec_t *_headers, param_vec_t *_params) : RGWRESTSimpleRequest(_cct, _method, _url, _headers, _params),
+ lock("RGWRESTStreamRWRequest"), write_lock("RGWRESTStreamRWRequest::write_lock"), cb(_cb) {
}
- virtual ~RGWRESTStreamRWRequest() override {}
- int send_request(RGWAccessKey& key, map<string, string>& extra_headers, rgw_obj& obj, RGWHTTPManager *mgr = NULL);
- int send_request(RGWAccessKey *key, map<string, string>& extra_headers, const string& resource, bufferlist *send_data = NULL /* optional input data */, RGWHTTPManager *mgr = NULL);
- int complete_request(string& etag, real_time *mtime, uint64_t *psize, map<string, string>& attrs);
+ virtual ~RGWHTTPStreamRWRequest() override {}
void set_outbl(bufferlist& _outbl) {
outbl.swap(_outbl);
void finish_write();
};
+class RGWRESTStreamRWRequest : public RGWHTTPStreamRWRequest {
+ RGWHTTPManager http_manager;
+public:
+ RGWRESTStreamRWRequest(CephContext *_cct, const string& _method, const string& _url, RGWGetDataCB *_cb,
+ param_vec_t *_headers, param_vec_t *_params) : RGWHTTPStreamRWRequest(_cct, _method, _url, _cb, _headers, _params),
+ http_manager(_cct) {
+ }
+ virtual ~RGWRESTStreamRWRequest() override {}
+ int send_request(RGWAccessKey& key, map<string, string>& extra_headers, rgw_obj& obj, RGWHTTPManager *mgr = NULL);
+ int send_request(RGWAccessKey *key, map<string, string>& extra_headers, const string& resource, bufferlist *send_data = NULL /* optional input data */, RGWHTTPManager *mgr = NULL);
+ int complete_request(string& etag, real_time *mtime, uint64_t *psize, map<string, string>& attrs);
+};
+
class RGWRESTStreamReadRequest : public RGWRESTStreamRWRequest {
public:
RGWRESTStreamReadRequest(CephContext *_cct, const string& _url, RGWGetDataCB *_cb, param_vec_t *_headers,
snprintf(buf, sizeof(buf), "%lld", (long long)objv->ver);
params.push_back(param_pair_t(RGW_SYS_PARAM_PREFIX "ver", buf));
}
- RGWRESTSimpleRequest req(cct, url, NULL, ¶ms);
+ RGWRESTSimpleRequest req(cct, info.method, url, NULL, ¶ms);
return req.forward_request(key, info, max_response, inbl, outbl);
}
param_vec_t params;
populate_params(params, &uid, self_zone_group);
- RGWRESTStreamWriteRequest *wr = new RGWRESTStreamWriteRequest(cct, url, NULL, ¶ms);
+ RGWRESTStreamWriteRequest *wr = new RGWRESTStreamWriteRequest(cct, "PUT", url, NULL, ¶ms);
ret = wr->put_obj_init(key, obj, obj_size, attrs);
if (ret < 0) {
delete wr;
char url_buf[auth_url.size() + 1 + token.length() + 1];
sprintf(url_buf, "%s/%s", auth_url.c_str(), token.c_str());
- RGWHTTPHeadersCollector validator(cct, { "X-Auth-Groups", "X-Auth-Ttl" });
+ RGWHTTPHeadersCollector validator(cct, "GET", url_buf, { "X-Auth-Groups", "X-Auth-Ttl" });
ldout(cct, 10) << "rgw_swift_validate_token url=" << url_buf << dendl;
- int ret = validator.process(url_buf);
+ int ret = validator.process();
if (ret < 0) {
throw ret;
}