refactor
This commit is contained in:
parent
ccc4a30ad5
commit
75d2d39e7c
@ -54,14 +54,14 @@ private:
|
||||
const std::string &object_name) const
|
||||
-> api_error;
|
||||
|
||||
[[nodiscard]] auto create_directory_paths(const std::string &api_path,
|
||||
const std::string &key) const
|
||||
-> api_error;
|
||||
|
||||
[[nodiscard]] auto create_file_extra(const std::string &api_path,
|
||||
api_meta_map &meta)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto create_path_directories(const std::string &api_path,
|
||||
const std::string &key) const
|
||||
-> api_error;
|
||||
|
||||
[[nodiscard]] auto decrypt_object_name(std::string &object_name) const
|
||||
-> api_error;
|
||||
|
||||
|
@ -62,8 +62,8 @@ auto s3_provider::add_if_not_found(api_file &file,
|
||||
api_meta_map meta{};
|
||||
auto res = get_item_meta(file.api_path, meta);
|
||||
if (res == api_error::item_not_found) {
|
||||
res = create_path_directories(
|
||||
file.api_parent, utils::path::get_parent_api_path(object_name));
|
||||
res = create_directory_paths(file.api_parent,
|
||||
utils::path::get_parent_api_path(object_name));
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
@ -160,36 +160,8 @@ auto s3_provider::create_directory_impl(const std::string &api_path,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto s3_provider::create_file_extra(const std::string &api_path,
|
||||
api_meta_map &meta) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
const auto &cfg = get_s3_config();
|
||||
if (not cfg.encryption_token.empty()) {
|
||||
std::string encrypted_file_path;
|
||||
auto res = get_item_meta(utils::path::get_parent_api_path(api_path),
|
||||
META_KEY, encrypted_file_path);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to create file");
|
||||
return res;
|
||||
}
|
||||
|
||||
data_buffer result;
|
||||
utils::encryption::encrypt_data(
|
||||
cfg.encryption_token,
|
||||
*(utils::string::split(api_path, '/', false).end() - 1U), result);
|
||||
|
||||
meta[META_KEY] = utils::path::create_api_path(
|
||||
utils::path::combine(utils::path::create_api_path(encrypted_file_path),
|
||||
{utils::collection::to_hex_string(result)}));
|
||||
}
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto s3_provider::create_path_directories(const std::string &api_path,
|
||||
const std::string &key) const
|
||||
auto s3_provider::create_directory_paths(const std::string &api_path,
|
||||
const std::string &key) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
@ -282,6 +254,34 @@ auto s3_provider::create_path_directories(const std::string &api_path,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto s3_provider::create_file_extra(const std::string &api_path,
|
||||
api_meta_map &meta) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
const auto &cfg = get_s3_config();
|
||||
if (not cfg.encryption_token.empty()) {
|
||||
std::string encrypted_file_path;
|
||||
auto res = get_item_meta(utils::path::get_parent_api_path(api_path),
|
||||
META_KEY, encrypted_file_path);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to create file");
|
||||
return res;
|
||||
}
|
||||
|
||||
data_buffer result;
|
||||
utils::encryption::encrypt_data(
|
||||
cfg.encryption_token,
|
||||
*(utils::string::split(api_path, '/', false).end() - 1U), result);
|
||||
|
||||
meta[META_KEY] = utils::path::create_api_path(
|
||||
utils::path::combine(utils::path::create_api_path(encrypted_file_path),
|
||||
{utils::collection::to_hex_string(result)}));
|
||||
}
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto s3_provider::decrypt_object_name(std::string &object_name) const
|
||||
-> api_error {
|
||||
auto parts = utils::string::split(object_name, '/', false);
|
||||
@ -401,7 +401,7 @@ auto s3_provider::get_directory_items_impl(const std::string &api_path,
|
||||
if (directory) {
|
||||
res = get_item_meta(dir_item.api_path, dir_item.meta);
|
||||
if (res == api_error::item_not_found) {
|
||||
res = create_path_directories(dir_item.api_path, child_object_name);
|
||||
res = create_directory_paths(dir_item.api_path, child_object_name);
|
||||
}
|
||||
} else {
|
||||
std::string size_str;
|
||||
|
Loading…
x
Reference in New Issue
Block a user