fixes
Some checks are pending
BlockStorage/repertory/pipeline/head Build queued...

This commit is contained in:
2024-08-23 22:02:47 -05:00
parent b0a42cb488
commit a7c1bbbb1b
2 changed files with 21 additions and 28 deletions

View File

@ -27,12 +27,11 @@
#include "file_manager/i_file_manager.hpp" #include "file_manager/i_file_manager.hpp"
#include "types/repertory.hpp" #include "types/repertory.hpp"
#include "types/s3.hpp" #include "types/s3.hpp"
#include "types/startup_exception.hpp"
#include "utils/collection.hpp" #include "utils/collection.hpp"
#include "utils/encrypting_reader.hpp" #include "utils/encrypting_reader.hpp"
#include "utils/encryption.hpp" #include "utils/encryption.hpp"
#include "utils/error_utils.hpp" #include "utils/error_utils.hpp"
#include "utils/file_utils.hpp" #include "utils/file.hpp"
#include "utils/path.hpp" #include "utils/path.hpp"
#include "utils/polling.hpp" #include "utils/polling.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
@ -748,25 +747,21 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
if (res != api_error::success) { if (res != api_error::success) {
return res; return res;
} }
const auto total_size = utils::string::to_uint64(temp);
auto total_size = utils::string::to_uint64(temp); return utils::encryption::read_encrypted_range(
res = api_error::success;
if (utils::encryption::read_encrypted_range(
{offset, offset + size - 1U}, {offset, offset + size - 1U},
utils::encryption::generate_key<utils::encryption::hash_256_t>( utils::encryption::generate_key<utils::encryption::hash_256_t>(
cfg.encryption_token), cfg.encryption_token),
[&](data_buffer &ct_buffer, std::uint64_t start_offset, [&](data_buffer &ct_buffer, std::uint64_t start_offset,
std::uint64_t end_offset) -> bool { std::uint64_t end_offset) -> bool {
res = read_bytes((end_offset - start_offset + 1U), start_offset, return read_bytes((end_offset - start_offset + 1U),
ct_buffer); start_offset,
return res == api_error::success; ct_buffer) == api_error::success;
}, },
total_size, data)) { total_size, data)
return api_error::success; ? api_error::success
} : api_error::decryption_error;
return res == api_error::success ? api_error::decryption_error : res;
} }
return read_bytes(size, offset, data); return read_bytes(size, offset, data);
@ -888,18 +883,16 @@ auto s3_provider::upload_file_impl(const std::string &api_path,
const std::string &source_path, const std::string &source_path,
stop_type &stop_requested) -> api_error { stop_type &stop_requested) -> api_error {
std::uint64_t file_size{}; std::uint64_t file_size{};
auto file = utils::file::file{source_path}; if (utils::file::file{source_path}.exists()) {
if (file.exists()) { auto opt_size = utils::file::file{source_path}.size();
auto opt_size = file.size();
if (not opt_size.has_value()) { if (not opt_size.has_value()) {
return api_error::comm_error; return api_error::comm_error;
} }
file_size = opt_size.value(); file_size = opt_size.value();
} }
auto cfg = get_config().get_s3_config(); const auto cfg = get_config().get_s3_config();
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) {
@ -909,7 +902,7 @@ auto s3_provider::upload_file_impl(const std::string &api_path,
} }
} }
auto object_name = const auto object_name =
utils::path::create_api_path(is_encrypted ? key : api_path); utils::path::create_api_path(is_encrypted ? key : api_path);
curl::requests::http_put_file put_file{}; curl::requests::http_put_file put_file{};

View File

@ -109,7 +109,7 @@ auto read_encrypted_range(const http_range &range,
source_offset = 0U; source_offset = 0U;
} }
return false; return true;
} }
#endif // defined(PROJECT_ENABLE_CURL) #endif // defined(PROJECT_ENABLE_CURL)
} // namespace repertory::utils::encryption } // namespace repertory::utils::encryption