This commit is contained in:
2025-01-01 01:15:11 -06:00
parent bdf85908ca
commit ecb9783f4e

View File

@ -40,9 +40,9 @@
#include "utils/time.hpp" #include "utils/time.hpp"
namespace { namespace {
[[nodiscard]] auto set_request_path(auto &request, [[nodiscard]] auto
const std::string &object_name) set_request_path(auto &request,
-> repertory::api_error { const std::string &object_name) -> repertory::api_error {
request.path = object_name; request.path = object_name;
if (request.path.substr(1U).size() > repertory::max_s3_object_name_length) { if (request.path.substr(1U).size() > repertory::max_s3_object_name_length) {
return repertory::api_error::name_too_long; return repertory::api_error::name_too_long;
@ -56,9 +56,8 @@ namespace repertory {
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) {}
auto s3_provider::add_if_not_found(api_file &file, auto s3_provider::add_if_not_found(
const std::string &object_name) const api_file &file, const std::string &object_name) const -> api_error {
-> api_error {
api_meta_map meta{}; api_meta_map meta{};
auto res = get_item_meta(file.api_path, meta); auto res = get_item_meta(file.api_path, meta);
if (res == api_error::item_not_found) { if (res == api_error::item_not_found) {
@ -85,7 +84,7 @@ auto s3_provider::convert_api_date(std::string_view date) -> std::uint64_t {
utils::string::split(date_parts.at(1U), 'Z', true).at(0U)) * utils::string::split(date_parts.at(1U), 'Z', true).at(0U)) *
1000000UL; 1000000UL;
struct tm tm1{}; struct tm tm1 {};
#if defined(_WIN32) #if defined(_WIN32)
utils::time::strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1); utils::time::strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1);
return nanos + utils::time::windows_time_t_to_unix_time(_mkgmtime(&tm1)); return nanos + utils::time::windows_time_t_to_unix_time(_mkgmtime(&tm1));
@ -160,9 +159,8 @@ auto s3_provider::create_directory_impl(const std::string &api_path,
return api_error::success; return api_error::success;
} }
auto s3_provider::create_directory_paths(const std::string &api_path, auto s3_provider::create_directory_paths(
const std::string &key) const const std::string &api_path, const std::string &key) const -> api_error {
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (api_path == "/") { if (api_path == "/") {
@ -284,16 +282,12 @@ auto s3_provider::create_file_extra(const std::string &api_path,
auto s3_provider::decrypt_object_name(std::string &object_name) const auto s3_provider::decrypt_object_name(std::string &object_name) const
-> api_error { -> api_error {
auto parts = utils::string::split(object_name, '/', false); if (utils::encryption::decrypt_file_path(get_s3_config().encryption_token,
for (auto &part : parts) { object_name)) {
if (not utils::encryption::decrypt_file_name( return api_error::success;
get_s3_config().encryption_token, part)) {
return api_error::decryption_error;
}
} }
object_name = utils::string::join(parts, '/'); return api_error::decryption_error;
return api_error::success;
} }
auto s3_provider::get_directory_item_count(const std::string &api_path) const auto s3_provider::get_directory_item_count(const std::string &api_path) const
@ -373,26 +367,25 @@ auto s3_provider::get_directory_item_count(const std::string &api_path) const
return 0U; return 0U;
} }
auto s3_provider::get_directory_items_impl(const std::string &api_path, auto s3_provider::get_directory_items_impl(
directory_item_list &list) const const std::string &api_path, directory_item_list &list) const -> api_error {
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto &cfg{get_s3_config()}; const auto &cfg{get_s3_config()};
auto is_encrypted{not cfg.encryption_token.empty()}; auto is_encrypted{not cfg.encryption_token.empty()};
const auto add_diretory_item = [this, &cfg, &is_encrypted, &list]( const auto add_diretory_item =
const std::string &child_object_name, [this, &is_encrypted, &list](const std::string &child_object_name,
bool directory, auto node) -> api_error { bool directory, auto node) -> api_error {
auto res{api_error::success}; auto res{api_error::success};
directory_item dir_item{}; directory_item dir_item{};
dir_item.api_path = child_object_name; dir_item.api_path = child_object_name;
dir_item.directory = directory; dir_item.directory = directory;
if (is_encrypted) { if (is_encrypted) {
if (not utils::encryption::decrypt_file_path(cfg.encryption_token, res = decrypt_object_name(dir_item.api_path);
dir_item.api_path)) { if (res != api_error::success) {
return api_error::decryption_error; return res;
} }
} }
dir_item.api_path = utils::path::create_api_path(dir_item.api_path); dir_item.api_path = utils::path::create_api_path(dir_item.api_path);
@ -526,8 +519,8 @@ auto s3_provider::get_directory_items_impl(const std::string &api_path,
return api_error::success; return api_error::success;
} }
auto s3_provider::get_file(const std::string &api_path, api_file &file) const auto s3_provider::get_file(const std::string &api_path,
-> api_error { api_file &file) const -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -566,8 +559,8 @@ auto s3_provider::get_file(const std::string &api_path, api_file &file) const
return api_error::error; return api_error::error;
} }
auto s3_provider::get_file_list(api_file_list &list, std::string &marker) const auto s3_provider::get_file_list(api_file_list &list,
-> api_error { std::string &marker) const -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -653,9 +646,8 @@ auto s3_provider::get_file_list(api_file_list &list, std::string &marker) const
return api_error::error; return api_error::error;
} }
auto s3_provider::get_last_modified(bool directory, auto s3_provider::get_last_modified(
const std::string &api_path) const bool directory, const std::string &api_path) const -> std::uint64_t {
-> std::uint64_t {
bool is_encrypted{}; bool is_encrypted{};
std::string object_name; std::string object_name;
head_object_result result{}; head_object_result result{};
@ -665,10 +657,9 @@ auto s3_provider::get_last_modified(bool directory,
: utils::time::get_time_now(); : utils::time::get_time_now();
} }
auto s3_provider::get_object_info(bool directory, const std::string &api_path, auto s3_provider::get_object_info(
bool &is_encrypted, std::string &object_name, bool directory, const std::string &api_path, bool &is_encrypted,
head_object_result &result) const std::string &object_name, head_object_result &result) const -> api_error {
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -727,12 +718,10 @@ 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, auto s3_provider::get_object_list(
long &response_code, std::string &response_data, long &response_code,
std::optional<std::string> delimiter, std::optional<std::string> delimiter, std::optional<std::string> prefix,
std::optional<std::string> prefix, std::optional<std::string> token) const -> bool {
std::optional<std::string> token) const
-> bool {
curl::requests::http_get get{}; curl::requests::http_get get{};
get.allow_timeout = true; get.allow_timeout = true;
get.aws_service = "aws:amz:" + get_s3_config().region + ":s3"; get.aws_service = "aws:amz:" + get_s3_config().region + ":s3";
@ -760,8 +749,8 @@ 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);
} }
auto s3_provider::is_directory(const std::string &api_path, bool &exists) const auto s3_provider::is_directory(const std::string &api_path,
-> api_error { bool &exists) const -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -788,8 +777,8 @@ auto s3_provider::is_directory(const std::string &api_path, bool &exists) const
return api_error::error; return api_error::error;
} }
auto s3_provider::is_file(const std::string &api_path, bool &exists) const auto s3_provider::is_file(const std::string &api_path,
-> api_error { bool &exists) const -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {