19 const char *user_agent_string =
"cvmfs/" 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) {
41 + std::string(static_cast<char *>(buffer), nmemb);
49 const std::string &repo_path,
50 const std::string &repo_service_url,
52 CURLcode ret =
static_cast<CURLcode
>(0);
59 const std::string payload =
"{\"path\" : \"" + repo_path
60 +
"\", \"api_version\" : \""
71 const std::string header_str = std::string(
"Authorization: ") + key_id +
" "
73 struct curl_slist *auth_header = NULL;
74 auth_header = curl_slist_append(auth_header, header_str.c_str());
75 curl_easy_setopt(h_curl, CURLOPT_HTTPHEADER, auth_header);
78 curl_easy_setopt(h_curl, CURLOPT_URL, (repo_service_url +
"/leases").c_str());
79 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
80 static_cast<curl_off_t>(payload.length()));
81 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, payload.c_str());
82 curl_easy_setopt(h_curl, CURLOPT_WRITEFUNCTION,
RecvCB);
83 curl_easy_setopt(h_curl, CURLOPT_WRITEDATA, buffer);
85 ret = curl_easy_perform(h_curl);
88 "Make lease acquire request failed: %d. Reply: %s", ret,
89 buffer->
data.c_str());
92 curl_easy_cleanup(h_curl);
99 const std::string &secret,
const std::string &session_token,
100 const std::string &repo_service_url,
101 const std::string &request_payload,
CurlBuffer *reply) {
102 CURLcode ret =
static_cast<CURLcode
>(0);
116 const std::string header_str = std::string(
"Authorization: ") + key_id +
" "
118 struct curl_slist *auth_header = NULL;
119 auth_header = curl_slist_append(auth_header, header_str.c_str());
120 curl_easy_setopt(h_curl, CURLOPT_HTTPHEADER, auth_header);
122 curl_easy_setopt(h_curl, CURLOPT_URL,
123 (repo_service_url +
"/leases/" + session_token).c_str());
124 if (request_payload !=
"") {
125 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
126 static_cast<curl_off_t>(request_payload.length()));
127 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, request_payload.c_str());
129 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
130 static_cast<curl_off_t>(0));
131 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, NULL);
133 curl_easy_setopt(h_curl, CURLOPT_WRITEFUNCTION,
RecvCB);
134 curl_easy_setopt(h_curl, CURLOPT_WRITEDATA, reply);
136 ret = curl_easy_perform(h_curl);
139 "Lease end request - curl_easy_perform failed: %d", ret);
144 reply_json->
root(),
"status", JSON_STRING);
145 const bool ok = (reply_status != NULL
146 && std::string(reply_status->string_value) ==
"ok");
149 "Lease end request - error reply: %s", reply->
data.c_str());
152 curl_easy_cleanup(h_curl);
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)
std::string GetHostname()
static JsonDocument * Create(const std::string &text)
bool ApplySslCertificatePath(CURL *handle) const
void UseSystemCertificatePath()
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
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)