From ebcebce51a6383e175cec549404781dd1c98a2c0 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Wed, 22 Jan 2025 16:17:14 -0500 Subject: [PATCH] Changes from review. --- tiledb/sm/rest/curl.cc | 15 +++++---------- tiledb/sm/rest/curl.h | 7 ++----- tiledb/sm/rest/rest_client_remote.cc | 7 +++---- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/tiledb/sm/rest/curl.cc b/tiledb/sm/rest/curl.cc index b32e579bf1b..38be5a097a5 100644 --- a/tiledb/sm/rest/curl.cc +++ b/tiledb/sm/rest/curl.cc @@ -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( @@ -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; @@ -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. @@ -940,8 +938,7 @@ 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( @@ -949,8 +946,7 @@ Status Curl::get_data( // 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)); @@ -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); diff --git a/tiledb/sm/rest/curl.h b/tiledb/sm/rest/curl.h index 070b4f7b8ff..43ceeab8022 100644 --- a/tiledb/sm/rest/curl.h +++ b/tiledb/sm/rest/curl.h @@ -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 @@ -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. diff --git a/tiledb/sm/rest/rest_client_remote.cc b/tiledb/sm/rest/rest_client_remote.cc index 3e7aecf6e4a..33c27fd1cca 100644 --- a/tiledb/sm/rest/rest_client_remote.cc +++ b/tiledb/sm/rest/rest_client_remote.cc @@ -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_;