Skip to content

Commit

Permalink
Changes from review.
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunrd0 committed Jan 22, 2025
1 parent b730bf9 commit ebcebce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
15 changes: 5 additions & 10 deletions tiledb/sm/rest/curl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ std::string Curl::url_escape(const std::string& url) const {
return escaped;
}

Status Curl::set_headers(struct curl_slist** headers, bool use_auth) const {
Status Curl::set_headers(struct curl_slist** headers) const {
CURL* curl = curl_.get();
if (curl == nullptr)
return LOG_STATUS(
Expand All @@ -347,13 +347,13 @@ Status Curl::set_headers(struct curl_slist** headers, bool use_auth) const {
const char* token = nullptr;
RETURN_NOT_OK(config_->get("rest.token", &token));

if (use_auth && token != nullptr) {
if (token != nullptr) {
*headers = curl_slist_append(
*headers, (std::string("X-TILEDB-REST-API-Key: ") + token).c_str());
if (*headers == nullptr)
return LOG_STATUS(Status_RestError(
"Cannot set curl auth; curl_slist_append returned null."));
} else if (use_auth) {
} else {
// Try username+password instead of token
const char* username = nullptr;
const char* password = nullptr;
Expand All @@ -369,8 +369,6 @@ Status Curl::set_headers(struct curl_slist** headers, bool use_auth) const {
std::string basic_auth = username + std::string(":") + password;
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_easy_setopt(curl, CURLOPT_USERPWD, basic_auth.c_str());
} else {
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_NONE);
}

// Add any extra headers.
Expand Down Expand Up @@ -940,17 +938,15 @@ Status Curl::get_data(
const std::string& url,
SerializationType serialization_type,
Buffer* returned_data,
const std::string& res_ns_uri,
bool use_auth) {
const std::string& res_ns_uri) {
CURL* curl = curl_.get();
if (curl == nullptr)
return LOG_STATUS(
Status_RestError("Error getting data; curl instance is null."));

// Set auth and content-type for request
struct curl_slist* headers = nullptr;
RETURN_NOT_OK_ELSE(
set_headers(&headers, use_auth), curl_slist_free_all(headers));
RETURN_NOT_OK_ELSE(set_headers(&headers), curl_slist_free_all(headers));
RETURN_NOT_OK_ELSE(
set_content_type(serialization_type, &headers),
curl_slist_free_all(headers));
Expand All @@ -960,7 +956,6 @@ Status Curl::get_data(

CURLcode ret;
headerData.uri = &res_ns_uri;
headerData.should_cache_redirect = res_ns_uri != "no-cache";
auto st = make_curl_request(stats, url.c_str(), &ret, nullptr, returned_data);
curl_slist_free_all(headers);
RETURN_NOT_OK(st);
Expand Down
7 changes: 2 additions & 5 deletions tiledb/sm/rest/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ class Curl {
const std::string& url,
SerializationType serialization_type,
Buffer* returned_data,
const std::string& res_ns_uri,
bool use_auth = true);
const std::string& res_ns_uri);

/**
* Simple wrapper for sending delete requests to server
Expand Down Expand Up @@ -429,11 +428,9 @@ class Curl {
* and any extra headers.
*
* @param headers Headers list (will be modified)
* @param use_auth If true, set headers for HTTP authentication.
* If false, the request will not use authentication.
* @return Status
*/
Status set_headers(struct curl_slist** headers, bool use_auth = true) const;
Status set_headers(struct curl_slist** headers) const;

/**
* Sets the appropriate Content-Type header for the given serialization type.
Expand Down
7 changes: 3 additions & 4 deletions tiledb/sm/rest/rest_client_remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1524,13 +1524,12 @@ const RestCapabilities& RestClientRemote::get_capabilities_from_rest() {

// Init curl and form the URL
Curl curlc(logger_);
throw_if_not_ok(
curlc.init(config_, extra_headers_, &redirect_meta_, &redirect_mtx_));
throw_if_not_ok(curlc.init(
config_, extra_headers_, &redirect_meta_, &redirect_mtx_, false));
const std::string url = rest_server_ + "/v4/version";

Buffer data;
throw_if_not_ok(curlc.get_data(
stats_, url, serialization_type_, &data, "no-cache", false));
throw_if_not_ok(curlc.get_data(stats_, url, serialization_type_, &data, {}));
rest_capabilities_ =
serialization::rest_version_deserialize(serialization_type_, data);
return rest_capabilities_;
Expand Down

0 comments on commit ebcebce

Please sign in to comment.