diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ad41683..df8f2537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## v2.0.2-rc +### BREAKING CHANGES + +* Refactored `config.json` - will need to verify configuration settings prior to mounting + ### Issues * \#12 \[Unit Test\] Complete all providers unit tests diff --git a/repertory/librepertory/include/app_config.hpp b/repertory/librepertory/include/app_config.hpp index 359f7440..81aceb9e 100644 --- a/repertory/librepertory/include/app_config.hpp +++ b/repertory/librepertory/include/app_config.hpp @@ -71,7 +71,6 @@ private: #if defined(_WIN32) std::atomic enable_mount_manager_; #endif // defined(_WIN32) - std::atomic enable_remote_mount_; std::atomic event_level_; std::atomic eviction_delay_mins_; std::atomic eviction_uses_accessed_time_; @@ -84,9 +83,6 @@ private: std::atomic online_check_retry_secs_; std::atomic orphaned_file_retention_days_; atomic preferred_download_type_; - std::atomic remote_client_pool_size_; - std::atomic remote_api_port_; - atomic remote_encryption_token_; std::atomic retry_read_count_; std::atomic ring_buffer_file_size_; std::atomic task_wait_ms_; @@ -99,47 +95,25 @@ private: std::string log_directory_; mutable std::recursive_mutex read_write_mutex_; atomic remote_config_; + atomic remote_mount_; atomic s3_config_; atomic sia_config_; + std::unordered_map> + value_get_lookup_; + std::unordered_map> + value_set_lookup_; std::uint64_t version_{REPERTORY_CONFIG_VERSION}; private: template auto get_value(const json &data, const std::string &name, dest &dst, - bool &success) -> bool { - REPERTORY_USES_FUNCTION_NAME(); - - auto ret{false}; - try { - if (data.find(name) != data.end()) { - data.at(name).get_to(dst); - ret = true; - } else { - success = false; - } - } catch (const std::exception &ex) { - utils::error::raise_error(function_name, ex, "exception occurred"); - success = false; - ret = false; - } - - return ret; - } + bool &success) -> bool; [[nodiscard]] auto load() -> bool; template - auto set_value(dest &dst, const source &src) -> bool { - auto ret{false}; - if (dst != src) { - dst = src; - config_changed_ = true; - save(); - ret = true; - } - - return ret; - } + auto set_value(dest &dst, const source &src) -> bool; public: [[nodiscard]] auto get_api_auth() const -> std::string { return api_auth_; } @@ -189,10 +163,6 @@ public: } #endif // defined(_WIN32) - [[nodiscard]] auto get_enable_remote_mount() const -> bool { - return enable_remote_mount_; - } - [[nodiscard]] auto get_event_level() const -> event_level { return event_level_; } @@ -254,21 +224,12 @@ public: return prov_; } - [[nodiscard]] auto get_remote_client_pool_size() const -> std::uint8_t { - return std::max(static_cast(5U), - remote_client_pool_size_.load()); - } - - [[nodiscard]] auto get_remote_api_port() const -> std::uint16_t { - return remote_api_port_; - } - [[nodiscard]] auto get_remote_config() const -> remote::remote_config { return remote_config_; } - [[nodiscard]] auto get_remote_encryption_token() const -> std::string { - return remote_encryption_token_; + [[nodiscard]] auto get_remote_mount() const -> remote::remote_mount { + return remote_mount_; } [[nodiscard]] auto get_retry_read_count() const -> std::uint16_t { @@ -337,8 +298,6 @@ public: } #endif // defined(_WIN32) - void set_enable_remote_mount(bool enable_remote_mount); - void set_event_level(const event_level &level) { if (set_value(event_level_, level)) { event_system::instance().raise( @@ -394,23 +353,13 @@ public: set_value(preferred_download_type_, type); } - void set_remote_client_pool_size(std::uint8_t remote_client_pool_size) { - set_value(remote_client_pool_size_, remote_client_pool_size); - } - void set_ring_buffer_file_size(std::uint16_t ring_buffer_file_size) { set_value(ring_buffer_file_size_, ring_buffer_file_size); } - void set_remote_api_port(std::uint16_t remote_api_port) { - set_value(remote_api_port_, remote_api_port); - } - void set_remote_config(remote::remote_config cfg); - void set_remote_encryption_token(const std::string &remote_encryption_token) { - set_value(remote_encryption_token_, remote_encryption_token); - } + void set_remote_mount(remote::remote_mount cfg); void set_retry_read_count(std::uint16_t retry_read_count) { set_value(retry_read_count_, retry_read_count); diff --git a/repertory/librepertory/include/types/remote.hpp b/repertory/librepertory/include/types/remote.hpp index 7a8b6d22..6b6ddc52 100644 --- a/repertory/librepertory/include/types/remote.hpp +++ b/repertory/librepertory/include/types/remote.hpp @@ -64,6 +64,31 @@ struct remote_config final { } }; +struct remote_mount final { + std::uint16_t api_port{}; + std::uint8_t client_pool_size{20U}; + bool enable{false}; + std::string encryption_token; + + auto operator==(const remote_mount &cfg) const noexcept -> bool { + if (&cfg == this) { + return true; + } + + return api_port == cfg.api_port && + client_pool_size == cfg.client_pool_size && enable == cfg.enable && + encryption_token == cfg.encryption_token; + } + + auto operator!=(const remote_mount &cfg) const noexcept -> bool { + if (&cfg == this) { + return false; + } + + return not(cfg == *this); + } +}; + using block_count = std::uint64_t; using block_size = std::uint32_t; using file_handle = std::uint64_t; @@ -214,6 +239,24 @@ template <> struct adl_serializer { data.at(repertory::JSON_SEND_TIMEOUT_MS).get_to(value.send_timeout_ms); } }; + +template <> struct adl_serializer { + static void to_json(json &data, + const repertory::remote::remote_mount &value) { + data[repertory::JSON_API_PORT] = value.api_port; + data[repertory::JSON_CLIENT_POOL_SIZE] = value.client_pool_size; + data[repertory::JSON_ENABLE_REMOTE_MOUNT] = value.enable; + data[repertory::JSON_ENCRYPTION_TOKEN] = value.encryption_token; + } + + static void from_json(const json &data, + repertory::remote::remote_mount &value) { + data.at(repertory::JSON_API_PORT).get_to(value.api_port); + data.at(repertory::JSON_CLIENT_POOL_SIZE).get_to(value.client_pool_size); + data.at(repertory::JSON_ENABLE_REMOTE_MOUNT).get_to(value.enable); + data.at(repertory::JSON_ENCRYPTION_TOKEN).get_to(value.encryption_token); + } +}; NLOHMANN_JSON_NAMESPACE_END #endif // REPERTORY_INCLUDE_TYPES_REMOTE_HPP_ diff --git a/repertory/librepertory/include/types/repertory.hpp b/repertory/librepertory/include/types/repertory.hpp index 3c934a4d..59a26372 100644 --- a/repertory/librepertory/include/types/repertory.hpp +++ b/repertory/librepertory/include/types/repertory.hpp @@ -407,19 +407,51 @@ inline constexpr const auto JSON_API_PASSWORD{"ApiPassword"}; inline constexpr const auto JSON_API_PATH{"ApiPath"}; inline constexpr const auto JSON_API_PORT{"ApiPort"}; inline constexpr const auto JSON_API_USER{"ApiUser"}; +inline constexpr const auto JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS{ + "ChunkDownloaderTimeoutSeconds"}; inline constexpr const auto JSON_BUCKET{"Bucket"}; +inline constexpr const auto JSON_CLIENT_POOL_SIZE{"ClientPoolSize"}; +inline constexpr const auto JSON_DATABASE_TYPE{"DatabaseType"}; inline constexpr const auto JSON_DIRECTORY{"Directory"}; +inline constexpr const auto JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT{ + "EnableChunkDownloaderTimeout"}; +inline constexpr const auto JSON_ENABLE_COMM_DURATION_EVENTS{ + "EnableCommDurationEvents"}; +inline constexpr const auto JSON_ENABLE_DRIVE_EVENTS{"EnableDriveEvents"}; +inline constexpr const auto JSON_ENABLE_MOUNT_MANAGER{"EnableMountManager"}; +inline constexpr const auto JSON_ENABLE_REMOTE_MOUNT{"Enable"}; inline constexpr const auto JSON_ENCRYPTION_TOKEN{"EncryptionToken"}; inline constexpr const auto JSON_ENCRYPT_CONFIG{"EncryptConfig"}; +inline constexpr const auto JSON_EVENT_LEVEL{"EventLevel"}; +inline constexpr const auto JSON_EVICTION_DELAY_MINS{"EvictionDelayMinutes"}; +inline constexpr const auto JSON_EVICTION_USE_ACCESS_TIME{ + "EvictionUseAccessedTime"}; +inline constexpr const auto JSON_HIGH_FREQ_INTERVAL_SECS{ + "HighFreqIntervalSeconds"}; inline constexpr const auto JSON_HOST_CONFIG{"HostConfig"}; inline constexpr const auto JSON_HOST_NAME_OR_IP{"HostNameOrIp"}; +inline constexpr const auto JSON_LOW_FREQ_INTERVAL_SECS{ + "LowFreqIntervalSeconds"}; +inline constexpr const auto JSON_MAX_CACHE_SIZE_BYTES{"MaxCacheSizeBytes"}; inline constexpr const auto JSON_MAX_CONNECTIONS{"MaxConnections"}; +inline constexpr const auto JSON_MAX_UPLOAD_COUNT{"MaxUploadCount"}; +inline constexpr const auto JSON_MED_FREQ_INTERVAL_SECS{ + "MedFreqIntervalSeconds"}; inline constexpr const auto JSON_META{"Meta"}; +inline constexpr const auto JSON_ONLINE_CHECK_RETRY_SECS{ + "OnlineCheckRetrySeconds"}; +inline constexpr const auto JSON_ORPHANED_FILE_RETENTION_DAYS{ + "OrphanedFileRetentionDays"}; inline constexpr const auto JSON_PATH{"Path"}; +inline constexpr const auto JSON_PREFERRED_DOWNLOAD_TYPE{ + "PreferredDownloadType"}; inline constexpr const auto JSON_PROTOCOL{"Protocol"}; inline constexpr const auto JSON_RECV_TIMEOUT_MS{"ReceiveTimeoutMs"}; inline constexpr const auto JSON_REGION{"Region"}; inline constexpr const auto JSON_REMOTE_CONFIG{"RemoteConfig"}; +inline constexpr const auto JSON_REMOTE_MOUNT{"RemoteMount"}; +inline constexpr const auto JSON_RETRY_READ_COUNT{"RetryReadCount"}; +inline constexpr const auto JSON_RING_BUFFER_FILE_SIZE{"RingBufferFileSize"}; inline constexpr const auto JSON_S3_CONFIG{"S3Config"}; inline constexpr const auto JSON_SECRET_KEY{"SecretKey"}; inline constexpr const auto JSON_SEND_TIMEOUT_MS{"SendTimeoutMs"}; @@ -430,6 +462,7 @@ inline constexpr const auto JSON_TIMEOUT_MS{"TimeoutMs"}; inline constexpr const auto JSON_URL{"URL"}; inline constexpr const auto JSON_USE_PATH_STYLE{"UsePathStyle"}; inline constexpr const auto JSON_USE_REGION_IN_URL{"UseRegionInURL"}; +inline constexpr const auto JSON_VERSION{"Version"}; } // namespace repertory NLOHMANN_JSON_NAMESPACE_BEGIN diff --git a/repertory/librepertory/src/app_config.cpp b/repertory/librepertory/src/app_config.cpp index dd3699db..61e40657 100644 --- a/repertory/librepertory/src/app_config.cpp +++ b/repertory/librepertory/src/app_config.cpp @@ -71,7 +71,6 @@ app_config::app_config(const provider_type &prov, #if defined(_WIN32) enable_mount_manager_(false), #endif // defined(_WIN32) - enable_remote_mount_(false), event_level_(event_level::info), eviction_delay_mins_(default_eviction_delay_mins), eviction_uses_accessed_time_(false), @@ -84,9 +83,6 @@ app_config::app_config(const provider_type &prov, online_check_retry_secs_(default_online_check_retry_secs), orphaned_file_retention_days_(default_orphaned_file_retention_days), preferred_download_type_(download_type::fallback), - remote_client_pool_size_(default_remote_client_pool_size), - remote_api_port_(default_remote_api_port(prov)), - remote_encryption_token_(default_remote_encryption_token), retry_read_count_(default_retry_read_count), ring_buffer_file_size_(default_ring_buffer_file_size), task_wait_ms_(default_task_wait_ms) { @@ -96,10 +92,10 @@ app_config::app_config(const provider_type &prov, cache_directory_ = utils::path::combine(data_directory_, {"cache"}); log_directory_ = utils::path::combine(data_directory_, {"logs"}); - auto cfg = get_host_config(); - cfg.agent_string = default_agent_name(prov_); - cfg.api_port = default_api_port(prov_); - set_host_config(cfg); + auto host_cfg = get_host_config(); + host_cfg.agent_string = default_agent_name(prov_); + host_cfg.api_port = default_api_port(prov_); + set_host_config(host_cfg); if (not utils::file::directory(data_directory_).create_directory()) { throw startup_exception("unable to create: " + data_directory_); @@ -116,6 +112,546 @@ app_config::app_config(const provider_type &prov, if (not load()) { save(); } + + value_get_lookup_ = { + {JSON_API_AUTH, [this]() { return get_api_auth(); }}, + {JSON_API_PORT, [this]() { return std::to_string(get_api_port()); }}, + {JSON_API_USER, [this]() { return get_api_user(); }}, + {JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS, + [this]() { + return std::to_string(get_chunk_downloader_timeout_secs()); + }}, + {JSON_DATABASE_TYPE, + [this]() { return database_type_to_string(get_database_type()); }}, + {JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, + [this]() { + return utils::string::from_bool(get_enable_chunk_download_timeout()); + }}, + {JSON_ENABLE_COMM_DURATION_EVENTS, + [this]() { + return utils::string::from_bool(get_enable_comm_duration_events()); + }}, + {JSON_ENABLE_DRIVE_EVENTS, + [this]() { + return utils::string::from_bool(get_enable_drive_events()); + }}, +#if defined(_WIN32) + {JSON_ENABLE_MOUNT_MANAGER, + [this]() { + return utils::string::from_bool(get_enable_mount_manager()); + }}, +#endif // defined(_WIN32) + {fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_ENCRYPTION_TOKEN), + [this]() { return get_encrypt_config().encryption_token; }}, + {fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_PATH), + [this]() { return utils::path::absolute(get_encrypt_config().path); }}, + {JSON_EVENT_LEVEL, + [this]() { return event_level_to_string(get_event_level()); }}, + {JSON_EVICTION_DELAY_MINS, + [this]() { return std::to_string(get_eviction_delay_mins()); }}, + {JSON_EVICTION_USE_ACCESS_TIME, + [this]() { + return utils::string::from_bool(get_eviction_uses_accessed_time()); + }}, + {JSON_HIGH_FREQ_INTERVAL_SECS, + [this]() { return std::to_string(get_high_frequency_interval_secs()); }}, + {fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_AGENT_STRING), + [this]() { return get_host_config().agent_string; }}, + {fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PASSWORD), + [this]() { return get_host_config().api_password; }}, + {fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PORT), + [this]() { return std::to_string(get_host_config().api_port); }}, + {fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_HOST_NAME_OR_IP), + [this]() { return get_host_config().host_name_or_ip; }}, + {fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_TIMEOUT_MS), + [this]() { return std::to_string(get_host_config().timeout_ms); }}, + {JSON_LOW_FREQ_INTERVAL_SECS, + [this]() { return std::to_string(get_low_frequency_interval_secs()); }}, + {JSON_MAX_CACHE_SIZE_BYTES, + [this]() { return std::to_string(get_max_cache_size_bytes()); }}, + {JSON_MAX_UPLOAD_COUNT, + [this]() { return std::to_string(get_max_upload_count()); }}, + {JSON_MED_FREQ_INTERVAL_SECS, + [this]() { return std::to_string(get_med_frequency_interval_secs()); }}, + {JSON_ONLINE_CHECK_RETRY_SECS, + [this]() { return std::to_string(get_online_check_retry_secs()); }}, + {JSON_ORPHANED_FILE_RETENTION_DAYS, + [this]() { return std::to_string(get_orphaned_file_retention_days()); }}, + {JSON_PREFERRED_DOWNLOAD_TYPE, + [this]() { + return download_type_to_string(get_preferred_download_type()); + }}, + {fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_API_PORT), + [this]() { return std::to_string(get_remote_config().api_port); }}, + {fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_ENCRYPTION_TOKEN), + [this]() { return get_remote_config().encryption_token; }}, + {fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_HOST_NAME_OR_IP), + [this]() { return get_remote_config().host_name_or_ip; }}, + {fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_MAX_CONNECTIONS), + [this]() { + return std::to_string(get_remote_config().max_connections); + }}, + {fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_RECV_TIMEOUT_MS), + [this]() { + return std::to_string(get_remote_config().recv_timeout_ms); + }}, + {fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_SEND_TIMEOUT_MS), + [this]() { + return std::to_string(get_remote_config().send_timeout_ms); + }}, + {fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_API_PORT), + [this]() { return std::to_string(get_remote_mount().api_port); }}, + {fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_CLIENT_POOL_SIZE), + [this]() { + return std::to_string(get_remote_mount().client_pool_size); + }}, + {fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_ENABLE_REMOTE_MOUNT), + [this]() { + return utils::string::from_bool(get_remote_mount().enable); + }}, + {fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_ENCRYPTION_TOKEN), + [this]() { return get_remote_mount().encryption_token; }}, + {JSON_RETRY_READ_COUNT, + [this]() { return std::to_string(get_retry_read_count()); }}, + {JSON_RING_BUFFER_FILE_SIZE, + [this]() { return std::to_string(get_ring_buffer_file_size()); }}, + {fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ACCESS_KEY), + [this]() { return get_s3_config().access_key; }}, + {fmt::format("{}.{}", JSON_S3_CONFIG, JSON_BUCKET), + [this]() { return get_s3_config().bucket; }}, + {fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ENCRYPTION_TOKEN), + [this]() { return get_s3_config().encryption_token; }}, + {fmt::format("{}.{}", JSON_S3_CONFIG, JSON_REGION), + [this]() { return get_s3_config().region; }}, + {fmt::format("{}.{}", JSON_S3_CONFIG, JSON_SECRET_KEY), + [this]() { return get_s3_config().secret_key; }}, + {fmt::format("{}.{}", JSON_S3_CONFIG, JSON_TIMEOUT_MS), + [this]() { return std::to_string(get_s3_config().timeout_ms); }}, + {fmt::format("{}.{}", JSON_S3_CONFIG, JSON_URL), + [this]() { return get_s3_config().url; }}, + {fmt::format("{}.{}", JSON_S3_CONFIG, JSON_USE_PATH_STYLE), + [this]() { + return utils::string::from_bool(get_s3_config().use_path_style); + }}, + {fmt::format("{}.{}", JSON_S3_CONFIG, JSON_USE_REGION_IN_URL), + [this]() { + return utils::string::from_bool(get_s3_config().use_region_in_url); + }}, + {fmt::format("{}.{}", JSON_SIA_CONFIG, JSON_BUCKET), + [this]() { return get_sia_config().bucket; }}, + {JSON_TASK_WAIT_MS, + [this]() { return std::to_string(get_task_wait_ms()); }}, + }; + + value_set_lookup_ = { + { + JSON_API_PATH, + [this](const std::string &value) { + set_api_auth(value); + return get_api_auth(); + }, + }, + { + JSON_API_PORT, + [this](const std::string &value) { + set_api_port(utils::string::to_uint16(value)); + return std::to_string(get_api_port()); + }, + }, + { + JSON_API_USER, + [this](const std::string &value) { + set_api_user(value); + return get_api_user(); + }, + }, + { + JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS, + [this](const std::string &value) { + set_chunk_downloader_timeout_secs(utils::string::to_uint8(value)); + return std::to_string(get_chunk_downloader_timeout_secs()); + }, + }, + { + JSON_DATABASE_TYPE, + [this](const std::string &value) { + set_database_type(database_type_from_string(value)); + return database_type_to_string(db_type_); + }, + }, + { + JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, + [this](const std::string &value) { + set_enable_chunk_downloader_timeout(utils::string::to_bool(value)); + return utils::string::from_bool( + get_enable_chunk_download_timeout()); + }, + }, + { + JSON_ENABLE_COMM_DURATION_EVENTS, + [this](const std::string &value) { + set_enable_comm_duration_events(utils::string::to_bool(value)); + return utils::string::from_bool(get_enable_comm_duration_events()); + }, + }, + { + JSON_ENABLE_DRIVE_EVENTS, + [this](const std::string &value) { + set_enable_drive_events(utils::string::to_bool(value)); + return utils::string::from_bool(get_enable_drive_events()); + }, + }, +#if defined(_WIN32) + { + JSON_ENABLE_MOUNT_MANAGER, + [this](const std::string &value) { + set_enable_mount_manager(utils::string::to_bool(value)); + return utils::string::from_bool(get_enable_mount_manager()); + }, + }, +#endif // defined(_WIN32) + { + fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_ENCRYPTION_TOKEN), + [this](const std::string &value) { + auto cfg = get_encrypt_config(); + cfg.encryption_token = value; + set_encrypt_config(cfg); + return get_encrypt_config().encryption_token; + }, + }, + { + fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_PATH), + [this](const std::string &value) { + auto cfg = get_encrypt_config(); + cfg.path = value; + set_encrypt_config(cfg); + return get_encrypt_config().path; + }, + }, + { + JSON_EVENT_LEVEL, + [this](const std::string &value) { + set_event_level(event_level_from_string(value)); + return event_level_to_string(get_event_level()); + }, + }, + { + JSON_EVICTION_DELAY_MINS, + [this](const std::string &value) { + set_eviction_delay_mins(utils::string::to_uint32(value)); + return std::to_string(get_eviction_delay_mins()); + }, + }, + { + JSON_EVICTION_USE_ACCESS_TIME, + [this](const std::string &value) { + set_eviction_uses_accessed_time(utils::string::to_bool(value)); + return utils::string::from_bool(get_eviction_uses_accessed_time()); + }, + }, + { + JSON_HIGH_FREQ_INTERVAL_SECS, + [this](const std::string &value) { + set_high_frequency_interval_secs(utils::string::to_uint8(value)); + return std::to_string(get_high_frequency_interval_secs()); + }, + }, + { + fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_AGENT_STRING), + [this](const std::string &value) { + auto cfg = get_host_config(); + cfg.agent_string = value; + set_host_config(cfg); + return get_host_config().agent_string; + }, + }, + { + fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PASSWORD), + [this](const std::string &value) { + auto cfg = get_host_config(); + cfg.api_password = value; + set_host_config(cfg); + return get_host_config().api_password; + }, + }, + { + fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PORT), + [this](const std::string &value) { + auto cfg = get_host_config(); + cfg.api_port = utils::string::to_uint16(value); + set_host_config(cfg); + return std::to_string(get_host_config().api_port); + }, + }, + { + fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_HOST_NAME_OR_IP), + [this](const std::string &value) { + auto cfg = get_host_config(); + cfg.host_name_or_ip = value; + set_host_config(cfg); + return get_host_config().host_name_or_ip; + }, + }, + { + fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_TIMEOUT_MS), + [this](const std::string &value) { + auto cfg = get_host_config(); + cfg.timeout_ms = utils::string::to_uint32(value); + set_host_config(cfg); + return std::to_string(get_host_config().timeout_ms); + }, + }, + { + JSON_LOW_FREQ_INTERVAL_SECS, + [this](const std::string &value) { + set_low_frequency_interval_secs(utils::string::to_uint8(value)); + return std::to_string(get_low_frequency_interval_secs()); + }, + }, + { + JSON_MED_FREQ_INTERVAL_SECS, + [this](const std::string &value) { + set_med_frequency_interval_secs(utils::string::to_uint8(value)); + return std::to_string(get_med_frequency_interval_secs()); + }, + }, + { + JSON_MAX_CACHE_SIZE_BYTES, + [this](const std::string &value) { + set_max_cache_size_bytes(utils::string::to_uint64(value)); + return std::to_string(get_max_cache_size_bytes()); + }, + }, + { + JSON_MAX_UPLOAD_COUNT, + [this](const std::string &value) { + set_max_upload_count(utils::string::to_uint8(value)); + return std::to_string(get_max_upload_count()); + }, + }, + { + JSON_ONLINE_CHECK_RETRY_SECS, + [this](const std::string &value) { + set_online_check_retry_secs(utils::string::to_uint16(value)); + return std::to_string(get_online_check_retry_secs()); + }, + }, + { + JSON_ORPHANED_FILE_RETENTION_DAYS, + [this](const std::string &value) { + set_orphaned_file_retention_days(utils::string::to_uint16(value)); + return std::to_string(get_orphaned_file_retention_days()); + }, + }, + { + JSON_PREFERRED_DOWNLOAD_TYPE, + [this](const std::string &value) { + set_preferred_download_type(download_type_from_string(value)); + return download_type_to_string(get_preferred_download_type()); + }, + }, + { + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_API_PORT), + [this](const std::string &value) { + auto cfg = get_remote_config(); + cfg.api_port = utils::string::to_uint16(value); + set_remote_config(cfg); + return std::to_string(get_remote_config().api_port); + }, + }, + { + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_ENCRYPTION_TOKEN), + [this](const std::string &value) { + auto cfg = get_remote_config(); + cfg.encryption_token = value; + set_remote_config(cfg); + return get_remote_config().encryption_token; + }, + }, + { + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_HOST_NAME_OR_IP), + [this](const std::string &value) { + auto cfg = get_remote_config(); + cfg.host_name_or_ip = value; + set_remote_config(cfg); + return get_remote_config().host_name_or_ip; + }, + }, + { + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_MAX_CONNECTIONS), + [this](const std::string &value) { + auto cfg = get_remote_config(); + cfg.max_connections = utils::string::to_uint8(value); + set_remote_config(cfg); + return std::to_string(get_remote_config().max_connections); + }, + }, + { + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_RECV_TIMEOUT_MS), + [this](const std::string &value) { + auto cfg = get_remote_config(); + cfg.recv_timeout_ms = utils::string::to_uint32(value); + set_remote_config(cfg); + return std::to_string(get_remote_config().recv_timeout_ms); + }, + }, + { + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_SEND_TIMEOUT_MS), + [this](const std::string &value) { + auto cfg = get_remote_config(); + cfg.send_timeout_ms = utils::string::to_uint32(value); + set_remote_config(cfg); + return std::to_string(get_remote_config().send_timeout_ms); + }, + }, + { + fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_API_PORT), + [this](const std::string &value) { + auto cfg = get_remote_mount(); + cfg.api_port = utils::string::to_uint16(value); + set_remote_mount(cfg); + return std::to_string(get_remote_mount().api_port); + }, + }, + { + fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_CLIENT_POOL_SIZE), + [this](const std::string &value) { + auto cfg = get_remote_mount(); + cfg.client_pool_size = utils::string::to_uint8(value); + set_remote_mount(cfg); + return std::to_string(get_remote_mount().client_pool_size); + }, + }, + { + fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_ENABLE_REMOTE_MOUNT), + [this](const std::string &value) { + auto cfg = get_remote_mount(); + cfg.enable = utils::string::to_bool(value); + set_remote_mount(cfg); + return utils::string::from_bool(get_remote_mount().enable); + }, + }, + { + fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_ENCRYPTION_TOKEN), + [this](const std::string &value) { + auto cfg = get_remote_mount(); + cfg.encryption_token = value; + set_remote_mount(cfg); + return get_remote_mount().encryption_token; + }, + }, + { + JSON_RETRY_READ_COUNT, + [this](const std::string &value) { + set_retry_read_count(utils::string::to_uint16(value)); + return std::to_string(get_retry_read_count()); + }, + }, + { + JSON_RING_BUFFER_FILE_SIZE, + [this](const std::string &value) { + set_ring_buffer_file_size(utils::string::to_uint16(value)); + return std::to_string(get_ring_buffer_file_size()); + }, + }, + { + fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ACCESS_KEY), + [this](const std::string &value) { + auto cfg = get_s3_config(); + cfg.access_key = value; + set_s3_config(cfg); + return get_s3_config().access_key; + }, + }, + { + fmt::format("{}.{}", JSON_S3_CONFIG, JSON_BUCKET), + [this](const std::string &value) { + auto cfg = get_s3_config(); + cfg.bucket = value; + set_s3_config(cfg); + return get_s3_config().bucket; + }, + }, + { + fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ENCRYPTION_TOKEN), + [this](const std::string &value) { + auto cfg = get_s3_config(); + cfg.encryption_token = value; + set_s3_config(cfg); + return get_s3_config().encryption_token; + }, + }, + { + fmt::format("{}.{}", JSON_S3_CONFIG, JSON_REGION), + [this](const std::string &value) { + auto cfg = get_s3_config(); + cfg.region = value; + set_s3_config(cfg); + return get_s3_config().region; + }, + }, + { + fmt::format("{}.{}", JSON_S3_CONFIG, JSON_SECRET_KEY), + [this](const std::string &value) { + auto cfg = get_s3_config(); + cfg.secret_key = value; + set_s3_config(cfg); + return get_s3_config().secret_key; + }, + }, + { + fmt::format("{}.{}", JSON_S3_CONFIG, JSON_TIMEOUT_MS), + [this](const std::string &value) { + auto cfg = get_s3_config(); + cfg.timeout_ms = utils::string::to_uint32(value); + set_s3_config(cfg); + return std::to_string(get_s3_config().timeout_ms); + }, + }, + { + fmt::format("{}.{}", JSON_S3_CONFIG, JSON_URL), + [this](const std::string &value) { + auto cfg = get_s3_config(); + cfg.url = value; + set_s3_config(cfg); + return get_s3_config().url; + }, + }, + { + fmt::format("{}.{}", JSON_S3_CONFIG, JSON_USE_PATH_STYLE), + [this](const std::string &value) { + auto cfg = get_s3_config(); + cfg.use_path_style = utils::string::to_bool(value); + set_s3_config(cfg); + return utils::string::from_bool(get_s3_config().use_path_style); + }, + }, + { + fmt::format("{}.{}", JSON_S3_CONFIG, JSON_USE_REGION_IN_URL), + [this](const std::string &value) { + auto cfg = get_s3_config(); + cfg.use_region_in_url = utils::string::to_bool(value); + set_s3_config(cfg); + return utils::string::from_bool(get_s3_config().use_region_in_url); + }, + }, + { + fmt::format("{}.{}", JSON_SIA_CONFIG, JSON_BUCKET), + [this](const std::string &value) { + auto cfg = get_sia_config(); + cfg.bucket = value; + set_sia_config(cfg); + return get_sia_config().bucket; + }, + }, + { + JSON_TASK_WAIT_MS, + [this](const std::string &value) { + set_task_wait_ms(utils::string::to_uint16(value)); + return std::to_string(get_task_wait_ms()); + }, + }, + }; } auto app_config::default_agent_name(const provider_type &prov) -> std::string { @@ -206,58 +742,51 @@ auto app_config::get_json() const -> json { {JSON_API_AUTH, api_auth_}, {JSON_API_PORT, api_port_}, {JSON_API_USER, api_user_}, - {"ChunkDownloaderTimeoutSeconds", download_timeout_secs_}, - {"DatabaseType", db_type_}, - {"EnableChunkDownloaderTimeout", enable_chunk_downloader_timeout_}, - {"EnableCommDurationEvents", enable_comm_duration_events_}, - {"EnableDriveEvents", enable_drive_events_}, + {JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS, download_timeout_secs_}, + {JSON_DATABASE_TYPE, db_type_}, + {JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, enable_chunk_downloader_timeout_}, + {JSON_ENABLE_COMM_DURATION_EVENTS, enable_comm_duration_events_}, + {JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_}, #if defined(_WIN32) - {"EnableMountManager", enable_mount_manager_}, + {JSON_ENABLE_MOUNT_MANAGER, enable_mount_manager_}, #endif // defined(_WIN32) {JSON_ENCRYPT_CONFIG, encrypt_config_}, - {"EventLevel", event_level_}, - {"EvictionDelayMinutes", eviction_delay_mins_}, - {"EvictionUsesAccessedTime", eviction_uses_accessed_time_}, - {"HighFreqIntervalSeconds", high_freq_interval_secs_}, + {JSON_EVENT_LEVEL, event_level_}, + {JSON_EVICTION_DELAY_MINS, eviction_delay_mins_}, + {JSON_EVICTION_USE_ACCESS_TIME, eviction_uses_accessed_time_}, + {JSON_HIGH_FREQ_INTERVAL_SECS, high_freq_interval_secs_}, {JSON_HOST_CONFIG, host_config_}, - {"LowFreqIntervalSeconds", low_freq_interval_secs_}, - {"MaxCacheSizeBytes", max_cache_size_bytes_}, - {"MaxUploadCount", max_upload_count_}, - {"MedFreqIntervalSeconds", med_freq_interval_secs_}, - {"OnlineCheckRetrySeconds", online_check_retry_secs_}, - {"OrphanedFileRetentionDays", orphaned_file_retention_days_}, - {"PreferredDownloadType", preferred_download_type_}, + {JSON_LOW_FREQ_INTERVAL_SECS, low_freq_interval_secs_}, + {JSON_MAX_CACHE_SIZE_BYTES, max_cache_size_bytes_}, + {JSON_MAX_UPLOAD_COUNT, max_upload_count_}, + {JSON_MED_FREQ_INTERVAL_SECS, med_freq_interval_secs_}, + {JSON_ONLINE_CHECK_RETRY_SECS, online_check_retry_secs_}, + {JSON_ORPHANED_FILE_RETENTION_DAYS, orphaned_file_retention_days_}, + {JSON_PREFERRED_DOWNLOAD_TYPE, preferred_download_type_}, {JSON_REMOTE_CONFIG, remote_config_}, - { - "RemoteMount", - { - {JSON_API_PORT, remote_api_port_}, - {"ClientPoolSize", remote_client_pool_size_}, - {"Enable", enable_remote_mount_}, - {JSON_ENCRYPTION_TOKEN, remote_encryption_token_}, - }, - }, - {"RetryReadCount", retry_read_count_}, - {"RingBufferFileSize", ring_buffer_file_size_}, + {JSON_REMOTE_MOUNT, remote_mount_}, + {JSON_RETRY_READ_COUNT, retry_read_count_}, + {JSON_RING_BUFFER_FILE_SIZE, ring_buffer_file_size_}, {JSON_S3_CONFIG, s3_config_}, {JSON_SIA_CONFIG, sia_config_}, - {"TaskWaitMillis", task_wait_ms_}, - {"Version", version_}}; + {JSON_TASK_WAIT_MS, task_wait_ms_}, + {JSON_VERSION, version_}, + }; if (prov_ == provider_type::encrypt) { - ret.erase("ChunkDownloaderTimeoutSeconds"); - ret.erase("EnableChunkDownloaderTimeout"); - ret.erase("EvictionDelayMinutes"); - ret.erase("EvictionUsesAccessedTime"); + ret.erase(JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS); + ret.erase(JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT); + ret.erase(JSON_EVICTION_DELAY_MINS); + ret.erase(JSON_EVICTION_USE_ACCESS_TIME); ret.erase(JSON_HOST_CONFIG); - ret.erase("MaxCacheSizeBytes"); - ret.erase("MaxUploadCount"); - ret.erase("OnlineCheckRetrySeconds"); - ret.erase("OrphanedFileRetentionDays"); - ret.erase("PreferredDownloadType"); + ret.erase(JSON_MAX_CACHE_SIZE_BYTES); + ret.erase(JSON_MAX_UPLOAD_COUNT); + ret.erase(JSON_ONLINE_CHECK_RETRY_SECS); + ret.erase(JSON_ORPHANED_FILE_RETENTION_DAYS); + ret.erase(JSON_PREFERRED_DOWNLOAD_TYPE); ret.erase(JSON_REMOTE_CONFIG); - ret.erase("RetryReadCount"); - ret.erase("RingBufferFileSize"); + ret.erase(JSON_RETRY_READ_COUNT); + ret.erase(JSON_RING_BUFFER_FILE_SIZE); ret.erase(JSON_S3_CONFIG); ret.erase(JSON_SIA_CONFIG); } else if (prov_ == provider_type::s3) { @@ -270,24 +799,24 @@ auto app_config::get_json() const -> json { ret.erase(JSON_REMOTE_CONFIG); ret.erase(JSON_S3_CONFIG); } else if (prov_ == provider_type::remote) { - ret.erase("ChunkDownloaderTimeoutSeconds"); - ret.erase("DatabaseType"); - ret.erase("EnableChunkDownloaderTimeout"); + ret.erase(JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS); + ret.erase(JSON_DATABASE_TYPE); + ret.erase(JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT); ret.erase(JSON_ENCRYPT_CONFIG); - ret.erase("EvictionDelayMinutes"); - ret.erase("EvictionUsesAccessedTime"); - ret.erase("HighFreqIntervalSeconds"); + ret.erase(JSON_EVICTION_DELAY_MINS); + ret.erase(JSON_EVICTION_USE_ACCESS_TIME); + ret.erase(JSON_HIGH_FREQ_INTERVAL_SECS); ret.erase(JSON_HOST_CONFIG); - ret.erase("LowFreqIntervalSeconds"); - ret.erase("MaxCacheSizeBytes"); - ret.erase("MaxUploadCount"); - ret.erase("MedFreqIntervalSeconds"); - ret.erase("OnlineCheckRetrySeconds"); - ret.erase("OrphanedFileRetentionDays"); - ret.erase("PreferredDownloadType"); - ret.erase("RemoteMount"); - ret.erase("RetryReadCount"); - ret.erase("RingBufferFileSize"); + ret.erase(JSON_LOW_FREQ_INTERVAL_SECS); + ret.erase(JSON_MAX_CACHE_SIZE_BYTES); + ret.erase(JSON_MAX_UPLOAD_COUNT); + ret.erase(JSON_MED_FREQ_INTERVAL_SECS); + ret.erase(JSON_ONLINE_CHECK_RETRY_SECS); + ret.erase(JSON_ORPHANED_FILE_RETENTION_DAYS); + ret.erase(JSON_PREFERRED_DOWNLOAD_TYPE); + ret.erase(JSON_REMOTE_MOUNT); + ret.erase(JSON_RETRY_READ_COUNT); + ret.erase(JSON_RING_BUFFER_FILE_SIZE); ret.erase(JSON_S3_CONFIG); ret.erase(JSON_SIA_CONFIG); } @@ -327,302 +856,169 @@ auto app_config::get_provider_name(const provider_type &prov) -> std::string { return PROVIDER_NAMES.at(static_cast(prov)); } +template +auto app_config::get_value(const json &data, const std::string &name, dest &dst, + bool &success) -> bool { + REPERTORY_USES_FUNCTION_NAME(); + + auto ret{false}; + try { + if (data.find(name) != data.end()) { + data.at(name).get_to(dst); + ret = true; + } else { + success = false; + } + } catch (const std::exception &ex) { + utils::error::raise_error(function_name, ex, + fmt::format("failed to get value|name|{}", name)); + success = false; + ret = false; + } + + return ret; +} + auto app_config::get_value_by_name(const std::string &name) const -> std::string { REPERTORY_USES_FUNCTION_NAME(); try { - if (name == JSON_API_AUTH) { - return get_api_auth(); - } - if (name == JSON_API_PORT) { - return std::to_string(get_api_port()); - } - if (name == JSON_API_USER) { - return get_api_user(); - } - if (name == "DatabaseType") { - return database_type_to_string(get_database_type()); - } - if (name == "ChunkDownloaderTimeoutSeconds") { - return std::to_string(get_chunk_downloader_timeout_secs()); - } - if (name == "EnableChunkDownloaderTimeout") { - return utils::string::from_bool(get_enable_chunk_download_timeout()); - } - if (name == "GetEnableCommDurationEvents") { - return utils::string::from_bool(get_enable_comm_duration_events()); - } - if (name == "EnableDriveEvents") { - return utils::string::from_bool(get_enable_drive_events()); -#if defined(_WIN32) - } - if (name == "EnableMountManager") { - return utils::string::from_bool(get_enable_mount_manager()); -#endif // defined(_WIN32) - } - if (name == fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_PATH)) { - return utils::path::absolute(get_encrypt_config().path); - } - if (name == - fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_ENCRYPTION_TOKEN)) { - return get_encrypt_config().encryption_token; - } - if (name == "EventLevel") { - return event_level_to_string(get_event_level()); - } - if (name == "EvictionDelayMinutes") { - return std::to_string(get_eviction_delay_mins()); - } - if (name == "EvictionUsesAccessedTime") { - return utils::string::from_bool(get_eviction_uses_accessed_time()); - } - if (name == "HighFreqIntervalSeconds") { - return std::to_string(get_high_frequency_interval_secs()); - } - if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_AGENT_STRING)) { - return get_host_config().agent_string; - } - if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PASSWORD)) { - return get_host_config().api_password; - } - if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PORT)) { - return std::to_string(get_host_config().api_port); - } - if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_HOST_NAME_OR_IP)) { - return get_host_config().host_name_or_ip; - } - if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_TIMEOUT_MS)) { - return std::to_string(get_host_config().timeout_ms); - } - if (name == "LowFreqIntervalSeconds") { - return std::to_string(get_low_frequency_interval_secs()); - } - if (name == "MedFreqIntervalSeconds") { - return std::to_string(get_med_frequency_interval_secs()); - } - if (name == "MaxCacheSizeBytes") { - return std::to_string(get_max_cache_size_bytes()); - } - if (name == "MaxUploadCount") { - return std::to_string(get_max_upload_count()); - } - if (name == "OnlineCheckRetrySeconds") { - return std::to_string(get_online_check_retry_secs()); - } - if (name == "OrphanedFileRetentionDays") { - return std::to_string(get_orphaned_file_retention_days()); - } - if (name == "PreferredDownloadType") { - return download_type_to_string(get_preferred_download_type()); - } - if (name == fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_API_PORT)) { - return std::to_string(get_remote_config().api_port); - } - if (name == - fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_ENCRYPTION_TOKEN)) { - return get_remote_config().encryption_token; - } - if (name == - fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_HOST_NAME_OR_IP)) { - return get_remote_config().host_name_or_ip; - } - if (name == - fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_MAX_CONNECTIONS)) { - return std::to_string(get_remote_config().max_connections); - } - if (name == - fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_RECV_TIMEOUT_MS)) { - return std::to_string(get_remote_config().recv_timeout_ms); - } - if (name == - fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_SEND_TIMEOUT_MS)) { - return std::to_string(get_remote_config().send_timeout_ms); - } - if (name == "RemoteMount.Enable") { - return utils::string::from_bool(get_enable_remote_mount()); - } - if (name == "RemoteMount.ClientPoolSize") { - return std::to_string(get_remote_client_pool_size()); - } - if (name == "RemoteMount.ApiPort") { - return std::to_string(get_remote_api_port()); - } - if (name == "RemoteMount.EncryptionToken") { - return get_remote_encryption_token(); - } - if (name == "RetryReadCount") { - return std::to_string(get_retry_read_count()); - } - if (name == "RingBufferFileSize") { - return std::to_string(get_ring_buffer_file_size()); - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ACCESS_KEY)) { - return get_s3_config().access_key; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_BUCKET)) { - return get_s3_config().bucket; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ENCRYPTION_TOKEN)) { - return get_s3_config().encryption_token; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_REGION)) { - return get_s3_config().region; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_SECRET_KEY)) { - return get_s3_config().secret_key; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_URL)) { - return get_s3_config().url; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_USE_PATH_STYLE)) { - return utils::string::from_bool(get_s3_config().use_path_style); - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_USE_REGION_IN_URL)) { - return utils::string::from_bool(get_s3_config().use_region_in_url); - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_TIMEOUT_MS)) { - return std::to_string(get_s3_config().timeout_ms); - } - if (name == fmt::format("{}.{}", JSON_SIA_CONFIG, JSON_BUCKET)) { - return get_sia_config().bucket; - } - if (name == JSON_TASK_WAIT_MS) { - return std::to_string(get_task_wait_ms()); - } + return value_get_lookup_.at(name)(); } catch (const std::exception &e) { - utils::error::raise_error(function_name, e, "exception occurred"); + utils::error::raise_error(function_name, e, + fmt::format("value not found|name|{}", name)); } + return ""; } auto app_config::load() -> bool { REPERTORY_USES_FUNCTION_NAME(); - auto ret{false}; - auto config_file_path = get_config_file_path(); - recur_mutex_lock lock(read_write_mutex_); - if (utils::file::file(config_file_path).exists()) { - try { - std::ifstream config_file(config_file_path.data()); - if (config_file.is_open()) { - std::stringstream stream; - stream << config_file.rdbuf(); - auto json_text = stream.str(); - config_file.close(); - ret = not json_text.empty(); - if (ret) { - auto json_document = json::parse(json_text); - get_value(json_document, JSON_API_AUTH, api_auth_, ret); - get_value(json_document, JSON_API_PORT, api_port_, ret); - get_value(json_document, JSON_API_USER, api_user_, ret); - get_value(json_document, "ChunkDownloaderTimeoutSeconds", - download_timeout_secs_, ret); - get_value(json_document, "DatabaseType", db_type_, ret); - get_value(json_document, "EvictionDelayMinutes", eviction_delay_mins_, - ret); - get_value(json_document, "EvictionUsesAccessedTime", - eviction_uses_accessed_time_, ret); - get_value(json_document, "EnableChunkDownloaderTimeout", - enable_chunk_downloader_timeout_, ret); - get_value(json_document, "EnableCommDurationEvents", - enable_comm_duration_events_, ret); - get_value(json_document, "EnableDriveEvents", enable_drive_events_, - ret); - - if (json_document.find(JSON_ENCRYPT_CONFIG) != json_document.end()) { - json_document.at(JSON_ENCRYPT_CONFIG) - .get_to>(encrypt_config_); - } else { - ret = false; - } - - get_value(json_document, "EventLevel", event_level_, ret); - - if (json_document.find(JSON_HOST_CONFIG) != json_document.end()) { - json_document.at(JSON_HOST_CONFIG) - .get_to>(host_config_); - } else { - ret = false; - } - - if (json_document.find(JSON_S3_CONFIG) != json_document.end()) { - json_document.at(JSON_S3_CONFIG) - .get_to>(s3_config_); - } else { - ret = false; - } - - if (json_document.find(JSON_SIA_CONFIG) != json_document.end()) { - json_document.at(JSON_SIA_CONFIG) - .get_to>(sia_config_); - } else { - ret = false; - } - - get_value(json_document, "RingBufferFileSize", ring_buffer_file_size_, - ret); - get_value(json_document, JSON_TASK_WAIT_MS, task_wait_ms_, ret); -#if defined(_WIN32) - get_value(json_document, "EnableMountManager", enable_mount_manager_, - ret); -#endif // defined(_WIN32) - get_value(json_document, "MaxCacheSizeBytes", max_cache_size_bytes_, - ret); - get_value(json_document, "MaxUploadCount", max_upload_count_, ret); - get_value(json_document, "OnlineCheckRetrySeconds", - online_check_retry_secs_, ret); - get_value(json_document, "HighFreqIntervalSeconds", - high_freq_interval_secs_, ret); - get_value(json_document, "LowFreqIntervalSeconds", - low_freq_interval_secs_, ret); - get_value(json_document, "MedFreqIntervalSeconds", - med_freq_interval_secs_, ret); - get_value(json_document, "OrphanedFileRetentionDays", - orphaned_file_retention_days_, ret); - get_value(json_document, "PreferredDownloadType", - preferred_download_type_, ret); - get_value(json_document, "RetryReadCount", retry_read_count_, ret); - get_value(json_document, JSON_REMOTE_CONFIG, remote_config_, ret); - if (json_document.find("RemoteMount") != json_document.end()) { - auto remoteMount = json_document.at("RemoteMount"); - get_value(remoteMount, "Enable", enable_remote_mount_, ret); - get_value(remoteMount, "ClientPoolSize", remote_client_pool_size_, - ret); - get_value(remoteMount, JSON_API_PORT, remote_api_port_, ret); - get_value(remoteMount, JSON_ENCRYPTION_TOKEN, - remote_encryption_token_, ret); - } else { - ret = false; - } - - std::uint64_t version{}; - get_value(json_document, "Version", version, ret); - - // Handle configuration defaults for new config versions - if (version != REPERTORY_CONFIG_VERSION) { - if (version > REPERTORY_CONFIG_VERSION) { - version = 0U; - } - - version_ = version; - ret = false; - } - } - } - - if (not ret) { - config_changed_ = true; - } - } catch (const std::exception &ex) { - utils::error::raise_error(function_name, ex, "exception occurred"); - ret = false; - } + if (not utils::file::file(config_file_path).exists()) { + config_changed_ = true; + return false; } - return ret; + try { + recur_mutex_lock lock(read_write_mutex_); + + std::ifstream config_file(config_file_path.c_str()); + if (not config_file.is_open()) { + config_changed_ = true; + return false; + } + + std::stringstream stream; + stream << config_file.rdbuf(); + auto json_text = stream.str(); + config_file.close(); + + if (json_text.empty()) { + config_changed_ = true; + return false; + } + + auto ret{false}; + auto json_document = json::parse(json_text); + + get_value(json_document, JSON_API_AUTH, api_auth_, ret); + get_value(json_document, JSON_API_PORT, api_port_, ret); + get_value(json_document, JSON_API_USER, api_user_, ret); + get_value(json_document, JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS, + download_timeout_secs_, ret); + get_value(json_document, JSON_DATABASE_TYPE, db_type_, ret); + get_value(json_document, JSON_EVICTION_DELAY_MINS, eviction_delay_mins_, + ret); + get_value(json_document, JSON_EVICTION_USE_ACCESS_TIME, + eviction_uses_accessed_time_, ret); + get_value(json_document, JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, + enable_chunk_downloader_timeout_, ret); + get_value(json_document, JSON_ENABLE_COMM_DURATION_EVENTS, + enable_comm_duration_events_, ret); + get_value(json_document, JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_, + ret); + + if (json_document.find(JSON_ENCRYPT_CONFIG) != json_document.end()) { + json_document.at(JSON_ENCRYPT_CONFIG) + .get_to>(encrypt_config_); + } else { + ret = false; + } + + get_value(json_document, JSON_EVENT_LEVEL, event_level_, ret); + + if (json_document.find(JSON_HOST_CONFIG) != json_document.end()) { + json_document.at(JSON_HOST_CONFIG) + .get_to>(host_config_); + } else { + ret = false; + } + + if (json_document.find(JSON_S3_CONFIG) != json_document.end()) { + json_document.at(JSON_S3_CONFIG).get_to>(s3_config_); + } else { + ret = false; + } + + if (json_document.find(JSON_SIA_CONFIG) != json_document.end()) { + json_document.at(JSON_SIA_CONFIG).get_to>(sia_config_); + } else { + ret = false; + } + + get_value(json_document, JSON_RING_BUFFER_FILE_SIZE, ring_buffer_file_size_, + ret); + get_value(json_document, JSON_TASK_WAIT_MS, task_wait_ms_, ret); +#if defined(_WIN32) + get_value(json_document, JSON_ENABLE_MOUNT_MANAGER, enable_mount_manager_, + ret); +#endif // defined(_WIN32) + get_value(json_document, JSON_MAX_CACHE_SIZE_BYTES, max_cache_size_bytes_, + ret); + get_value(json_document, JSON_MAX_UPLOAD_COUNT, max_upload_count_, ret); + get_value(json_document, JSON_ONLINE_CHECK_RETRY_SECS, + online_check_retry_secs_, ret); + get_value(json_document, JSON_HIGH_FREQ_INTERVAL_SECS, + high_freq_interval_secs_, ret); + get_value(json_document, JSON_LOW_FREQ_INTERVAL_SECS, + low_freq_interval_secs_, ret); + get_value(json_document, JSON_MED_FREQ_INTERVAL_SECS, + med_freq_interval_secs_, ret); + get_value(json_document, JSON_ORPHANED_FILE_RETENTION_DAYS, + orphaned_file_retention_days_, ret); + get_value(json_document, JSON_PREFERRED_DOWNLOAD_TYPE, + preferred_download_type_, ret); + get_value(json_document, JSON_RETRY_READ_COUNT, retry_read_count_, ret); + get_value(json_document, JSON_REMOTE_CONFIG, remote_config_, ret); + get_value(json_document, JSON_REMOTE_MOUNT, remote_mount_, ret); + + std::uint64_t version{}; + get_value(json_document, JSON_VERSION, version, ret); + + // Handle configuration defaults for new config versions + if (version != REPERTORY_CONFIG_VERSION) { + if (version > REPERTORY_CONFIG_VERSION) { + version = REPERTORY_CONFIG_VERSION; + } + + version_ = version; + ret = false; + } + + config_changed_ = not ret; + return ret; + } catch (const std::exception &ex) { + utils::error::raise_error( + function_name, ex, + fmt::format("failed to load configuration file|sp|{}", + config_file_path)); + } + + return false; } void app_config::save() { @@ -631,28 +1027,20 @@ void app_config::save() { recur_mutex_lock lock(read_write_mutex_); auto file_path = get_config_file_path(); - if (config_changed_ || not utils::file::file(file_path).exists()) { - if (not utils::file::directory{data_directory_}.create_directory()) { - utils::error::raise_error( - function_name, "failed to create directory|sp|" + data_directory_ + - "|err|" + - std::to_string(utils::get_last_error_code())); - } - - config_changed_ = false; - json data = get_json(); - auto success = false; - for (auto i = 0U; not success && (i < retry_save_count); i++) { - success = utils::file::write_json_file(file_path, data); - if (not success) { - std::this_thread::sleep_for(1s); - } - } + if (not(config_changed_ || utils::file::file(file_path).exists())) { + return; } -} -void app_config::set_enable_remote_mount(bool enable_remote_mount) { - set_value(enable_remote_mount_, enable_remote_mount); + if (not utils::file::directory{data_directory_}.create_directory()) { + utils::error::raise_error( + function_name, + fmt::format("failed to create directory|sp|{}|err|{}", data_directory_, + utils::get_last_error_code())); + } + + config_changed_ = not utils::retry_action([this, &file_path]() -> bool { + return utils::file::write_json_file(file_path, get_json()); + }); } void app_config::set_encrypt_config(encrypt_config cfg) { @@ -667,272 +1055,35 @@ void app_config::set_remote_config(remote::remote_config cfg) { set_value(remote_config_, cfg); } +void app_config::set_remote_mount(remote::remote_mount cfg) { + set_value(remote_mount_, cfg); +} + void app_config::set_s3_config(s3_config cfg) { set_value(s3_config_, cfg); } void app_config::set_sia_config(sia_config cfg) { set_value(sia_config_, cfg); } +template +auto app_config::set_value(dest &dst, const source &src) -> bool { + if (dst == src) { + return false; + } + + dst = src; + config_changed_ = true; + save(); + return true; +} + auto app_config::set_value_by_name(const std::string &name, const std::string &value) -> std::string { REPERTORY_USES_FUNCTION_NAME(); try { - if (name == JSON_API_AUTH) { - set_api_auth(value); - return get_api_auth(); - } - if (name == JSON_API_PORT) { - set_api_port(utils::string::to_uint16(value)); - return std::to_string(get_api_port()); - } - if (name == JSON_API_USER) { - set_api_user(value); - return get_api_user(); - } - if (name == "ChunkDownloaderTimeoutSeconds") { - set_chunk_downloader_timeout_secs(utils::string::to_uint8(value)); - return std::to_string(get_chunk_downloader_timeout_secs()); - } - if (name == "DatabaseType") { - set_database_type( - database_type_from_string(value, database_type::rocksdb)); - return database_type_to_string(db_type_); - } - if (name == "EnableChunkDownloaderTimeout") { - set_enable_chunk_downloader_timeout(utils::string::to_bool(value)); - return utils::string::from_bool(get_enable_chunk_download_timeout()); - } - if (name == "EnableCommDurationEvents") { - set_enable_comm_duration_events(utils::string::to_bool(value)); - return utils::string::from_bool(get_enable_comm_duration_events()); - } - if (name == "EnableDriveEvents") { - set_enable_drive_events(utils::string::to_bool(value)); - return utils::string::from_bool(get_enable_drive_events()); -#if defined(_WIN32) - } - if (name == "EnableMountManager") { - set_enable_mount_manager(utils::string::to_bool(value)); - return utils::string::from_bool(get_enable_mount_manager()); -#endif // defined(_WIN32) - } - if (name == - fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_ENCRYPTION_TOKEN)) { - auto cfg = get_encrypt_config(); - cfg.encryption_token = value; - set_encrypt_config(cfg); - return get_encrypt_config().encryption_token; - } - if (name == fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_PATH)) { - auto cfg = get_encrypt_config(); - cfg.path = value; - set_encrypt_config(cfg); - return get_encrypt_config().path; - } - if (name == "EventLevel") { - set_event_level(event_level_from_string(value)); - return event_level_to_string(get_event_level()); - } - if (name == "EvictionDelayMinutes") { - set_eviction_delay_mins(utils::string::to_uint32(value)); - return std::to_string(get_eviction_delay_mins()); - } - if (name == "EvictionUsesAccessedTime") { - set_eviction_uses_accessed_time(utils::string::to_bool(value)); - return utils::string::from_bool(get_eviction_uses_accessed_time()); - } - if (name == "HighFreqIntervalSeconds") { - set_high_frequency_interval_secs(utils::string::to_uint8(value)); - return std::to_string(get_high_frequency_interval_secs()); - } - if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_AGENT_STRING)) { - auto cfg = get_host_config(); - cfg.agent_string = value; - set_host_config(cfg); - return get_host_config().agent_string; - } - if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PASSWORD)) { - auto cfg = get_host_config(); - cfg.api_password = value; - set_host_config(cfg); - return get_host_config().api_password; - } - if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PORT)) { - auto cfg = get_host_config(); - cfg.api_port = utils::string::to_uint16(value); - set_host_config(cfg); - return std::to_string(get_host_config().api_port); - } - if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_HOST_NAME_OR_IP)) { - auto cfg = get_host_config(); - cfg.host_name_or_ip = value; - set_host_config(cfg); - return get_host_config().host_name_or_ip; - } - if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_TIMEOUT_MS)) { - auto cfg = get_host_config(); - cfg.timeout_ms = utils::string::to_uint32(value); - set_host_config(cfg); - return std::to_string(get_host_config().timeout_ms); - } - if (name == "LowFreqIntervalSeconds") { - set_low_frequency_interval_secs(utils::string::to_uint16(value)); - return std::to_string(get_low_frequency_interval_secs()); - } - if (name == "MedFreqIntervalSeconds") { - set_med_frequency_interval_secs(utils::string::to_uint16(value)); - return std::to_string(get_med_frequency_interval_secs()); - } - if (name == "MaxCacheSizeBytes") { - set_max_cache_size_bytes(utils::string::to_uint64(value)); - return std::to_string(get_max_cache_size_bytes()); - } - if (name == "MaxUploadCount") { - set_max_upload_count(utils::string::to_uint8(value)); - return std::to_string(get_max_upload_count()); - } - if (name == "OnlineCheckRetrySeconds") { - set_online_check_retry_secs(utils::string::to_uint16(value)); - return std::to_string(get_online_check_retry_secs()); - } - if (name == "OrphanedFileRetentionDays") { - set_orphaned_file_retention_days(utils::string::to_uint16(value)); - return std::to_string(get_orphaned_file_retention_days()); - } - if (name == "PreferredDownloadType") { - set_preferred_download_type(download_type_from_string(value)); - return download_type_to_string(get_preferred_download_type()); - } - if (name == fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_API_PORT)) { - auto cfg = get_remote_config(); - cfg.api_port = utils::string::to_uint16(value); - set_remote_config(cfg); - return std::to_string(get_remote_config().api_port); - } - if (name == - fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_ENCRYPTION_TOKEN)) { - auto cfg = get_remote_config(); - cfg.encryption_token = value; - set_remote_config(cfg); - return get_remote_config().encryption_token; - } - if (name == - fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_HOST_NAME_OR_IP)) { - auto cfg = get_remote_config(); - cfg.host_name_or_ip = value; - set_remote_config(cfg); - return get_remote_config().host_name_or_ip; - } - if (name == - fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_MAX_CONNECTIONS)) { - auto cfg = get_remote_config(); - cfg.max_connections = utils::string::to_uint8(value); - set_remote_config(cfg); - return std::to_string(get_remote_config().max_connections); - } - if (name == - fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_RECV_TIMEOUT_MS)) { - auto cfg = get_remote_config(); - cfg.recv_timeout_ms = utils::string::to_uint32(value); - set_remote_config(cfg); - return std::to_string(get_remote_config().recv_timeout_ms); - } - if (name == - fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_SEND_TIMEOUT_MS)) { - auto cfg = get_remote_config(); - cfg.send_timeout_ms = utils::string::to_uint32(value); - set_remote_config(cfg); - return std::to_string(get_remote_config().send_timeout_ms); - } - if (name == "RemoteMount.ApiPort") { - set_remote_api_port(utils::string::to_uint16(value)); - return std::to_string(get_remote_api_port()); - } - if (name == "RemoteMount.ClientPoolSize") { - set_remote_client_pool_size(utils::string::to_uint8(value)); - return std::to_string(get_remote_client_pool_size()); - } - if (name == "RemoteMount.Enable") { - set_enable_remote_mount(utils::string::to_bool(value)); - return utils::string::from_bool(get_enable_remote_mount()); - } - if (name == "RemoteMount.EncryptionToken") { - set_remote_encryption_token(value); - return get_remote_encryption_token(); - } - if (name == "RetryReadCount") { - set_retry_read_count(utils::string::to_uint16(value)); - return std::to_string(get_retry_read_count()); - } - if (name == "RingBufferFileSize") { - set_ring_buffer_file_size(utils::string::to_uint16(value)); - return std::to_string(get_ring_buffer_file_size()); - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ACCESS_KEY)) { - auto cfg = get_s3_config(); - cfg.access_key = value; - set_s3_config(cfg); - return get_s3_config().access_key; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_BUCKET)) { - auto cfg = get_s3_config(); - cfg.bucket = value; - set_s3_config(cfg); - return get_s3_config().bucket; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ENCRYPTION_TOKEN)) { - auto cfg = get_s3_config(); - cfg.encryption_token = value; - set_s3_config(cfg); - return get_s3_config().encryption_token; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_REGION)) { - auto cfg = get_s3_config(); - cfg.region = value; - set_s3_config(cfg); - return get_s3_config().region; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_SECRET_KEY)) { - auto cfg = get_s3_config(); - cfg.secret_key = value; - set_s3_config(cfg); - return get_s3_config().secret_key; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_TIMEOUT_MS)) { - auto cfg = get_s3_config(); - cfg.timeout_ms = utils::string::to_uint32(value); - set_s3_config(cfg); - return std::to_string(get_s3_config().timeout_ms); - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_URL)) { - auto cfg = get_s3_config(); - cfg.url = value; - set_s3_config(cfg); - return get_s3_config().url; - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_USE_PATH_STYLE)) { - auto cfg = get_s3_config(); - cfg.use_path_style = utils::string::to_bool(value); - set_s3_config(cfg); - return utils::string::from_bool(get_s3_config().use_path_style); - } - if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_USE_REGION_IN_URL)) { - auto cfg = get_s3_config(); - cfg.use_region_in_url = utils::string::to_bool(value); - set_s3_config(cfg); - return utils::string::from_bool(get_s3_config().use_region_in_url); - } - if (name == fmt::format("{}.{}", JSON_SIA_CONFIG, JSON_BUCKET)) { - auto cfg = get_sia_config(); - cfg.bucket = value; - set_sia_config(cfg); - return get_sia_config().bucket; - } - if (name == JSON_TASK_WAIT_MS) { - set_task_wait_ms(utils::string::to_uint16(value)); - return std::to_string(get_task_wait_ms()); - } + return value_set_lookup_.at(name)(value); } catch (const std::exception &e) { - utils::error::raise_error(function_name, e, "exception occurred"); + utils::error::raise_error(function_name, e, + fmt::format("value not found|name|{}", name)); } return ""; diff --git a/repertory/repertory_test/src/config_test.cpp b/repertory/repertory_test/src/config_test.cpp index a61e85c2..17a1fee9 100644 --- a/repertory/repertory_test/src/config_test.cpp +++ b/repertory/repertory_test/src/config_test.cpp @@ -31,30 +31,34 @@ namespace repertory { class config_test : public ::testing::Test { public: static console_consumer cs; + static std::atomic idx; - std::string s3_directory{ - utils::path::combine(test::get_test_output_dir(), {"config_test", "s3"})}; - - std::string sia_directory{utils::path::combine(test::get_test_output_dir(), - {"config_test", "sia"})}; + std::string s3_directory; + std::string sia_directory; void SetUp() override { + s3_directory = utils::path::combine(test::get_test_output_dir(), + { + "config_test", + "s3", + std::to_string(++idx), + }); + + sia_directory = utils::path::combine(test::get_test_output_dir(), + { + "config_test", + "sia", + std::to_string(++idx), + }); event_system::instance().start(); - ASSERT_TRUE( - utils::file::directory( - utils::path::combine(test::get_test_output_dir(), {"config_test"})) - .remove_recursively()); } - void TearDown() override { - ASSERT_TRUE( - utils::file::directory( - utils::path::combine(test::get_test_output_dir(), {"config_test"})) - .remove_recursively()); - event_system::instance().stop(); - } + void TearDown() override { event_system::instance().stop(); } }; +console_consumer config_test::cs; +std::atomic config_test::idx{0U}; + TEST_F(config_test, api_path) { std::string original_value; { @@ -538,19 +542,19 @@ TEST_F(config_test, enable_remote_mount) { // } // } -TEST_F(config_test, remote_api_port) { - std::uint16_t original_value{}; - { - app_config config(provider_type::sia, sia_directory); - original_value = config.get_remote_api_port(); - config.set_remote_api_port(original_value + 5); - EXPECT_EQ(original_value + 5, config.get_remote_api_port()); - } - { - app_config config(provider_type::sia, sia_directory); - EXPECT_EQ(original_value + 5, config.get_remote_api_port()); - } -} +// TEST_F(config_test, remote_api_port) { +// std::uint16_t original_value{}; +// { +// app_config config(provider_type::sia, sia_directory); +// original_value = config.get_remote_api_port(); +// config.set_remote_api_port(original_value + 5); +// EXPECT_EQ(original_value + 5, config.get_remote_api_port()); +// } +// { +// app_config config(provider_type::sia, sia_directory); +// EXPECT_EQ(original_value + 5, config.get_remote_api_port()); +// } +// } // TEST_F(config_test, remote_receive_timeout_secs) { // std::uint16_t original_value{}; @@ -580,43 +584,43 @@ TEST_F(config_test, remote_api_port) { // } // } -TEST_F(config_test, remote_encryption_token) { - { - app_config config(provider_type::sia, sia_directory); - config.set_remote_encryption_token("myToken"); - EXPECT_STREQ("myToken", config.get_remote_encryption_token().c_str()); - } - { - app_config config(provider_type::sia, sia_directory); - EXPECT_STREQ("myToken", config.get_remote_encryption_token().c_str()); - } -} - -TEST_F(config_test, remote_client_pool_size) { - std::uint8_t original_value{}; - { - app_config config(provider_type::sia, sia_directory); - original_value = config.get_remote_client_pool_size(); - config.set_remote_client_pool_size(original_value + 5); - EXPECT_EQ(original_value + 5, config.get_remote_client_pool_size()); - } - { - app_config config(provider_type::sia, sia_directory); - EXPECT_EQ(original_value + 5, config.get_remote_client_pool_size()); - } -} - -TEST_F(config_test, remote_client_pool_size_minimum_value) { - { - app_config config(provider_type::sia, sia_directory); - config.set_remote_client_pool_size(0); - EXPECT_EQ(5, config.get_remote_client_pool_size()); - } - { - app_config config(provider_type::sia, sia_directory); - EXPECT_EQ(5, config.get_remote_client_pool_size()); - } -} +// TEST_F(config_test, remote_encryption_token) { +// { +// app_config config(provider_type::sia, sia_directory); +// config.set_remote_encryption_token("myToken"); +// EXPECT_STREQ("myToken", config.get_remote_encryption_token().c_str()); +// } +// { +// app_config config(provider_type::sia, sia_directory); +// EXPECT_STREQ("myToken", config.get_remote_encryption_token().c_str()); +// } +// } +// +// TEST_F(config_test, remote_client_pool_size) { +// std::uint8_t original_value{}; +// { +// app_config config(provider_type::sia, sia_directory); +// original_value = config.get_remote_client_pool_size(); +// config.set_remote_client_pool_size(original_value + 5); +// EXPECT_EQ(original_value + 5, config.get_remote_client_pool_size()); +// } +// { +// app_config config(provider_type::sia, sia_directory); +// EXPECT_EQ(original_value + 5, config.get_remote_client_pool_size()); +// } +// } +// +// TEST_F(config_test, remote_client_pool_size_minimum_value) { +// { +// app_config config(provider_type::sia, sia_directory); +// config.set_remote_client_pool_size(0); +// EXPECT_EQ(5, config.get_remote_client_pool_size()); +// } +// { +// app_config config(provider_type::sia, sia_directory); +// EXPECT_EQ(5, config.get_remote_client_pool_size()); +// } +// } // TEST_F(config_test, remote_max_connections) { // std::uint8_t original_value{}; diff --git a/repertory/repertory_test/src/json_serialize_test.cpp b/repertory/repertory_test/src/json_serialize_test.cpp index ac051ee8..f80715a6 100644 --- a/repertory/repertory_test/src/json_serialize_test.cpp +++ b/repertory/repertory_test/src/json_serialize_test.cpp @@ -27,16 +27,15 @@ namespace repertory { TEST(json_serialize, can_handle_directory_item) { directory_item cfg{ - "api", "parent", true, 2U, {{META_DIRECTORY, "true"}}, false, + "api", "parent", true, 2U, {{META_DIRECTORY, "true"}}, }; json data(cfg); EXPECT_STREQ("api", data.at(JSON_API_PATH).get().c_str()); EXPECT_STREQ("parent", data.at(JSON_API_PARENT).get().c_str()); EXPECT_TRUE(data.at(JSON_DIRECTORY).get()); - EXPECT_STREQ("true", - data.at("meta").at(META_DIRECTORY).get().c_str()); - EXPECT_FALSE(data.at("Resolved").get()); + EXPECT_STREQ( + "true", data.at(JSON_META).at(META_DIRECTORY).get().c_str()); { auto cfg2 = data.get(); @@ -45,7 +44,6 @@ TEST(json_serialize, can_handle_directory_item) { EXPECT_EQ(cfg2.directory, cfg.directory); EXPECT_STREQ(cfg2.meta.at(META_DIRECTORY).c_str(), cfg.meta.at(META_DIRECTORY).c_str()); - EXPECT_EQ(cfg2.resolved, cfg.resolved); } } @@ -122,6 +120,25 @@ TEST(json_serialize, can_handle_remote_config) { } } +TEST(json_serialize, can_handle_remote_mount) { + remote::remote_mount cfg{1024U, 21U, true, "token"}; + + json data(cfg); + EXPECT_EQ(1024U, data.at(JSON_API_PORT).get()); + EXPECT_EQ(21U, data.at(JSON_CLIENT_POOL_SIZE).get()); + EXPECT_TRUE(data.at(JSON_ENABLE_REMOTE_MOUNT).get()); + EXPECT_STREQ("token", + data.at(JSON_ENCRYPTION_TOKEN).get().c_str()); + + { + auto cfg2 = data.get(); + EXPECT_EQ(cfg2.api_port, cfg.api_port); + EXPECT_EQ(cfg2.client_pool_size, cfg.client_pool_size); + EXPECT_EQ(cfg2.enable, cfg.enable); + EXPECT_STREQ(cfg2.encryption_token.c_str(), cfg.encryption_token.c_str()); + } +} + TEST(json_serialize, can_handle_s3_config) { s3_config cfg{ "access", "bucket", "token", "region", "secret", 31U, "url", true, false,