23 const char *user_agent_string =
"cvmfs/" CVMFS_VERSION;
25 CURL *h_curl = curl_easy_init();
28 curl_easy_setopt(h_curl, CURLOPT_NOPROGRESS, 1L);
29 curl_easy_setopt(h_curl, CURLOPT_USERAGENT, user_agent_string);
30 curl_easy_setopt(h_curl, CURLOPT_MAXREDIRS, 50L);
31 curl_easy_setopt(h_curl, CURLOPT_CUSTOMREQUEST, method.c_str());
37 size_t RecvCB(
void *buffer,
size_t size,
size_t nmemb,
void *userp) {
40 if (size * nmemb < 1) {
45 + std::string(static_cast<char *>(buffer), nmemb);
53 const std::string& repo_path,
54 const std::string& repo_service_url,
56 const std::string& metadata) {
57 CURLcode ret =
static_cast<CURLcode
>(0);
65 payloadJson.
Add(
"path", repo_path);
68 if (!metadata.empty()) {
80 const std::string header_str = std::string(
"Authorization: ") + key_id +
" "
82 struct curl_slist *auth_header = NULL;
83 auth_header = curl_slist_append(auth_header, header_str.c_str());
84 curl_easy_setopt(h_curl, CURLOPT_HTTPHEADER, auth_header);
87 curl_easy_setopt(h_curl, CURLOPT_URL, (repo_service_url +
"/leases").c_str());
88 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
89 static_cast<curl_off_t>(payload.length()));
90 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, payload.c_str());
91 curl_easy_setopt(h_curl, CURLOPT_WRITEFUNCTION,
RecvCB);
92 curl_easy_setopt(h_curl, CURLOPT_WRITEDATA, buffer);
94 ret = curl_easy_perform(h_curl);
97 "Make lease acquire request failed: %d. Reply: %s", ret,
98 buffer->
data.c_str());
101 curl_easy_cleanup(h_curl);
108 const std::string& secret,
const std::string& session_token,
109 const std::string& repo_service_url,
110 const std::string& request_payload,
CurlBuffer* reply,
bool expect_final_revision) {
111 CURLcode ret =
static_cast<CURLcode
>(0);
125 const std::string header_str = std::string(
"Authorization: ") + key_id +
" "
127 struct curl_slist *auth_header = NULL;
128 auth_header = curl_slist_append(auth_header, header_str.c_str());
129 curl_easy_setopt(h_curl, CURLOPT_HTTPHEADER, auth_header);
131 curl_easy_setopt(h_curl, CURLOPT_URL,
132 (repo_service_url +
"/leases/" + session_token).c_str());
133 if (request_payload !=
"") {
134 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
135 static_cast<curl_off_t>(request_payload.length()));
136 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, request_payload.c_str());
138 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDSIZE_LARGE,
139 static_cast<curl_off_t>(0));
140 curl_easy_setopt(h_curl, CURLOPT_POSTFIELDS, NULL);
142 curl_easy_setopt(h_curl, CURLOPT_WRITEFUNCTION,
RecvCB);
143 curl_easy_setopt(h_curl, CURLOPT_WRITEDATA, reply);
145 ret = curl_easy_perform(h_curl);
148 "Lease end request - curl_easy_perform failed: %d", ret);
158 const JSON *reply_status =
160 ok = (reply_status != NULL &&
161 std::string(reply_status->string_value) ==
"ok");
164 "Lease end request - error reply: %s",
165 reply->
data.c_str());
169 curl_easy_cleanup(h_curl);
void Add(const std::string &key, const std::string &val)
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, bool expect_final_revision)
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)
std::string GenerateString() const
void AddJsonObject(const std::string &key, const std::string &json)
const JSON * root() const
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)