refactor
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
2025-08-31 07:22:49 -05:00
parent 23f1852337
commit 91463bcac0
3 changed files with 49 additions and 36 deletions

View File

@@ -110,10 +110,6 @@ protected:
[[nodiscard]] auto get_db() const -> const i_meta_db & { return *db3_; }
[[nodiscard]] virtual auto
get_directory_item_impl(const std::string &api_path, bool directory,
directory_item &item) const -> api_error;
[[nodiscard]] virtual auto
get_directory_items_impl(const std::string &api_path,
directory_item_list &list) const -> api_error = 0;

View File

@@ -23,6 +23,7 @@
#define REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_
#include "utils/atomic.hpp"
#include "utils/encryption.hpp"
namespace repertory {
inline constexpr auto default_api_password_size{48U};
@@ -271,11 +272,13 @@ struct directory_item final {
struct encrypt_config final {
std::string encryption_token;
utils::encryption::kdf_config kdf_cfg;
std::string path;
auto operator==(const encrypt_config &cfg) const noexcept -> bool {
if (&cfg != this) {
return encryption_token == cfg.encryption_token && path == cfg.path;
return encryption_token == cfg.encryption_token &&
kdf_cfg == cfg.kdf_cfg && path == cfg.path;
}
return true;
@@ -393,15 +396,15 @@ inline constexpr auto JSON_API_PARENT{"ApiParent"};
inline constexpr auto JSON_API_PASSWORD{"ApiPassword"};
inline constexpr auto JSON_API_PATH{"ApiPath"};
inline constexpr auto JSON_API_PORT{"ApiPort"};
inline constexpr auto JSON_AUTO_START{"AutoStart"};
inline constexpr auto JSON_API_USER{"ApiUser"};
inline constexpr auto JSON_AUTO_START{"AutoStart"};
inline constexpr auto JSON_BUCKET{"Bucket"};
inline constexpr auto JSON_CLIENT_POOL_SIZE{"ClientPoolSize"};
inline constexpr auto JSON_DATABASE_TYPE{"DatabaseType"};
inline constexpr auto JSON_DIRECTORY{"Directory"};
inline constexpr auto JSON_DOWNLOAD_TIMEOUT_SECS{"DownloadTimeoutSeconds"};
inline constexpr auto JSON_ENABLE_DRIVE_EVENTS{"EnableDriveEvents"};
inline constexpr auto JSON_ENABLE_DOWNLOAD_TIMEOUT{"EnableDownloadTimeout"};
inline constexpr auto JSON_ENABLE_DRIVE_EVENTS{"EnableDriveEvents"};
inline constexpr auto JSON_ENABLE_MOUNT_MANAGER{"EnableMountManager"};
inline constexpr auto JSON_ENABLE_REMOTE_MOUNT{"Enable"};
inline constexpr auto JSON_ENCRYPTION_TOKEN{"EncryptionToken"};
@@ -412,6 +415,7 @@ inline constexpr auto JSON_EVICTION_USE_ACCESS_TIME{"EvictionUseAccessedTime"};
inline constexpr auto JSON_HIGH_FREQ_INTERVAL_SECS{"HighFreqIntervalSeconds"};
inline constexpr auto JSON_HOST_CONFIG{"HostConfig"};
inline constexpr auto JSON_HOST_NAME_OR_IP{"HostNameOrIp"};
inline constexpr auto JSON_KDF_CONFIG{"KDFConfig"};
inline constexpr auto JSON_LOW_FREQ_INTERVAL_SECS{"LowFreqIntervalSeconds"};
inline constexpr auto JSON_MAX_CACHE_SIZE_BYTES{"MaxCacheSizeBytes"};
inline constexpr auto JSON_MAX_CONNECTIONS{"MaxConnections"};
@@ -464,12 +468,32 @@ template <> struct adl_serializer<repertory::directory_item> {
template <> struct adl_serializer<repertory::encrypt_config> {
static void to_json(json &data, const repertory::encrypt_config &value) {
data[repertory::JSON_ENCRYPTION_TOKEN] = value.encryption_token;
data[repertory::JSON_KDF_CONFIG] =
repertory::utils::collection::to_hex_string(value.kdf_cfg.to_header());
data[repertory::JSON_PATH] = value.path;
}
static void from_json(const json &data, repertory::encrypt_config &value) {
REPERTORY_USES_FUNCTION_NAME();
data.at(repertory::JSON_ENCRYPTION_TOKEN).get_to(value.encryption_token);
data.at(repertory::JSON_PATH).get_to(value.path);
auto kdf_str = data.at(repertory::JSON_KDF_CONFIG).get<std::string>();
if (kdf_str.empty()) {
return;
}
repertory::data_buffer buffer;
if (not repertory::utils::collection::from_hex_string(kdf_str, buffer)) {
throw repertory::utils::error::create_exception(
function_name, {"failed to convert kdf config hex string to buffer"});
}
if (not repertory::utils::encryption::kdf_config::from_header(
buffer, value.kdf_cfg)) {
throw repertory::utils::error::create_exception(
function_name, {"failed to parse kdf header"});
}
}
};

View File

@@ -275,33 +275,6 @@ auto base_provider::get_api_path_from_source(const std::string &source_path,
return db3_->get_api_path(source_path, api_path);
}
auto base_provider::get_directory_item_impl(const std::string &api_path,
bool directory,
directory_item &item) const
-> api_error {
filesystem_item fsi{};
auto ret = get_filesystem_item(api_path, directory, fsi);
if (ret != api_error::success) {
return ret;
}
api_meta_map meta;
ret = get_item_meta(api_path, meta);
if (ret != api_error::success) {
return ret;
}
item = {
.api_path = fsi.api_path,
.api_parent = fsi.api_parent,
.directory = fsi.directory,
.size = fsi.size,
.meta = meta,
};
return ret;
}
auto base_provider::get_directory_item(const std::string &api_path,
directory_item &item) const
-> api_error {
@@ -314,10 +287,30 @@ auto base_provider::get_directory_item(const std::string &api_path,
return ret;
}
return get_directory_item_impl(api_path, directory, item);
filesystem_item fsi{};
ret = get_filesystem_item(api_path, directory, fsi);
if (ret != api_error::success) {
return ret;
}
api_meta_map meta;
ret = get_item_meta(api_path, meta);
if (ret != api_error::success) {
return ret;
}
item = {
.api_path = fsi.api_path,
.api_parent = fsi.api_parent,
.directory = fsi.directory,
.size = fsi.size,
.meta = meta,
};
return ret;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get directory items");
"failed to get directory item");
}
return api_error::error;