From 75d2d39e7c0a970a458b3df9da60bd42ca4a57f5 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 31 Dec 2024 12:53:08 -0600 Subject: [PATCH] refactor --- .../include/providers/s3/s3_provider.hpp | 8 +-- .../src/providers/s3/s3_provider.cpp | 66 +++++++++---------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/repertory/librepertory/include/providers/s3/s3_provider.hpp b/repertory/librepertory/include/providers/s3/s3_provider.hpp index 5c741b8b..d79da1fb 100644 --- a/repertory/librepertory/include/providers/s3/s3_provider.hpp +++ b/repertory/librepertory/include/providers/s3/s3_provider.hpp @@ -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; diff --git a/repertory/librepertory/src/providers/s3/s3_provider.cpp b/repertory/librepertory/src/providers/s3/s3_provider.cpp index 353a046d..9ffe51af 100644 --- a/repertory/librepertory/src/providers/s3/s3_provider.cpp +++ b/repertory/librepertory/src/providers/s3/s3_provider.cpp @@ -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;