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

View File

@ -25,6 +25,32 @@
#include "utils/string.hpp"
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,
const download_type &default_type)
-> download_type {