From de5eb1005c06cca169be40ba278c62b9ee46c512 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 23 Apr 2025 15:31:37 -0500 Subject: [PATCH] [ui] Implement provider test button #49 --- .../include/comm/curl/curl_comm.hpp | 8 +-- .../librepertory/include/comm/i_http_comm.hpp | 27 ++++----- .../librepertory/src/comm/curl/curl_comm.cpp | 56 ++++++++----------- .../src/providers/s3/s3_provider.cpp | 6 +- .../repertory_test/src/curl_comm_test.cpp | 12 ++-- 5 files changed, 48 insertions(+), 61 deletions(-) diff --git a/repertory/librepertory/include/comm/curl/curl_comm.hpp b/repertory/librepertory/include/comm/curl/curl_comm.hpp index 72a6a9bb..9965b7ca 100644 --- a/repertory/librepertory/include/comm/curl/curl_comm.hpp +++ b/repertory/librepertory/include/comm/curl/curl_comm.hpp @@ -53,9 +53,6 @@ private: std::optional host_config_; std::optional s3_config_; -private: - bool use_s3_path_style_{false}; - public: [[nodiscard]] static auto create_curl() -> CURL *; @@ -67,8 +64,7 @@ public: const host_config &cfg) -> std::string; - [[nodiscard]] static auto create_host_config(const s3_config &cfg, - bool use_s3_path_style) + [[nodiscard]] static auto create_host_config(const s3_config &cfg) -> host_config; [[nodiscard]] static auto url_encode(CURL *curl, const std::string &data, @@ -237,8 +233,6 @@ public: } public: - void enable_s3_path_style(bool enable) override; - [[nodiscard]] auto make_request(const curl::requests::http_delete &del, long &response_code, stop_type &stop_requested) const diff --git a/repertory/librepertory/include/comm/i_http_comm.hpp b/repertory/librepertory/include/comm/i_http_comm.hpp index e4373b76..79e774c0 100644 --- a/repertory/librepertory/include/comm/i_http_comm.hpp +++ b/repertory/librepertory/include/comm/i_http_comm.hpp @@ -34,28 +34,29 @@ struct i_http_comm { INTERFACE_SETUP(i_http_comm); public: - virtual void enable_s3_path_style(bool enable) = 0; - [[nodiscard]] virtual auto make_request(const curl::requests::http_delete &del, long &response_code, stop_type &stop_requested) const -> bool = 0; - [[nodiscard]] virtual auto - make_request(const curl::requests::http_get &get, long &response_code, - stop_type &stop_requested) const -> bool = 0; + [[nodiscard]] virtual auto make_request(const curl::requests::http_get &get, + long &response_code, + stop_type &stop_requested) const + -> bool = 0; - [[nodiscard]] virtual auto - make_request(const curl::requests::http_head &head, long &response_code, - stop_type &stop_requested) const -> bool = 0; + [[nodiscard]] virtual auto make_request(const curl::requests::http_head &head, + long &response_code, + stop_type &stop_requested) const + -> bool = 0; - [[nodiscard]] virtual auto - make_request(const curl::requests::http_post &post, long &response_code, - stop_type &stop_requested) const -> bool = 0; + [[nodiscard]] virtual auto make_request(const curl::requests::http_post &post, + long &response_code, + stop_type &stop_requested) const + -> bool = 0; [[nodiscard]] virtual auto make_request(const curl::requests::http_put_file &put_file, - long &response_code, - stop_type &stop_requested) const -> bool = 0; + long &response_code, stop_type &stop_requested) const + -> bool = 0; }; } // namespace repertory diff --git a/repertory/librepertory/src/comm/curl/curl_comm.cpp b/repertory/librepertory/src/comm/curl/curl_comm.cpp index e4113e8f..ee795dc7 100644 --- a/repertory/librepertory/src/comm/curl/curl_comm.cpp +++ b/repertory/librepertory/src/comm/curl/curl_comm.cpp @@ -102,8 +102,7 @@ auto curl_comm::reset_curl(CURL *curl_handle) -> CURL * { return curl_handle; } -auto curl_comm::create_host_config(const s3_config &cfg, bool use_s3_path_style) - -> host_config { +auto curl_comm::create_host_config(const s3_config &cfg) -> host_config { host_config host_cfg{}; host_cfg.api_password = cfg.secret_key; host_cfg.api_user = cfg.access_key; @@ -118,70 +117,61 @@ auto curl_comm::create_host_config(const s3_config &cfg, bool use_s3_path_style) } } - if (not use_s3_path_style) { + if (not cfg.use_path_style) { host_cfg.host_name_or_ip = cfg.bucket + '.' + host_cfg.host_name_or_ip; } host_cfg.protocol = cfg.url.substr(0U, pos); - if (use_s3_path_style) { + if (cfg.use_path_style) { host_cfg.path = '/' + cfg.bucket; } return host_cfg; } -void curl_comm::enable_s3_path_style(bool enable) { - use_s3_path_style_ = enable; -} - auto curl_comm::make_request(const curl::requests::http_delete &del, long &response_code, stop_type &stop_requested) const -> bool { - return make_request( - s3_config_.has_value() - ? create_host_config(s3_config_.value(), use_s3_path_style_) - : host_config_.value_or(host_config{}), - del, response_code, stop_requested); + return make_request(s3_config_.has_value() + ? create_host_config(s3_config_.value()) + : host_config_.value_or(host_config{}), + del, response_code, stop_requested); } auto curl_comm::make_request(const curl::requests::http_get &get, long &response_code, stop_type &stop_requested) const -> bool { - return make_request( - s3_config_.has_value() - ? create_host_config(s3_config_.value(), use_s3_path_style_) - : host_config_.value_or(host_config{}), - get, response_code, stop_requested); + return make_request(s3_config_.has_value() + ? create_host_config(s3_config_.value()) + : host_config_.value_or(host_config{}), + get, response_code, stop_requested); } auto curl_comm::make_request(const curl::requests::http_head &head, long &response_code, stop_type &stop_requested) const -> bool { - return make_request( - s3_config_.has_value() - ? create_host_config(s3_config_.value(), use_s3_path_style_) - : host_config_.value_or(host_config{}), - head, response_code, stop_requested); + return make_request(s3_config_.has_value() + ? create_host_config(s3_config_.value()) + : host_config_.value_or(host_config{}), + head, response_code, stop_requested); } auto curl_comm::make_request(const curl::requests::http_post &post, long &response_code, stop_type &stop_requested) const -> bool { - return make_request( - s3_config_.has_value() - ? create_host_config(s3_config_.value(), use_s3_path_style_) - : host_config_.value_or(host_config{}), - post, response_code, stop_requested); + return make_request(s3_config_.has_value() + ? create_host_config(s3_config_.value()) + : host_config_.value_or(host_config{}), + post, response_code, stop_requested); } auto curl_comm::make_request(const curl::requests::http_put_file &put_file, long &response_code, stop_type &stop_requested) const -> bool { - return make_request( - s3_config_.has_value() - ? create_host_config(s3_config_.value(), use_s3_path_style_) - : host_config_.value_or(host_config{}), - put_file, response_code, stop_requested); + return make_request(s3_config_.has_value() + ? create_host_config(s3_config_.value()) + : host_config_.value_or(host_config{}), + put_file, response_code, stop_requested); } auto curl_comm::url_encode(CURL *curl, const std::string &data, diff --git a/repertory/librepertory/src/providers/s3/s3_provider.cpp b/repertory/librepertory/src/providers/s3/s3_provider.cpp index f9929c57..79d7576b 100644 --- a/repertory/librepertory/src/providers/s3/s3_provider.cpp +++ b/repertory/librepertory/src/providers/s3/s3_provider.cpp @@ -57,7 +57,7 @@ namespace { namespace repertory { s3_provider::s3_provider(app_config &config, i_http_comm &comm) - : base_provider(config, comm) {} + : base_provider(config, comm), s3_config_(config.get_s3_config()) {} auto s3_provider::add_if_not_found(api_file &file, const std::string &object_name) const @@ -799,7 +799,7 @@ auto s3_provider::is_online() const -> bool { std::string token; std::string response_data; long response_code{}; - return get_object_list(response_data, response_code, "/", "/", token); + return get_object_list(response_data, response_code, "/", "", token); } catch (const std::exception &e) { utils::error::raise_error(function_name, e, "exception occurred"); } @@ -1073,8 +1073,6 @@ auto s3_provider::start(api_item_added_callback api_item_added, event_system::instance().raise(function_name, "s3_provider"); - s3_config_ = get_config().get_s3_config(); - get_comm().enable_s3_path_style(s3_config_.use_path_style); auto ret = base_provider::start(api_item_added, mgr); event_system::instance().raise(function_name, "s3_provider"); diff --git a/repertory/repertory_test/src/curl_comm_test.cpp b/repertory/repertory_test/src/curl_comm_test.cpp index a2191635..3d4af959 100644 --- a/repertory/repertory_test/src/curl_comm_test.cpp +++ b/repertory/repertory_test/src/curl_comm_test.cpp @@ -30,8 +30,9 @@ TEST(curl_comm_test, can_create_s3_host_config) { config.bucket = "repertory"; config.url = "https://s3.test.com"; config.region = "any"; + config.use_path_style = false; - auto hc = curl_comm::create_host_config(config, false); + auto hc = curl_comm::create_host_config(config); EXPECT_STREQ("https", hc.protocol.c_str()); EXPECT_STREQ("repertory.s3.test.com", hc.host_name_or_ip.c_str()); EXPECT_TRUE(hc.path.empty()); @@ -42,8 +43,9 @@ TEST(curl_comm_test, can_create_s3_host_config_with_path_style) { config.bucket = "repertory"; config.url = "https://s3.test.com"; config.region = "any"; + config.use_path_style = true; - auto hc = curl_comm::create_host_config(config, true); + auto hc = curl_comm::create_host_config(config); EXPECT_STREQ("https", hc.protocol.c_str()); EXPECT_STREQ("s3.test.com", hc.host_name_or_ip.c_str()); EXPECT_STREQ("/repertory", hc.path.c_str()); @@ -55,8 +57,9 @@ TEST(curl_comm_test, can_create_s3_host_config_with_region) { config.url = "https://s3.test.com"; config.region = "any"; config.use_region_in_url = true; + config.use_path_style = false; - auto hc = curl_comm::create_host_config(config, false); + auto hc = curl_comm::create_host_config(config); EXPECT_STREQ("https", hc.protocol.c_str()); EXPECT_STREQ("repertory.s3.any.test.com", hc.host_name_or_ip.c_str()); EXPECT_TRUE(hc.path.empty()); @@ -68,8 +71,9 @@ TEST(curl_comm_test, can_create_s3_host_config_with_region_and_path_style) { config.url = "https://s3.test.com"; config.region = "any"; config.use_region_in_url = true; + config.use_path_style = true; - auto hc = curl_comm::create_host_config(config, true); + auto hc = curl_comm::create_host_config(config); EXPECT_STREQ("https", hc.protocol.c_str()); EXPECT_STREQ("s3.any.test.com", hc.host_name_or_ip.c_str()); EXPECT_STREQ("/repertory", hc.path.c_str());