[ui] Implement provider test button #49
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2025-04-23 15:31:37 -05:00
parent fcaade316f
commit de5eb1005c
5 changed files with 48 additions and 61 deletions

View File

@ -53,9 +53,6 @@ private:
std::optional<host_config> host_config_;
std::optional<s3_config> 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

View File

@ -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

View File

@ -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,28 +117,23 @@ 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_)
return make_request(s3_config_.has_value()
? create_host_config(s3_config_.value())
: host_config_.value_or(host_config{}),
del, response_code, stop_requested);
}
@ -147,9 +141,8 @@ auto curl_comm::make_request(const curl::requests::http_delete &del,
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_)
return make_request(s3_config_.has_value()
? create_host_config(s3_config_.value())
: host_config_.value_or(host_config{}),
get, response_code, stop_requested);
}
@ -157,9 +150,8 @@ auto curl_comm::make_request(const curl::requests::http_get &get,
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_)
return make_request(s3_config_.has_value()
? create_host_config(s3_config_.value())
: host_config_.value_or(host_config{}),
head, response_code, stop_requested);
}
@ -167,9 +159,8 @@ auto curl_comm::make_request(const curl::requests::http_head &head,
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_)
return make_request(s3_config_.has_value()
? create_host_config(s3_config_.value())
: host_config_.value_or(host_config{}),
post, response_code, stop_requested);
}
@ -177,9 +168,8 @@ auto curl_comm::make_request(const curl::requests::http_post &post,
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_)
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);
}

View File

@ -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<service_start_begin>(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<service_start_end>(function_name,
"s3_provider");

View File

@ -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());