7 #include "cvmfs_config.h"
21 const char* user_agent_string =
"cvmfs/" VERSION;
23 CURL* h_curl = curl_easy_init();
26 curl_easy_setopt(h_curl, CURLOPT_NOPROGRESS, 1L);
27 curl_easy_setopt(h_curl, CURLOPT_USERAGENT, user_agent_string);
28 curl_easy_setopt(h_curl, CURLOPT_MAXREDIRS, 50L);
29 curl_easy_setopt(h_curl, CURLOPT_CUSTOMREQUEST, method.c_str());
35 size_t RecvCB(
void* buffer,
size_t size,
size_t nmemb,
void* userp) {
38 if (size * nmemb < 1) {
42 my_buffer->
data =
static_cast<char*
>(buffer);
44 return my_buffer->
data.size();
50 const std::string& repo_path,
51 const std::string& repo_service_url,
53 CURLcode ret =
static_cast<CURLcode
>(0);
60 const std::string payload =
"{\"path\" : \"" + repo_path +
61 "\", \"api_version\" : \"" +
72 const std::string header_str = std::string(
"Authorization: ") + key_id +
" " +
74 struct curl_slist* auth_header = NULL;
75 auth_header = curl_slist_append(auth_header, header_str.c_str());
76 curl_easy_setopt(h_curl, CURLOPT_HTTPHEADER, auth_header);
79 curl_easy_setopt(h_curl, CURLOPT_URL, (repo_service_url +
"/leases").c_str());
80 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
81 static_cast<curl_off_t>(payload.length()));
82 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, payload.c_str());
83 curl_easy_setopt(h_curl, CURLOPT_WRITEFUNCTION,
RecvCB);
84 curl_easy_setopt(h_curl, CURLOPT_WRITEDATA, buffer);
86 ret = curl_easy_perform(h_curl);
89 "Make lease acquire request failed: %d. Reply: %s", ret,
90 buffer->
data.c_str());
93 curl_easy_cleanup(h_curl);
100 const std::string& secret,
const std::string& session_token,
101 const std::string& repo_service_url,
102 const std::string& request_payload,
CurlBuffer* reply) {
103 CURLcode ret =
static_cast<CURLcode
>(0);
117 const std::string header_str = std::string(
"Authorization: ") + key_id +
" " +
119 struct curl_slist* auth_header = NULL;
120 auth_header = curl_slist_append(auth_header, header_str.c_str());
121 curl_easy_setopt(h_curl, CURLOPT_HTTPHEADER, auth_header);
123 curl_easy_setopt(h_curl, CURLOPT_URL,
124 (repo_service_url +
"/leases/" + session_token).c_str());
125 if (request_payload !=
"") {
126 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
127 static_cast<curl_off_t>(request_payload.length()));
128 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, request_payload.c_str());
130 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
131 static_cast<curl_off_t>(0));
132 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, NULL);
134 curl_easy_setopt(h_curl, CURLOPT_WRITEFUNCTION,
RecvCB);
135 curl_easy_setopt(h_curl, CURLOPT_WRITEDATA, reply);
137 ret = curl_easy_perform(h_curl);
140 "Lease end request - curl_easy_perform failed: %d", ret);
144 const JSON *reply_status =
146 const bool ok = (reply_status != NULL &&
147 std::string(reply_status->string_value) ==
"ok");
150 "Lease end request - error reply: %s",
151 reply->
data.c_str());
154 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,...)