Add support for bucket name in Sia provider #16
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
parent
7e45fa9708
commit
0b80e82721
@ -37,6 +37,14 @@
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace {
|
||||
[[nodiscard]] auto get_bucket(repertory::sia_config cfg) -> std::string {
|
||||
repertory::utils::string::trim(cfg.bucket);
|
||||
if (cfg.bucket.empty()) {
|
||||
return "default";
|
||||
}
|
||||
return cfg.bucket;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_last_modified(const nlohmann::json &obj) -> std::uint64_t {
|
||||
try {
|
||||
@ -61,7 +69,7 @@ auto sia_provider::create_directory_impl(
|
||||
curl::requests::http_put_file put_file{};
|
||||
put_file.allow_timeout = true;
|
||||
put_file.path = "/api/worker/objects" + api_path + "/";
|
||||
put_file.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
put_file.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
|
||||
long response_code{};
|
||||
stop_type stop_requested{};
|
||||
@ -287,7 +295,7 @@ auto sia_provider::get_object_info(const std::string &api_path,
|
||||
curl::requests::http_get get{};
|
||||
get.allow_timeout = true;
|
||||
get.path = "/api/bus/objects" + api_path;
|
||||
get.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
get.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
|
||||
get.response_handler = [&object_info](const data_buffer &data,
|
||||
long response_code) {
|
||||
@ -330,7 +338,7 @@ auto sia_provider::get_object_list(const std::string &api_path,
|
||||
curl::requests::http_get get{};
|
||||
get.allow_timeout = true;
|
||||
get.path = "/api/bus/objects" + api_path + "/";
|
||||
get.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
get.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
|
||||
get.response_handler = [&object_list](const data_buffer &data,
|
||||
long response_code) {
|
||||
@ -366,7 +374,7 @@ auto sia_provider::get_total_drive_space() const -> std::uint64_t {
|
||||
curl::requests::http_get get{};
|
||||
get.allow_timeout = true;
|
||||
get.path = "/api/autopilot/config";
|
||||
get.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
get.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
|
||||
json config_data{};
|
||||
get.response_handler = [&config_data](const data_buffer &data,
|
||||
@ -405,7 +413,7 @@ auto sia_provider::get_used_drive_space_impl() const -> std::uint64_t {
|
||||
curl::requests::http_get get{};
|
||||
get.allow_timeout = true;
|
||||
get.path = "/api/bus/stats/objects";
|
||||
get.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
get.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
|
||||
json object_data{};
|
||||
get.response_handler = [&object_data](const data_buffer &data,
|
||||
@ -506,7 +514,7 @@ auto sia_provider::is_online() const -> bool {
|
||||
curl::requests::http_get get{};
|
||||
get.allow_timeout = true;
|
||||
get.path = "/api/bus/consensus/state";
|
||||
get.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
get.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
|
||||
json state_data{};
|
||||
get.response_handler = [&state_data](const data_buffer &data,
|
||||
@ -549,7 +557,7 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
|
||||
|
||||
curl::requests::http_get get{};
|
||||
get.path = "/api/worker/objects" + api_path;
|
||||
get.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
get.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
get.range = {{
|
||||
offset,
|
||||
offset + size - 1U,
|
||||
@ -606,7 +614,7 @@ auto sia_provider::remove_directory_impl(const std::string &api_path)
|
||||
curl::requests::http_delete del{};
|
||||
del.allow_timeout = true;
|
||||
del.path = "/api/bus/objects" + api_path + "/";
|
||||
del.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
del.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
|
||||
long response_code{};
|
||||
stop_type stop_requested{};
|
||||
@ -634,7 +642,7 @@ auto sia_provider::remove_file_impl(const std::string &api_path) -> api_error {
|
||||
curl::requests::http_delete del{};
|
||||
del.allow_timeout = true;
|
||||
del.path = "/api/bus/objects" + api_path;
|
||||
del.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
del.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
|
||||
long response_code{};
|
||||
stop_type stop_requested{};
|
||||
@ -668,7 +676,7 @@ auto sia_provider::rename_file(const std::string &from_api_path,
|
||||
{"mode", "single"},
|
||||
});
|
||||
post.path = "/api/bus/objects/rename";
|
||||
post.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
post.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
|
||||
long response_code{};
|
||||
stop_type stop_requested{};
|
||||
@ -711,7 +719,7 @@ auto sia_provider::upload_file_impl(const std::string &api_path,
|
||||
|
||||
curl::requests::http_put_file put_file{};
|
||||
put_file.path = "/api/worker/objects" + api_path;
|
||||
put_file.query["bucket"] = get_config().get_sia_config().bucket;
|
||||
put_file.query["bucket"] = get_bucket(get_config().get_sia_config());
|
||||
put_file.source_path = source_path;
|
||||
|
||||
long response_code{};
|
||||
|
Loading…
x
Reference in New Issue
Block a user