Merge branch 'development' of ssh://git.fifthgrid.com:3022/BlockStorage/repertory into development
This commit is contained in:
commit
a605d7af11
@ -69,6 +69,12 @@ private:
|
|||||||
bool &is_encrypted, std::string &object_name,
|
bool &is_encrypted, std::string &object_name,
|
||||||
head_object_result &result) const -> api_error;
|
head_object_result &result) const -> api_error;
|
||||||
|
|
||||||
|
[[nodiscard]] auto
|
||||||
|
get_object_list(std::string &response_data, long &response_code,
|
||||||
|
std::optional<std::string> delimiter = std::nullopt,
|
||||||
|
std::optional<std::string> prefix = std::nullopt) const
|
||||||
|
-> bool;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
|
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
|
||||||
-> std::uint64_t override;
|
-> std::uint64_t override;
|
||||||
|
20
src/main.cpp
20
src/main.cpp
@ -56,11 +56,11 @@ auto main(int argc, char **argv) -> int {
|
|||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
argc++;
|
argc++;
|
||||||
static std::string cmd(argv[0U]);
|
static std::string cmd(argv[0U]);
|
||||||
static std::vector<const char *> v({&cmd[0U], "-h"});
|
static std::vector<const char *> v({cmd.data(), "-h"});
|
||||||
argv = (char **)&v[0U];
|
argv = (char **)v.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pt = utils::cli::get_provider_type_from_args(argc, argv);
|
auto prov = utils::cli::get_provider_type_from_args(argc, argv);
|
||||||
|
|
||||||
std::string data_directory;
|
std::string data_directory;
|
||||||
auto res = utils::cli::parse_string_option(
|
auto res = utils::cli::parse_string_option(
|
||||||
@ -81,7 +81,7 @@ auto main(int argc, char **argv) -> int {
|
|||||||
std::string remote_host;
|
std::string remote_host;
|
||||||
std::uint16_t remote_port{};
|
std::uint16_t remote_port{};
|
||||||
std::string unique_id;
|
std::string unique_id;
|
||||||
if ((res == exit_code::success) && (pt == provider_type::remote)) {
|
if ((res == exit_code::success) && (prov == provider_type::remote)) {
|
||||||
std::string data;
|
std::string data;
|
||||||
if ((res = utils::cli::parse_string_option(
|
if ((res = utils::cli::parse_string_option(
|
||||||
argc, argv, utils::cli::options::remote_mount_option, data)) ==
|
argc, argv, utils::cli::options::remote_mount_option, data)) ==
|
||||||
@ -98,7 +98,7 @@ auto main(int argc, char **argv) -> int {
|
|||||||
try {
|
try {
|
||||||
remote_port = utils::string::to_uint16(parts[1U]);
|
remote_port = utils::string::to_uint16(parts[1U]);
|
||||||
data_directory = utils::path::combine(
|
data_directory = utils::path::combine(
|
||||||
data_directory.empty() ? app_config::default_data_directory(pt)
|
data_directory.empty() ? app_config::default_data_directory(prov)
|
||||||
: data_directory,
|
: data_directory,
|
||||||
{utils::string::replace_copy(unique_id, ':', '_')});
|
{utils::string::replace_copy(unique_id, ':', '_')});
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
@ -111,7 +111,7 @@ auto main(int argc, char **argv) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef REPERTORY_ENABLE_S3
|
#ifdef REPERTORY_ENABLE_S3
|
||||||
if ((res == exit_code::success) && (pt == provider_type::s3)) {
|
if ((res == exit_code::success) && (prov == provider_type::s3)) {
|
||||||
std::string data;
|
std::string data;
|
||||||
if ((res = utils::cli::parse_string_option(argc, argv,
|
if ((res = utils::cli::parse_string_option(argc, argv,
|
||||||
utils::cli::options::name_option,
|
utils::cli::options::name_option,
|
||||||
@ -122,7 +122,7 @@ auto main(int argc, char **argv) -> int {
|
|||||||
res = exit_code::invalid_syntax;
|
res = exit_code::invalid_syntax;
|
||||||
} else {
|
} else {
|
||||||
data_directory = utils::path::combine(
|
data_directory = utils::path::combine(
|
||||||
data_directory.empty() ? app_config::default_data_directory(pt)
|
data_directory.empty() ? app_config::default_data_directory(prov)
|
||||||
: data_directory,
|
: data_directory,
|
||||||
{unique_id});
|
{unique_id});
|
||||||
}
|
}
|
||||||
@ -145,11 +145,11 @@ auto main(int argc, char **argv) -> int {
|
|||||||
idx++) {
|
idx++) {
|
||||||
res = cli::actions::perform_action(
|
res = cli::actions::perform_action(
|
||||||
utils::cli::options::option_list[idx], argc, argv, data_directory,
|
utils::cli::options::option_list[idx], argc, argv, data_directory,
|
||||||
pt, unique_id, user, password);
|
prov, unique_id, user, password);
|
||||||
}
|
}
|
||||||
if (res == exit_code::option_not_found) {
|
if (res == exit_code::option_not_found) {
|
||||||
res = cli::actions::mount(argc, argv, data_directory, mount_result, pt,
|
res = cli::actions::mount(argc, argv, data_directory, mount_result,
|
||||||
remote_host, remote_port, unique_id);
|
prov, remote_host, remote_port, unique_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,34 +40,6 @@
|
|||||||
#include "utils/string_utils.hpp"
|
#include "utils/string_utils.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
namespace {
|
|
||||||
[[nodiscard]] auto
|
|
||||||
get_object_list(i_http_comm &client, const s3_config &config,
|
|
||||||
std::string &response_data, long &response_code,
|
|
||||||
std::optional<std::string> delimiter = std::nullopt,
|
|
||||||
std::optional<std::string> prefix = std::nullopt) -> bool {
|
|
||||||
curl::requests::http_get get{};
|
|
||||||
get.allow_timeout = true;
|
|
||||||
get.aws_service = "aws:amz:" + config.region + ":s3";
|
|
||||||
get.path = '/';
|
|
||||||
get.query["list-type"] = "2";
|
|
||||||
if (delimiter.has_value() && not delimiter.value().empty()) {
|
|
||||||
get.query["delimiter"] = delimiter.value();
|
|
||||||
}
|
|
||||||
if (prefix.has_value() && not prefix.value().empty()) {
|
|
||||||
get.query["prefix"] = prefix.value();
|
|
||||||
utils::string::left_trim(get.query["prefix"], '/');
|
|
||||||
}
|
|
||||||
get.response_handler = [&response_data](const data_buffer &data,
|
|
||||||
long /*response_code*/) {
|
|
||||||
response_data = std::string(data.begin(), data.end());
|
|
||||||
};
|
|
||||||
|
|
||||||
stop_type stop_requested{};
|
|
||||||
return client.make_request(get, response_code, stop_requested);
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
s3_provider::s3_provider(app_config &config, i_http_comm &comm)
|
s3_provider::s3_provider(app_config &config, i_http_comm &comm)
|
||||||
: base_provider(config, comm) {
|
: base_provider(config, comm) {
|
||||||
get_comm().enable_s3_path_style(config.get_s3_config().use_path_style);
|
get_comm().enable_s3_path_style(config.get_s3_config().use_path_style);
|
||||||
@ -246,8 +218,7 @@ auto s3_provider::get_directory_item_count(const std::string &api_path) const
|
|||||||
long response_code{};
|
long response_code{};
|
||||||
auto prefix = object_name.empty() ? object_name : object_name + "/";
|
auto prefix = object_name.empty() ? object_name : object_name + "/";
|
||||||
|
|
||||||
if (not get_object_list(get_comm(), get_config().get_s3_config(),
|
if (not get_object_list(response_data, response_code, "/", prefix)) {
|
||||||
response_data, response_code, "/", prefix)) {
|
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +271,7 @@ auto s3_provider::get_directory_items(const std::string &api_path,
|
|||||||
const auto is_encrypted = not cfg.encryption_token.empty();
|
const auto is_encrypted = not cfg.encryption_token.empty();
|
||||||
std::string key;
|
std::string key;
|
||||||
if (is_encrypted) {
|
if (is_encrypted) {
|
||||||
auto res = get_item_meta(api_path, META_KEY, key);
|
res = get_item_meta(api_path, META_KEY, key);
|
||||||
if (res != api_error::success) {
|
if (res != api_error::success) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -315,8 +286,7 @@ auto s3_provider::get_directory_items(const std::string &api_path,
|
|||||||
long response_code{};
|
long response_code{};
|
||||||
auto prefix = object_name.empty() ? object_name : object_name + "/";
|
auto prefix = object_name.empty() ? object_name : object_name + "/";
|
||||||
|
|
||||||
if (not get_object_list(get_comm(), get_config().get_s3_config(),
|
if (not get_object_list(response_data, response_code, "/", prefix)) {
|
||||||
response_data, response_code, "/", prefix)) {
|
|
||||||
return api_error::comm_error;
|
return api_error::comm_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,7 +313,7 @@ auto s3_provider::get_directory_items(const std::string &api_path,
|
|||||||
std::string child_object_name;
|
std::string child_object_name;
|
||||||
if (is_encrypted) {
|
if (is_encrypted) {
|
||||||
child_object_name = child_api_path;
|
child_object_name = child_api_path;
|
||||||
auto res = utils::encryption::decrypt_file_path(cfg.encryption_token,
|
res = utils::encryption::decrypt_file_path(cfg.encryption_token,
|
||||||
child_api_path);
|
child_api_path);
|
||||||
if (res != api_error::success) {
|
if (res != api_error::success) {
|
||||||
return res;
|
return res;
|
||||||
@ -355,7 +325,7 @@ auto s3_provider::get_directory_items(const std::string &api_path,
|
|||||||
dir_item.api_parent = utils::path::get_parent_api_path(dir_item.api_path);
|
dir_item.api_parent = utils::path::get_parent_api_path(dir_item.api_path);
|
||||||
dir_item.directory = directory;
|
dir_item.directory = directory;
|
||||||
dir_item.size = get_size(dir_item);
|
dir_item.size = get_size(dir_item);
|
||||||
auto res = get_item_meta(child_api_path, dir_item.meta);
|
res = get_item_meta(child_api_path, dir_item.meta);
|
||||||
if (res == api_error::item_not_found) {
|
if (res == api_error::item_not_found) {
|
||||||
if (directory) {
|
if (directory) {
|
||||||
res = create_path_directories(child_api_path, child_object_name);
|
res = create_path_directories(child_api_path, child_object_name);
|
||||||
@ -465,8 +435,7 @@ auto s3_provider::get_file(const std::string &api_path, api_file &file) const
|
|||||||
auto s3_provider::get_file_list(api_file_list &list) const -> api_error {
|
auto s3_provider::get_file_list(api_file_list &list) const -> api_error {
|
||||||
std::string response_data;
|
std::string response_data;
|
||||||
long response_code{};
|
long response_code{};
|
||||||
if (not get_object_list(get_comm(), get_config().get_s3_config(),
|
if (not get_object_list(response_data, response_code)) {
|
||||||
response_data, response_code)) {
|
|
||||||
return api_error::comm_error;
|
return api_error::comm_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,6 +540,32 @@ auto s3_provider::get_object_info(bool directory, const std::string &api_path,
|
|||||||
return api_error::error;
|
return api_error::error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto s3_provider::get_object_list(std::string &response_data,
|
||||||
|
long &response_code,
|
||||||
|
std::optional<std::string> delimiter,
|
||||||
|
std::optional<std::string> prefix) const
|
||||||
|
-> bool {
|
||||||
|
curl::requests::http_get get{};
|
||||||
|
get.allow_timeout = true;
|
||||||
|
get.aws_service = "aws:amz:" + get_config().get_s3_config().region + ":s3";
|
||||||
|
get.path = '/';
|
||||||
|
get.query["list-type"] = "2";
|
||||||
|
if (delimiter.has_value() && not delimiter.value().empty()) {
|
||||||
|
get.query["delimiter"] = delimiter.value();
|
||||||
|
}
|
||||||
|
if (prefix.has_value() && not prefix.value().empty()) {
|
||||||
|
get.query["prefix"] = prefix.value();
|
||||||
|
utils::string::left_trim(get.query["prefix"], '/');
|
||||||
|
}
|
||||||
|
get.response_handler = [&response_data](const data_buffer &data,
|
||||||
|
long /*response_code*/) {
|
||||||
|
response_data = std::string(data.begin(), data.end());
|
||||||
|
};
|
||||||
|
|
||||||
|
stop_type stop_requested{};
|
||||||
|
return get_comm().make_request(get, response_code, stop_requested);
|
||||||
|
}
|
||||||
|
|
||||||
auto s3_provider::get_total_drive_space() const -> std::uint64_t {
|
auto s3_provider::get_total_drive_space() const -> std::uint64_t {
|
||||||
return std::numeric_limits<std::int64_t>::max() / std::int64_t(2);
|
return std::numeric_limits<std::int64_t>::max() / std::int64_t(2);
|
||||||
}
|
}
|
||||||
@ -578,8 +573,7 @@ auto s3_provider::get_total_drive_space() const -> std::uint64_t {
|
|||||||
auto s3_provider::get_used_drive_space() const -> std::uint64_t {
|
auto s3_provider::get_used_drive_space() const -> std::uint64_t {
|
||||||
std::string response_data;
|
std::string response_data;
|
||||||
long response_code{};
|
long response_code{};
|
||||||
if (not get_object_list(get_comm(), get_config().get_s3_config(),
|
if (not get_object_list(response_data, response_code)) {
|
||||||
response_data, response_code)) {
|
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user