This commit is contained in:
Scott E. Graves 2024-12-10 12:24:26 -06:00
parent 2fe468826d
commit 78d7949347
2 changed files with 97 additions and 52 deletions

View File

@ -23,7 +23,9 @@
#define REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_ #define REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_
namespace repertory { namespace repertory {
inline constexpr const auto max_time{std::numeric_limits<std::uint64_t>::max()}; inline constexpr const auto max_time{
std::numeric_limits<std::uint64_t>::max(),
};
inline constexpr const std::string META_ACCESSED{"accessed"}; inline constexpr const std::string META_ACCESSED{"accessed"};
inline constexpr const std::string META_ATTRIBUTES{"attributes"}; inline constexpr const std::string META_ATTRIBUTES{"attributes"};
@ -99,7 +101,22 @@ enum class api_error {
[[nodiscard]] auto api_error_to_string(const api_error &error) [[nodiscard]] auto api_error_to_string(const api_error &error)
-> const std::string &; -> const std::string &;
enum class download_type { direct, fallback, ring_buffer }; enum class database_type {
rocksdb,
sqlite,
};
[[nodiscard]] auto database_type_from_string(std::string type,
const database_type &default_type)
-> database_type;
[[nodiscard]] auto database_type_to_string(const database_type &type)
-> std::string;
enum class download_type {
direct,
fallback,
ring_buffer,
};
[[nodiscard]] auto download_type_from_string(std::string type, [[nodiscard]] auto download_type_from_string(std::string type,
const download_type &default_type) const download_type &default_type)
-> download_type; -> download_type;
@ -158,23 +175,23 @@ using open_file_data = int;
#endif #endif
struct api_file final { struct api_file final {
std::string api_path{}; std::string api_path;
std::string api_parent{}; std::string api_parent;
std::uint64_t accessed_date{}; std::uint64_t accessed_date{};
std::uint64_t changed_date{}; std::uint64_t changed_date{};
std::uint64_t creation_date{}; std::uint64_t creation_date{};
std::uint64_t file_size{}; std::uint64_t file_size{};
std::string key{}; std::string key;
std::uint64_t modified_date{}; std::uint64_t modified_date{};
std::string source_path; std::string source_path;
}; };
struct directory_item final { struct directory_item final {
std::string api_path{}; std::string api_path;
std::string api_parent{}; std::string api_parent;
bool directory{false}; bool directory{false};
std::uint64_t size{}; std::uint64_t size{};
api_meta_map meta{}; api_meta_map meta;
bool resolved{false}; bool resolved{false};
[[nodiscard]] static auto from_json(const json &item) -> directory_item { [[nodiscard]] static auto from_json(const json &item) -> directory_item {
@ -196,42 +213,42 @@ struct directory_item final {
}; };
struct encrypt_config final { struct encrypt_config final {
std::string encryption_token{}; std::string encryption_token;
std::string path{}; std::string path;
}; };
struct filesystem_item final { struct filesystem_item final {
std::string api_path{}; std::string api_path;
std::string api_parent{}; std::string api_parent;
bool directory{false}; bool directory{false};
std::uint64_t size{}; std::uint64_t size{};
std::string source_path{}; std::string source_path;
}; };
struct host_config final { struct host_config final {
std::string agent_string{}; std::string agent_string;
std::string api_password{}; std::string api_password;
std::string api_user{}; std::string api_user;
std::uint16_t api_port{}; std::uint16_t api_port;
std::string host_name_or_ip{"localhost"}; std::string host_name_or_ip{"localhost"};
std::string path{}; std::string path;
std::string protocol{"http"}; std::string protocol{"http"};
std::uint32_t timeout_ms{60000U}; std::uint32_t timeout_ms{60000U};
auto operator==(const host_config &hc) const noexcept -> bool { auto operator==(const host_config &cfg) const noexcept -> bool {
if (&hc != this) { if (&cfg != this) {
return agent_string == hc.agent_string && return agent_string == cfg.agent_string &&
api_password == hc.api_password && api_user == hc.api_user && api_password == cfg.api_password && api_user == cfg.api_user &&
api_port == hc.api_port && host_name_or_ip == hc.host_name_or_ip && api_port == cfg.api_port &&
path == hc.path && protocol == hc.protocol && host_name_or_ip == cfg.host_name_or_ip && path == cfg.path &&
timeout_ms == hc.timeout_ms; protocol == cfg.protocol && timeout_ms == cfg.timeout_ms;
} }
return true; return true;
} }
auto operator!=(const host_config &hc) const noexcept -> bool { auto operator!=(const host_config &cfg) const noexcept -> bool {
if (&hc != this) { if (&cfg != this) {
return not(hc == *this); return not(cfg == *this);
} }
return false; return false;
} }
@ -241,46 +258,48 @@ struct host_config final {
__attribute__((unused)) __attribute__((unused))
#endif #endif
static void static void
to_json(json &j, const host_config &hc) { to_json(json &data, const host_config &cfg) {
j = json{{"AgentString", hc.agent_string}, data = json{
{"ApiPassword", hc.api_password}, {"AgentString", cfg.agent_string},
{"ApiPort", hc.api_port}, {"ApiPassword", cfg.api_password},
{"ApiUser", hc.api_user}, {"ApiPort", cfg.api_port},
{"HostNameOrIp", hc.host_name_or_ip}, {"ApiUser", cfg.api_user},
{"Path", hc.path}, {"HostNameOrIp", cfg.host_name_or_ip},
{"Protocol", hc.protocol}, {"Path", cfg.path},
{"TimeoutMs", hc.timeout_ms}}; {"Protocol", cfg.protocol},
{"TimeoutMs", cfg.timeout_ms},
};
} }
#if defined(__GNUG__) #if defined(__GNUG__)
__attribute__((unused)) __attribute__((unused))
#endif #endif
static void static void
from_json(const json &j, host_config &hc) { from_json(const json &data, host_config &cfg) {
j.at("AgentString").get_to(hc.agent_string); data.at("AgentString").get_to(cfg.agent_string);
j.at("ApiPassword").get_to(hc.api_password); data.at("ApiPassword").get_to(cfg.api_password);
j.at("ApiPort").get_to(hc.api_port); data.at("ApiPort").get_to(cfg.api_port);
j.at("AuthUser").get_to(hc.api_user); data.at("AuthUser").get_to(cfg.api_user);
j.at("HostNameOrIp").get_to(hc.host_name_or_ip); data.at("HostNameOrIp").get_to(cfg.host_name_or_ip);
j.at("Path").get_to(hc.path); data.at("Path").get_to(cfg.path);
j.at("Protocol").get_to(hc.protocol); data.at("Protocol").get_to(cfg.protocol);
j.at("TimeoutMs").get_to(hc.timeout_ms); data.at("TimeoutMs").get_to(cfg.timeout_ms);
} }
struct s3_config final { struct s3_config final {
std::string access_key{}; std::string access_key;
std::string bucket{}; std::string bucket;
std::string encryption_token{}; std::string encryption_token;
std::string region{"any"}; std::string region{"any"};
std::string secret_key{}; std::string secret_key;
std::uint32_t timeout_ms{60000U}; std::uint32_t timeout_ms{60000U};
std::string url{}; std::string url;
bool use_path_style{false}; bool use_path_style{false};
bool use_region_in_url{false}; bool use_region_in_url{false};
}; };
struct sia_config final { struct sia_config final {
std::string bucket{}; std::string bucket;
}; };
using api_file_list = std::vector<api_file>; using api_file_list = std::vector<api_file>;

View File

@ -25,6 +25,32 @@
#include "utils/string.hpp" #include "utils/string.hpp"
namespace repertory { namespace repertory {
auto database_type_from_string(std::string type,
const database_type &default_type)
-> database_type {
type = utils::string::to_lower(utils::string::trim(type));
if (type == "rocksdb") {
return database_type::rocksdb;
}
if (type == "sqlite") {
return database_type::sqlite;
}
return default_type;
}
auto database_type_to_string(const database_type &type) -> std::string {
switch (type) {
case database_type::rocksdb:
return "rocksdb";
case database_type::sqlite:
return "sqlite";
default:
return "rocksdb";
}
}
auto download_type_from_string(std::string type, auto download_type_from_string(std::string type,
const download_type &default_type) const download_type &default_type)
-> download_type { -> download_type {