7 #include "cvmfs_config.h"
19 const char* user_agent_string =
"cvmfs/" VERSION;
21 CURL* h_curl = curl_easy_init();
24 curl_easy_setopt(h_curl, CURLOPT_NOPROGRESS, 1L);
25 curl_easy_setopt(h_curl, CURLOPT_USERAGENT, user_agent_string);
26 curl_easy_setopt(h_curl, CURLOPT_MAXREDIRS, 50L);
27 curl_easy_setopt(h_curl, CURLOPT_CUSTOMREQUEST, method.c_str());
33 size_t RecvCB(
void* buffer,
size_t size,
size_t nmemb,
void* userp) {
36 if (size * nmemb < 1) {
40 my_buffer->
data =
static_cast<char*
>(buffer);
42 return my_buffer->
data.size();
48 const std::string& repo_path,
49 const std::string& repo_service_url,
51 CURLcode ret =
static_cast<CURLcode
>(0);
58 const std::string payload =
"{\"path\" : \"" + repo_path +
59 "\", \"api_version\" : \"" +
65 const std::string header_str = std::string(
"Authorization: ") + key_id +
" " +
67 struct curl_slist* auth_header = NULL;
68 auth_header = curl_slist_append(auth_header, header_str.c_str());
69 curl_easy_setopt(h_curl, CURLOPT_HTTPHEADER, auth_header);
72 curl_easy_setopt(h_curl, CURLOPT_URL, (repo_service_url +
"/leases").c_str());
73 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
74 static_cast<curl_off_t>(payload.length()));
75 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, payload.c_str());
76 curl_easy_setopt(h_curl, CURLOPT_WRITEFUNCTION,
RecvCB);
77 curl_easy_setopt(h_curl, CURLOPT_WRITEDATA, buffer);
79 ret = curl_easy_perform(h_curl);
82 "Make lease acquire request failed: %d. Reply: %s", ret,
83 buffer->
data.c_str());
86 curl_easy_cleanup(h_curl);
93 const std::string& secret,
const std::string& session_token,
94 const std::string& repo_service_url,
95 const std::string& request_payload,
CurlBuffer* reply) {
96 CURLcode ret =
static_cast<CURLcode
>(0);
106 const std::string header_str = std::string(
"Authorization: ") + key_id +
" " +
108 struct curl_slist* auth_header = NULL;
109 auth_header = curl_slist_append(auth_header, header_str.c_str());
110 curl_easy_setopt(h_curl, CURLOPT_HTTPHEADER, auth_header);
112 curl_easy_setopt(h_curl, CURLOPT_URL,
113 (repo_service_url +
"/leases/" + session_token).c_str());
114 if (request_payload !=
"") {
115 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
116 static_cast<curl_off_t>(request_payload.length()));
117 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, request_payload.c_str());
119 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
120 static_cast<curl_off_t>(0));
121 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, NULL);
123 curl_easy_setopt(h_curl, CURLOPT_WRITEFUNCTION,
RecvCB);
124 curl_easy_setopt(h_curl, CURLOPT_WRITEDATA, reply);
126 ret = curl_easy_perform(h_curl);
129 "Lease end request - curl_easy_perform failed: %d", ret);
133 const JSON *reply_status =
135 const bool ok = (reply_status != NULL &&
136 std::string(reply_status->string_value) ==
"ok");
139 "Lease end request - error reply: %s",
140 reply->
data.c_str());
143 curl_easy_cleanup(h_curl);
#define LogCvmfs(source, mask,...)
bool MakeEndRequest(const std::string &method, const std::string &key_id, const std::string &secret, const std::string &session_token, const std::string &repo_service_url, const std::string &request_payload, CurlBuffer *reply)
static JSON * SearchInObject(const JSON *json_object, const std::string &name, const json_type type)
std::string ToString(const bool with_suffix=false) const
static CURL * PrepareCurl(const std::string &method)
static JsonDocument * Create(const std::string &text)
size_t RecvCB(void *buffer, size_t size, size_t nmemb, void *userp)
string StringifyInt(const int64_t value)
string Base64(const string &data)
static void MakeAcquireRequest(const gateway::GatewayKey &key, const std::string &repo_path, const std::string &repo_service_url, int llvl, CurlBuffer *buffer)
void HmacString(const std::string &key, const std::string &content, Any *any_digest)
const JSON * root() const