diff --git a/repertory/librepertory/include/app_config.hpp b/repertory/librepertory/include/app_config.hpp index f3d9aa85..359f7440 100644 --- a/repertory/librepertory/include/app_config.hpp +++ b/repertory/librepertory/include/app_config.hpp @@ -95,7 +95,7 @@ private: std::string cache_directory_; std::string data_directory_; atomic encrypt_config_; - atomic hc_; + atomic host_config_; std::string log_directory_; mutable std::recursive_mutex read_write_mutex_; atomic remote_config_; @@ -210,7 +210,9 @@ public: high_freq_interval_secs_.load()); } - [[nodiscard]] auto get_host_config() const -> host_config { return hc_; } + [[nodiscard]] auto get_host_config() const -> host_config { + return host_config_; + } [[nodiscard]] auto get_json() const -> json; diff --git a/repertory/librepertory/include/types/remote.hpp b/repertory/librepertory/include/types/remote.hpp index b9e880e5..7a8b6d22 100644 --- a/repertory/librepertory/include/types/remote.hpp +++ b/repertory/librepertory/include/types/remote.hpp @@ -22,6 +22,8 @@ #ifndef REPERTORY_INCLUDE_TYPES_REMOTE_HPP_ #define REPERTORY_INCLUDE_TYPES_REMOTE_HPP_ +#include "types/repertory.hpp" + inline constexpr const auto PACKET_SERVICE_FUSE{1U}; inline constexpr const auto PACKET_SERVICE_WINFSP{2U}; @@ -194,22 +196,22 @@ NLOHMANN_JSON_NAMESPACE_BEGIN template <> struct adl_serializer { static void to_json(json &data, const repertory::remote::remote_config &value) { - data["ApiPort"] = value.api_port; - data["EncryptionToken"] = value.encryption_token; - data["HostNameOrIp"] = value.host_name_or_ip; - data["MaxConnections"] = value.max_connections; - data["ReceiveTimeoutMs"] = value.recv_timeout_ms; - data["SendTimeoutMs"] = value.send_timeout_ms; + data[repertory::JSON_API_PORT] = value.api_port; + data[repertory::JSON_ENCRYPTION_TOKEN] = value.encryption_token; + data[repertory::JSON_HOST_NAME_OR_IP] = value.host_name_or_ip; + data[repertory::JSON_MAX_CONNECTIONS] = value.max_connections; + data[repertory::JSON_RECV_TIMEOUT_MS] = value.recv_timeout_ms; + data[repertory::JSON_SEND_TIMEOUT_MS] = value.send_timeout_ms; } static void from_json(const json &data, repertory::remote::remote_config &value) { - data.at("ApiPort").get_to(value.api_port); - data.at("EncryptionToken").get_to(value.encryption_token); - data.at("HostNameOrIp").get_to(value.host_name_or_ip); - data.at("MaxConnections").get_to(value.max_connections); - data.at("ReceiveTimeoutMs").get_to(value.recv_timeout_ms); - data.at("SendTimeoutMs").get_to(value.send_timeout_ms); + data.at(repertory::JSON_API_PORT).get_to(value.api_port); + data.at(repertory::JSON_ENCRYPTION_TOKEN).get_to(value.encryption_token); + data.at(repertory::JSON_HOST_NAME_OR_IP).get_to(value.host_name_or_ip); + data.at(repertory::JSON_MAX_CONNECTIONS).get_to(value.max_connections); + data.at(repertory::JSON_RECV_TIMEOUT_MS).get_to(value.recv_timeout_ms); + data.at(repertory::JSON_SEND_TIMEOUT_MS).get_to(value.send_timeout_ms); } }; NLOHMANN_JSON_NAMESPACE_END diff --git a/repertory/librepertory/include/types/repertory.hpp b/repertory/librepertory/include/types/repertory.hpp index 1855a2bc..3c934a4d 100644 --- a/repertory/librepertory/include/types/repertory.hpp +++ b/repertory/librepertory/include/types/repertory.hpp @@ -398,96 +398,128 @@ using api_file_provider_callback = std::function; using api_item_added_callback = std::function; using directory_item_list = std::vector; using meta_provider_callback = std::function; + +inline constexpr const auto JSON_ACCESS_KEY{"AccessKey"}; +inline constexpr const auto JSON_AGENT_STRING{"AgentString"}; +inline constexpr const auto JSON_API_AUTH{"ApiAuth"}; +inline constexpr const auto JSON_API_PARENT{"ApiParent"}; +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_BUCKET{"Bucket"}; +inline constexpr const auto JSON_DIRECTORY{"Directory"}; +inline constexpr const auto JSON_ENCRYPTION_TOKEN{"EncryptionToken"}; +inline constexpr const auto JSON_ENCRYPT_CONFIG{"EncryptConfig"}; +inline constexpr const auto JSON_HOST_CONFIG{"HostConfig"}; +inline constexpr const auto JSON_HOST_NAME_OR_IP{"HostNameOrIp"}; +inline constexpr const auto JSON_MAX_CONNECTIONS{"MaxConnections"}; +inline constexpr const auto JSON_META{"Meta"}; +inline constexpr const auto JSON_PATH{"Path"}; +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_S3_CONFIG{"S3Config"}; +inline constexpr const auto JSON_SECRET_KEY{"SecretKey"}; +inline constexpr const auto JSON_SEND_TIMEOUT_MS{"SendTimeoutMs"}; +inline constexpr const auto JSON_SIA_CONFIG{"SiaConfig"}; +inline constexpr const auto JSON_SIZE{"Size"}; +inline constexpr const auto JSON_TASK_WAIT_MS{"TaskWaitMs"}; +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"}; } // namespace repertory NLOHMANN_JSON_NAMESPACE_BEGIN template <> struct adl_serializer { static void to_json(json &data, const repertory::directory_item &value) { - data["ApiParent"] = value.api_parent; - data["ApiPath"] = value.api_path; - data["Directory"] = value.directory; - data["Meta"] = value.meta; - data["Size"] = value.size; + data[repertory::JSON_API_PARENT] = value.api_parent; + data[repertory::JSON_API_PATH] = value.api_path; + data[repertory::JSON_DIRECTORY] = value.directory; + data[repertory::JSON_META] = value.meta; + data[repertory::JSON_SIZE] = value.size; } static void from_json(const json &data, repertory::directory_item &value) { - data.at("ApiParent").get_to(value.api_parent); - data.at("ApiPath").get_to(value.api_path); - data.at("Directory").get_to(value.directory); - data.at("Meta").get_to(value.meta); - data.at("Size").get_to(value.size); + data.at(repertory::JSON_API_PARENT).get_to(value.api_parent); + data.at(repertory::JSON_API_PATH).get_to(value.api_path); + data.at(repertory::JSON_DIRECTORY).get_to(value.directory); + data.at(repertory::JSON_META).get_to(value.meta); + data.at(repertory::JSON_SIZE).get_to(value.size); } }; template <> struct adl_serializer { static void to_json(json &data, const repertory::encrypt_config &value) { - data["EncryptionToken"] = value.encryption_token; - data["Path"] = value.path; + data[repertory::JSON_ENCRYPTION_TOKEN] = value.encryption_token; + data[repertory::JSON_PATH] = value.path; } static void from_json(const json &data, repertory::encrypt_config &value) { - data.at("EncryptionToken").get_to(value.encryption_token); - data.at("Path").get_to(value.path); + data.at(repertory::JSON_ENCRYPTION_TOKEN).get_to(value.encryption_token); + data.at(repertory::JSON_PATH).get_to(value.path); } }; template <> struct adl_serializer { static void to_json(json &data, const repertory::host_config &value) { - data["AgentString"] = value.agent_string; - data["ApiPassword"] = value.api_password; - data["ApiPort"] = value.api_port; - data["ApiUser"] = value.api_user; - data["HostNameOrIp"] = value.host_name_or_ip; - data["Path"] = value.path; - data["Protocol"] = value.protocol; - data["TimeoutMs"] = value.timeout_ms; + data[repertory::JSON_AGENT_STRING] = value.agent_string; + data[repertory::JSON_API_PASSWORD] = value.api_password; + data[repertory::JSON_API_PORT] = value.api_port; + data[repertory::JSON_API_USER] = value.api_user; + data[repertory::JSON_HOST_NAME_OR_IP] = value.host_name_or_ip; + data[repertory::JSON_PATH] = value.path; + data[repertory::JSON_PROTOCOL] = value.protocol; + data[repertory::JSON_TIMEOUT_MS] = value.timeout_ms; } static void from_json(const json &data, repertory::host_config &value) { - data.at("AgentString").get_to(value.agent_string); - data.at("ApiPassword").get_to(value.api_password); - data.at("ApiPort").get_to(value.api_port); - data.at("AuthUser").get_to(value.api_user); - data.at("HostNameOrIp").get_to(value.host_name_or_ip); - data.at("Path").get_to(value.path); - data.at("Protocol").get_to(value.protocol); - data.at("TimeoutMs").get_to(value.timeout_ms); + data.at(repertory::JSON_AGENT_STRING).get_to(value.agent_string); + data.at(repertory::JSON_API_PASSWORD).get_to(value.api_password); + data.at(repertory::JSON_API_PORT).get_to(value.api_port); + data.at(repertory::JSON_API_USER).get_to(value.api_user); + data.at(repertory::JSON_HOST_NAME_OR_IP).get_to(value.host_name_or_ip); + data.at(repertory::JSON_PATH).get_to(value.path); + data.at(repertory::JSON_PROTOCOL).get_to(value.protocol); + data.at(repertory::JSON_TIMEOUT_MS).get_to(value.timeout_ms); } }; template <> struct adl_serializer { static void to_json(json &data, const repertory::s3_config &value) { - data["AccessKey"] = value.access_key; - data["Bucket"] = value.bucket; - data["EncryptionToken"] = value.encryption_token; - data["Region"] = value.region; - data["SecretKey"] = value.secret_key; - data["TimeoutMs"] = value.timeout_ms; - data["URL"] = value.url; - data["UsePathStyle"] = value.use_path_style; - data["UseRegionInURL"] = value.use_region_in_url; + data[repertory::JSON_ACCESS_KEY] = value.access_key; + data[repertory::JSON_BUCKET] = value.bucket; + data[repertory::JSON_ENCRYPTION_TOKEN] = value.encryption_token; + data[repertory::JSON_REGION] = value.region; + data[repertory::JSON_SECRET_KEY] = value.secret_key; + data[repertory::JSON_TIMEOUT_MS] = value.timeout_ms; + data[repertory::JSON_URL] = value.url; + data[repertory::JSON_USE_PATH_STYLE] = value.use_path_style; + data[repertory::JSON_USE_REGION_IN_URL] = value.use_region_in_url; } static void from_json(const json &data, repertory::s3_config &value) { - data.at("AccessKey").get_to(value.access_key); - data.at("Bucket").get_to(value.bucket); - data.at("EncryptionToken").get_to(value.encryption_token); - data.at("Region").get_to(value.region); - data.at("SecretKey").get_to(value.secret_key); - data.at("TimeoutMs").get_to(value.timeout_ms); - data.at("URL").get_to(value.url); - data.at("UsePathStyle").get_to(value.use_path_style); - data.at("UseRegionInURL").get_to(value.use_region_in_url); + data.at(repertory::JSON_ACCESS_KEY).get_to(value.access_key); + data.at(repertory::JSON_BUCKET).get_to(value.bucket); + data.at(repertory::JSON_ENCRYPTION_TOKEN).get_to(value.encryption_token); + data.at(repertory::JSON_REGION).get_to(value.region); + data.at(repertory::JSON_SECRET_KEY).get_to(value.secret_key); + data.at(repertory::JSON_TIMEOUT_MS).get_to(value.timeout_ms); + data.at(repertory::JSON_URL).get_to(value.url); + data.at(repertory::JSON_USE_PATH_STYLE).get_to(value.use_path_style); + data.at(repertory::JSON_USE_REGION_IN_URL).get_to(value.use_region_in_url); } }; template <> struct adl_serializer { static void to_json(json &data, const repertory::sia_config &value) { - data["Bucket"] = value.bucket; + data[repertory::JSON_BUCKET] = value.bucket; } static void from_json(const json &data, repertory::sia_config &value) { - data.at("Bucket").get_to(value.bucket); + data.at(repertory::JSON_BUCKET).get_to(value.bucket); } }; diff --git a/repertory/librepertory/src/app_config.cpp b/repertory/librepertory/src/app_config.cpp index 4f5a0cb0..8156b6a9 100644 --- a/repertory/librepertory/src/app_config.cpp +++ b/repertory/librepertory/src/app_config.cpp @@ -203,9 +203,9 @@ auto app_config::get_config_file_path() const -> std::string { auto app_config::get_json() const -> json { json ret = { - {"ApiAuth", api_auth_}, - {"ApiPort", api_port_}, - {"ApiUser", api_user_}, + {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_}, @@ -214,12 +214,12 @@ auto app_config::get_json() const -> json { #if defined(_WIN32) {"EnableMountManager", enable_mount_manager_}, #endif // defined(_WIN32) - {"EncryptConfig", encrypt_config_}, + {JSON_ENCRYPT_CONFIG, encrypt_config_}, {"EventLevel", event_level_}, {"EvictionDelayMinutes", eviction_delay_mins_}, {"EvictionUsesAccessedTime", eviction_uses_accessed_time_}, {"HighFreqIntervalSeconds", high_freq_interval_secs_}, - {"HostConfig", hc_}, + {JSON_HOST_CONFIG, host_config_}, {"LowFreqIntervalSeconds", low_freq_interval_secs_}, {"MaxCacheSizeBytes", max_cache_size_bytes_}, {"MaxUploadCount", max_upload_count_}, @@ -227,20 +227,20 @@ auto app_config::get_json() const -> json { {"OnlineCheckRetrySeconds", online_check_retry_secs_}, {"OrphanedFileRetentionDays", orphaned_file_retention_days_}, {"PreferredDownloadType", preferred_download_type_}, - {"RemoteConfig", remote_config_}, + {JSON_REMOTE_CONFIG, remote_config_}, { "RemoteMount", { - {"ApiPort", remote_api_port_}, + {JSON_API_PORT, remote_api_port_}, {"ClientPoolSize", remote_client_pool_size_}, {"Enable", enable_remote_mount_}, - {"EncryptionToken", remote_encryption_token_}, + {JSON_ENCRYPTION_TOKEN, remote_encryption_token_}, }, }, {"RetryReadCount", retry_read_count_}, {"RingBufferFileSize", ring_buffer_file_size_}, - {"S3Config", s3_config_}, - {"SiaConfig", sia_config_}, + {JSON_S3_CONFIG, s3_config_}, + {JSON_SIA_CONFIG, sia_config_}, {"TaskWaitMillis", task_wait_ms_}, {"Version", version_}}; @@ -249,35 +249,35 @@ auto app_config::get_json() const -> json { ret.erase("EnableChunkDownloaderTimeout"); ret.erase("EvictionDelayMinutes"); ret.erase("EvictionUsesAccessedTime"); - ret.erase("HostConfig"); + ret.erase(JSON_HOST_CONFIG); ret.erase("MaxCacheSizeBytes"); ret.erase("MaxUploadCount"); ret.erase("OnlineCheckRetrySeconds"); ret.erase("OrphanedFileRetentionDays"); ret.erase("PreferredDownloadType"); - ret.erase("RemoteConfig"); + ret.erase(JSON_REMOTE_CONFIG); ret.erase("RetryReadCount"); ret.erase("RingBufferFileSize"); - ret.erase("S3Config"); - ret.erase("SiaConfig"); + ret.erase(JSON_S3_CONFIG); + ret.erase(JSON_SIA_CONFIG); } else if (prov_ == provider_type::s3) { - ret.erase("EncryptConfig"); - ret.erase("HostConfig"); - ret.erase("RemoteConfig"); - ret.erase("SiaConfig"); + ret.erase(JSON_ENCRYPT_CONFIG); + ret.erase(JSON_HOST_CONFIG); + ret.erase(JSON_REMOTE_CONFIG); + ret.erase(JSON_SIA_CONFIG); } else if (prov_ == provider_type::sia) { - ret.erase("EncryptConfig"); - ret.erase("RemoteConfig"); - ret.erase("S3Config"); + ret.erase(JSON_ENCRYPT_CONFIG); + 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("EncryptConfig"); + ret.erase(JSON_ENCRYPT_CONFIG); ret.erase("EvictionDelayMinutes"); ret.erase("EvictionUsesAccessedTime"); ret.erase("HighFreqIntervalSeconds"); - ret.erase("HostConfig"); + ret.erase(JSON_HOST_CONFIG); ret.erase("LowFreqIntervalSeconds"); ret.erase("MaxCacheSizeBytes"); ret.erase("MaxUploadCount"); @@ -288,8 +288,8 @@ auto app_config::get_json() const -> json { ret.erase("RemoteMount"); ret.erase("RetryReadCount"); ret.erase("RingBufferFileSize"); - ret.erase("S3Config"); - ret.erase("SiaConfig"); + ret.erase(JSON_S3_CONFIG); + ret.erase(JSON_SIA_CONFIG); } return ret; @@ -332,13 +332,13 @@ auto app_config::get_value_by_name(const std::string &name) const REPERTORY_USES_FUNCTION_NAME(); try { - if (name == "ApiAuth") { + if (name == JSON_API_AUTH) { return get_api_auth(); } - if (name == "ApiPort") { + if (name == JSON_API_PORT) { return std::to_string(get_api_port()); } - if (name == "ApiUser") { + if (name == JSON_API_USER) { return get_api_user(); } if (name == "DatabaseType") { @@ -361,10 +361,11 @@ auto app_config::get_value_by_name(const std::string &name) const return utils::string::from_bool(get_enable_mount_manager()); #endif // defined(_WIN32) } - if (name == "EncryptConfig.Path") { + if (name == fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_PATH)) { return utils::path::absolute(get_encrypt_config().path); } - if (name == "EncryptConfig.EncryptionToken") { + if (name == + fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_ENCRYPTION_TOKEN)) { return get_encrypt_config().encryption_token; } if (name == "EventLevel") { @@ -379,19 +380,19 @@ auto app_config::get_value_by_name(const std::string &name) const if (name == "HighFreqIntervalSeconds") { return std::to_string(get_high_frequency_interval_secs()); } - if (name == "HostConfig.AgentString") { + if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_AGENT_STRING)) { return get_host_config().agent_string; } - if (name == "HostConfig.ApiPassword") { + if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PASSWORD)) { return get_host_config().api_password; } - if (name == "HostConfig.ApiPort") { + if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PORT)) { return std::to_string(get_host_config().api_port); } - if (name == "HostConfig.HostNameOrIp") { + if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_HOST_NAME_OR_IP)) { return get_host_config().host_name_or_ip; } - if (name == "HostConfig.TimeoutMs") { + if (name == fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_TIMEOUT_MS)) { return std::to_string(get_host_config().timeout_ms); } if (name == "LowFreqIntervalSeconds") { @@ -415,22 +416,27 @@ auto app_config::get_value_by_name(const std::string &name) const if (name == "PreferredDownloadType") { return download_type_to_string(get_preferred_download_type()); } - if (name == "RemoteConfig.ApiPort") { + if (name == fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_API_PORT)) { return std::to_string(get_remote_config().api_port); } - if (name == "RemoteConfig.EncryptionToken") { + if (name == + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_ENCRYPTION_TOKEN)) { return get_remote_config().encryption_token; } - if (name == "RemoteConfig.HostNameOrIp") { + if (name == + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_HOST_NAME_OR_IP)) { return get_remote_config().host_name_or_ip; } - if (name == "RemoteConfig.MaxConnections") { + if (name == + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_MAX_CONNECTIONS)) { return std::to_string(get_remote_config().max_connections); } - if (name == "RemoteConfig.ReceiveTimeoutMs") { + if (name == + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_RECV_TIMEOUT_MS)) { return std::to_string(get_remote_config().recv_timeout_ms); } - if (name == "RemoteConfig.SendTimeoutMs") { + 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") { @@ -451,37 +457,37 @@ auto app_config::get_value_by_name(const std::string &name) const if (name == "RingBufferFileSize") { return std::to_string(get_ring_buffer_file_size()); } - if (name == "S3Config.AccessKey") { + if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ACCESS_KEY)) { return get_s3_config().access_key; } - if (name == "S3Config.Bucket") { + if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_BUCKET)) { return get_s3_config().bucket; } - if (name == "S3Config.EncryptionToken") { + if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ENCRYPTION_TOKEN)) { return get_s3_config().encryption_token; } - if (name == "S3Config.Region") { + if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_REGION)) { return get_s3_config().region; } - if (name == "S3Config.SecretKey") { + if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_SECRET_KEY)) { return get_s3_config().secret_key; } - if (name == "S3Config.URL") { + if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_URL)) { return get_s3_config().url; } - if (name == "S3Config.UsePathStyle") { + if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_USE_PATH_STYLE)) { return utils::string::from_bool(get_s3_config().use_path_style); } - if (name == "S3Config.UseRegionInURL") { + 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 == "S3Config.TimeoutMs") { + if (name == fmt::format("{}.{}", JSON_S3_CONFIG, JSON_TIMEOUT_MS)) { return std::to_string(get_s3_config().timeout_ms); } - if (name == "SiaConfig.Bucket") { + if (name == fmt::format("{}.{}", JSON_SIA_CONFIG, JSON_BUCKET)) { return get_sia_config().bucket; } - if (name == "TaskWaitMillis") { + if (name == JSON_TASK_WAIT_MS) { return std::to_string(get_task_wait_ms()); } } catch (const std::exception &e) { @@ -509,9 +515,9 @@ auto app_config::load() -> bool { if (ret) { auto json_document = json::parse(json_text); - get_value(json_document, "ApiAuth", api_auth_, ret); - get_value(json_document, "ApiPort", api_port_, ret); - get_value(json_document, "ApiUser", api_user_, ret); + 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); @@ -526,8 +532,8 @@ auto app_config::load() -> bool { get_value(json_document, "EnableDriveEvents", enable_drive_events_, ret); - if (json_document.find("EncryptConfig") != json_document.end()) { - json_document.at("EncryptConfig") + if (json_document.find(JSON_ENCRYPT_CONFIG) != json_document.end()) { + json_document.at(JSON_ENCRYPT_CONFIG) .get_to>(encrypt_config_); } else { ret = false; @@ -535,20 +541,22 @@ auto app_config::load() -> bool { get_value(json_document, "EventLevel", event_level_, ret); - if (json_document.find("HostConfig") != json_document.end()) { - json_document.at("HostConfig").get_to>(hc_); + 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("S3Config") != json_document.end()) { - json_document.at("S3Config").get_to>(s3_config_); + 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("SiaConfig") != json_document.end()) { - json_document.at("SiaConfig") + if (json_document.find(JSON_SIA_CONFIG) != json_document.end()) { + json_document.at(JSON_SIA_CONFIG) .get_to>(sia_config_); } else { ret = false; @@ -556,7 +564,7 @@ auto app_config::load() -> bool { get_value(json_document, "RingBufferFileSize", ring_buffer_file_size_, ret); - get_value(json_document, "TaskWaitMillis", task_wait_ms_, 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); @@ -577,15 +585,15 @@ auto app_config::load() -> bool { get_value(json_document, "PreferredDownloadType", preferred_download_type_, ret); get_value(json_document, "RetryReadCount", retry_read_count_, ret); - get_value(json_document, "RemoteConfig", remote_config_, 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, "ApiPort", remote_api_port_, ret); - get_value(remoteMount, "EncryptionToken", remote_encryption_token_, - ret); + get_value(remoteMount, JSON_API_PORT, remote_api_port_, ret); + get_value(remoteMount, JSON_ENCRYPTION_TOKEN, + remote_encryption_token_, ret); } else { ret = false; } @@ -651,7 +659,9 @@ void app_config::set_encrypt_config(encrypt_config cfg) { set_value(encrypt_config_, cfg); } -void app_config::set_host_config(host_config cfg) { set_value(hc_, cfg); } +void app_config::set_host_config(host_config cfg) { + set_value(host_config_, cfg); +} void app_config::set_remote_config(remote::remote_config cfg) { set_value(remote_config_, cfg); @@ -666,15 +676,15 @@ auto app_config::set_value_by_name(const std::string &name, REPERTORY_USES_FUNCTION_NAME(); try { - if (name == "ApiAuth") { + if (name == JSON_API_AUTH) { set_api_auth(value); return get_api_auth(); } - if (name == "ApiPort") { + if (name == JSON_API_PORT) { set_api_port(utils::string::to_uint16(value)); return std::to_string(get_api_port()); } - if (name == "ApiUser") { + if (name == JSON_API_USER) { set_api_user(value); return get_api_user(); } @@ -705,13 +715,14 @@ auto app_config::set_value_by_name(const std::string &name, return utils::string::from_bool(get_enable_mount_manager()); #endif // defined(_WIN32) } - if (name == "EncryptConfig.EncryptionToken") { + 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 == "EncryptConfig.Path") { + if (name == fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_PATH)) { auto cfg = get_encrypt_config(); cfg.path = value; set_encrypt_config(cfg); @@ -733,31 +744,31 @@ auto app_config::set_value_by_name(const std::string &name, set_high_frequency_interval_secs(utils::string::to_uint8(value)); return std::to_string(get_high_frequency_interval_secs()); } - if (name == "HostConfig.AgentString") { + 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 == "HostConfig.ApiPassword") { + 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 == "HostConfig.ApiPort") { + 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 == "HostConfig.HostNameOrIp") { + 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 == "HostConfig.TimeoutMs") { + 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); @@ -791,37 +802,42 @@ auto app_config::set_value_by_name(const std::string &name, set_preferred_download_type(download_type_from_string(value)); return download_type_to_string(get_preferred_download_type()); } - if (name == "RemoteConfig.ApiPort") { + 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 == "RemoteConfig.EncryptionToken") { + 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 == "RemoteConfig.HostNameOrIp") { + 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 == "RemoteConfig.MaxConnections") { + 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 == "RemoteConfig.ReceiveTimeoutMs") { + 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 == "RemoteConfig.SendTimeoutMs") { + 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); @@ -851,67 +867,67 @@ auto app_config::set_value_by_name(const std::string &name, set_ring_buffer_file_size(utils::string::to_uint16(value)); return std::to_string(get_ring_buffer_file_size()); } - if (name == "S3Config.AccessKey") { + if (name == fmt::format("{}.{}", JSON_ACCESS_KEY)) { auto cfg = get_s3_config(); cfg.access_key = value; set_s3_config(cfg); return get_s3_config().access_key; } - if (name == "S3Config.Bucket") { + if (name == fmt::format("{}.{}", JSON_BUCKET)) { auto cfg = get_s3_config(); cfg.bucket = value; set_s3_config(cfg); return get_s3_config().bucket; } - if (name == "S3Config.EncryptionToken") { + if (name == fmt::format("{}.{}", JSON_ENCRYPTION_TOKEN)) { auto cfg = get_s3_config(); cfg.encryption_token = value; set_s3_config(cfg); return get_s3_config().encryption_token; } - if (name == "S3Config.Region") { + if (name == fmt::format("{}.{}", JSON_REGION)) { auto cfg = get_s3_config(); cfg.region = value; set_s3_config(cfg); return get_s3_config().region; } - if (name == "S3Config.SecretKey") { + if (name == fmt::format("{}.{}", JSON_SECRET_KEY)) { auto cfg = get_s3_config(); cfg.secret_key = value; set_s3_config(cfg); return get_s3_config().secret_key; } - if (name == "S3Config.TimeoutMs") { + if (name == fmt::format("{}.{}", 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 == "S3Config.URL") { + if (name == fmt::format("{}.{}", JSON_URL)) { auto cfg = get_s3_config(); cfg.url = value; set_s3_config(cfg); return get_s3_config().url; } - if (name == "S3Config.UsePathStyle") { + if (name == fmt::format("{}.{}", 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 == "S3Config.UseRegionInURL") { + if (name == fmt::format("{}.{}", 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 == "SiaConfig.Bucket") { + 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 == "TaskWaitMillis") { + if (name == JSON_TASK_WAIT_MS) { set_task_wait_ms(utils::string::to_uint16(value)); return std::to_string(get_task_wait_ms()); } diff --git a/repertory/librepertory/src/utils/cli_utils.cpp b/repertory/librepertory/src/utils/cli_utils.cpp index 8538bf30..e3e3bc00 100644 --- a/repertory/librepertory/src/utils/cli_utils.cpp +++ b/repertory/librepertory/src/utils/cli_utils.cpp @@ -45,15 +45,15 @@ void get_api_authentication_data(std::string &user, std::string &password, if (success) { if (user.empty() && password.empty()) { - password = data["ApiAuth"].get(); - user = data["ApiUser"].get(); + password = data[JSON_API_AUTH].get(); + user = data[JSON_API_USER].get(); } - port = data["ApiPort"].get(); + port = data[JSON_API_PORT].get(); } } -[[nodiscard]] auto -get_provider_type_from_args(std::vector args) -> provider_type { +[[nodiscard]] auto get_provider_type_from_args(std::vector args) + -> provider_type { if (has_option(args, options::s3_option)) { return provider_type::s3; } @@ -67,8 +67,8 @@ get_provider_type_from_args(std::vector args) -> provider_type { return provider_type::sia; } -auto has_option(std::vector args, - const std::string &option_name) -> bool { +auto has_option(std::vector args, const std::string &option_name) + -> bool { return std::find_if(args.begin(), args.end(), [&option_name](const auto &value) -> bool { return option_name == value; @@ -80,8 +80,8 @@ auto has_option(std::vector args, const option &opt) -> bool { } auto parse_option(std::vector args, - const std::string &option_name, - std::uint8_t count) -> std::vector { + const std::string &option_name, std::uint8_t count) + -> std::vector { std::vector ret; auto found{false}; for (std::size_t i = 0U; not found && (i < args.size()); i++) { @@ -119,9 +119,10 @@ auto parse_string_option(std::vector args, const option &opt, return ret; } -auto parse_drive_options( - std::vector args, [[maybe_unused]] provider_type &prov, - [[maybe_unused]] std::string &data_directory) -> std::vector { +auto parse_drive_options(std::vector args, + [[maybe_unused]] provider_type &prov, + [[maybe_unused]] std::string &data_directory) + -> std::vector { // Strip out options from command line const auto &option_list = options::option_list; std::vector drive_args; diff --git a/repertory/repertory_test/src/config_test.cpp b/repertory/repertory_test/src/config_test.cpp index 4b237676..a61e85c2 100644 --- a/repertory/repertory_test/src/config_test.cpp +++ b/repertory/repertory_test/src/config_test.cpp @@ -55,140 +55,6 @@ public: } }; -const auto DEFAULT_SIA_CONFIG = "{\n" - " \"ApiAuth\": \"\",\n" - " \"ApiPort\": 10000,\n" - " \"ApiUser\": \"repertory\",\n" - " \"ChunkDownloaderTimeoutSeconds\": 30,\n" - " \"DatabaseType\": \"rocksdb\",\n" - " \"EnableChunkDownloaderTimeout\": true,\n" - " \"EnableCommDurationEvents\": false,\n" - " \"EnableDriveEvents\": false,\n" -#if defined(_WIN32) - " \"EnableMountManager\": false,\n" -#endif - " \"EventLevel\": \"info\",\n" - " \"EvictionDelayMinutes\": 10,\n" - " \"EvictionUsesAccessedTime\": false,\n" - " \"HighFreqIntervalSeconds\": 30,\n" - " \"HostConfig\": {\n" - " \"AgentString\": \"Sia-Agent\",\n" - " \"ApiPassword\": \"\",\n" - " \"ApiPort\": 9980,\n" - " \"HostNameOrIp\": \"localhost\",\n" - " \"TimeoutMs\": 60000\n" - " },\n" - " \"LowFreqIntervalSeconds\": 3600,\n" - " \"MaxCacheSizeBytes\": 21474836480,\n" - " \"MaxUploadCount\": 5,\n" - " \"MedFreqIntervalSeconds\": 120,\n" - " \"OnlineCheckRetrySeconds\": 60,\n" - " \"OrphanedFileRetentionDays\": 15,\n" - " \"PreferredDownloadType\": \"fallback\",\n" - " \"RemoteMount\": {\n" - " \"ApiPort\": 20000,\n" - " \"ClientPoolSize\": 10,\n" - " \"Enable\": false,\n" - " \"EncryptionToken\": \"\"\n" - " },\n" - " \"RetryReadCount\": 6,\n" - " \"RingBufferFileSize\": 512,\n" - " \"SiaConfig\": {\n" - " \"Bucket\": \"\"\n" - " },\n" - " \"TaskWaitMillis\": 100,\n" - " \"Version\": " + - std::to_string(REPERTORY_CONFIG_VERSION) + - "\n" - "}"; - -const auto DEFAULT_S3_CONFIG = "{\n" - " \"ApiAuth\": \"\",\n" - " \"ApiPort\": 10100,\n" - " \"ApiUser\": \"repertory\",\n" - " \"ChunkDownloaderTimeoutSeconds\": 30,\n" - " \"DatabaseType\": \"rocksdb\",\n" - " \"EnableChunkDownloaderTimeout\": true,\n" - " \"EnableCommDurationEvents\": false,\n" - " \"EnableDriveEvents\": false,\n" -#if defined(_WIN32) - " \"EnableMountManager\": false,\n" -#endif - " \"EventLevel\": \"info\",\n" - " \"EvictionDelayMinutes\": 10,\n" - " \"EvictionUsesAccessedTime\": false,\n" - " \"HighFreqIntervalSeconds\": 30,\n" - " \"LowFreqIntervalSeconds\": 3600,\n" - " \"MaxCacheSizeBytes\": 21474836480,\n" - " \"MaxUploadCount\": 5,\n" - " \"MedFreqIntervalSeconds\": 120,\n" - " \"OnlineCheckRetrySeconds\": 60,\n" - " \"OrphanedFileRetentionDays\": 15,\n" - " \"PreferredDownloadType\": \"fallback\",\n" - " \"RemoteMount\": {\n" - " \"ApiPort\": 20100,\n" - " \"ClientPoolSize\": 10,\n" - " \"Enable\": false,\n" - " \"EncryptionToken\": \"\"\n" - " },\n" - " \"RetryReadCount\": 6,\n" - " \"RingBufferFileSize\": 512,\n" - " \"S3Config\": {\n" - " \"AccessKey\": \"\",\n" - " \"Bucket\": \"\",\n" - " \"EncryptionToken\": \"\",\n" - " \"Region\": \"any\",\n" - " \"SecretKey\": \"\",\n" - " \"TimeoutMs\": 60000,\n" - " \"URL\": \"\",\n" - " \"UsePathStyle\": false,\n" - " \"UseRegionInURL\": false\n" - " },\n" - " \"TaskWaitMillis\": 100,\n" - " \"Version\": " + - std::to_string(REPERTORY_CONFIG_VERSION) + - "\n" - "}"; - -TEST_F(config_test, sia_default_settings) { - const auto config_file = utils::path::combine(sia_directory, {"config.json"}); - - for (int i = 0; i < 2; i++) { - app_config config(provider_type::sia, sia_directory); - config.set_remote_encryption_token(""); - config.set_api_auth(""); - EXPECT_TRUE(config.set_value_by_name("HostConfig.ApiPassword", "").empty()); - json data; - EXPECT_TRUE(utils::file::read_json_file(config_file, data)); - EXPECT_STREQ(DEFAULT_SIA_CONFIG.c_str(), data.dump(2).c_str()); - EXPECT_TRUE( - utils::file::directory(utils::path::combine(sia_directory, {"cache"})) - .exists()); - EXPECT_TRUE( - utils::file::directory(utils::path::combine(sia_directory, {"logs"})) - .exists()); - } -} - -TEST_F(config_test, s3_default_settings) { - const auto config_file = utils::path::combine(s3_directory, {"config.json"}); - - for (int i = 0; i < 2; i++) { - app_config config(provider_type::s3, s3_directory); - config.set_remote_encryption_token(""); - config.set_api_auth(""); - json data; - EXPECT_TRUE(utils::file::read_json_file(config_file, data)); - EXPECT_STREQ(DEFAULT_S3_CONFIG.c_str(), data.dump(2).c_str()); - EXPECT_TRUE( - utils::file::directory(utils::path::combine(s3_directory, {"cache"})) - .exists()); - EXPECT_TRUE( - utils::file::directory(utils::path::combine(s3_directory, {"logs"})) - .exists()); - } -} - TEST_F(config_test, api_path) { std::string original_value; { diff --git a/repertory/repertory_test/src/json_serialize_test.cpp b/repertory/repertory_test/src/json_serialize_test.cpp index 88661876..ac051ee8 100644 --- a/repertory/repertory_test/src/json_serialize_test.cpp +++ b/repertory/repertory_test/src/json_serialize_test.cpp @@ -31,10 +31,11 @@ TEST(json_serialize, can_handle_directory_item) { }; json data(cfg); - EXPECT_STREQ("api", data.at("ApiPath").get().c_str()); - EXPECT_STREQ("parent", data.at("ApiParent").get().c_str()); - EXPECT_TRUE(data.at("Directory").get()); - EXPECT_STREQ("true", data.at("meta").at(META_DIRECTORY).get()); + 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()); { @@ -55,8 +56,9 @@ TEST(json_serialize, can_handle_encrypt_config) { }; json data(cfg); - EXPECT_STREQ("token", data.at("EncryptionToken").get().c_str()); - EXPECT_STREQ("path", data.at("Path").get().c_str()); + EXPECT_STREQ("token", + data.at(JSON_ENCRYPTION_TOKEN).get().c_str()); + EXPECT_STREQ("path", data.at(JSON_PATH).get().c_str()); { auto cfg2 = data.get(); @@ -71,14 +73,15 @@ TEST(json_serialize, can_handle_host_config) { }; json data(cfg); - EXPECT_STREQ("agent", data.at("AgentString").get().c_str()); - EXPECT_STREQ("pwd", data.at("ApiPassword").get().c_str()); - EXPECT_STREQ("user", data.at("ApiUser").get().c_str()); - EXPECT_EQ(1024U, data.at("ApiPort").get()); - EXPECT_STREQ("host", data.at("HostNameOrIp").get().c_str()); - EXPECT_STREQ("path", data.at("Path").get().c_str()); - EXPECT_STREQ("http", data.at("Protocol").get().c_str()); - EXPECT_EQ(11U, data.at("TimeoutMs").get()); + EXPECT_STREQ("agent", data.at(JSON_AGENT_STRING).get().c_str()); + EXPECT_STREQ("pwd", data.at(JSON_API_PASSWORD).get().c_str()); + EXPECT_STREQ("user", data.at(JSON_API_USER).get().c_str()); + EXPECT_EQ(1024U, data.at(JSON_API_PORT).get()); + EXPECT_STREQ("host", + data.at(JSON_HOST_NAME_OR_IP).get().c_str()); + EXPECT_STREQ("path", data.at(JSON_PATH).get().c_str()); + EXPECT_STREQ("http", data.at(JSON_PROTOCOL).get().c_str()); + EXPECT_EQ(11U, data.at(JSON_TIMEOUT_MS).get()); { auto cfg2 = data.get(); @@ -99,12 +102,14 @@ TEST(json_serialize, can_handle_remote_config) { }; json data(cfg); - EXPECT_EQ(1024U, data.at("ApiPort").get()); - EXPECT_STREQ("token", data.at("EncryptionToken").get().c_str()); - EXPECT_STREQ("host", data.at("HostNameOrIp").get().c_str()); - EXPECT_EQ(11U, data.at("MaxConnections").get()); - EXPECT_EQ(20U, data.at("ReceiveTimeoutMs").get()); - EXPECT_EQ(21U, data.at("SendTimeoutMs").get()); + EXPECT_EQ(1024U, data.at(JSON_API_PORT).get()); + EXPECT_STREQ("token", + data.at(JSON_ENCRYPTION_TOKEN).get().c_str()); + EXPECT_STREQ("host", + data.at(JSON_HOST_NAME_OR_IP).get().c_str()); + EXPECT_EQ(11U, data.at(JSON_MAX_CONNECTIONS).get()); + EXPECT_EQ(20U, data.at(JSON_RECV_TIMEOUT_MS).get()); + EXPECT_EQ(21U, data.at(JSON_SEND_TIMEOUT_MS).get()); { auto cfg2 = data.get(); @@ -123,15 +128,16 @@ TEST(json_serialize, can_handle_s3_config) { }; json data(cfg); - EXPECT_STREQ("access", data.at("AccessKey").get().c_str()); - EXPECT_STREQ("bucket", data.at("Bucket").get().c_str()); - EXPECT_STREQ("token", data.at("EncryptionToken").get().c_str()); - EXPECT_STREQ("region", data.at("Region").get().c_str()); - EXPECT_STREQ("secret", data.at("SecretKey").get().c_str()); - EXPECT_EQ(31U, data.at("TimeoutMs").get()); - EXPECT_STREQ("url", data.at("URL").get().c_str()); - EXPECT_TRUE(data.at("UsePathStyle").get()); - EXPECT_FALSE(data.at("UseRegionInURL").get()); + EXPECT_STREQ("access", data.at(JSON_ACCESS_KEY).get().c_str()); + EXPECT_STREQ("bucket", data.at(JSON_BUCKET).get().c_str()); + EXPECT_STREQ("token", + data.at(JSON_ENCRYPTION_TOKEN).get().c_str()); + EXPECT_STREQ("region", data.at(JSON_REGION).get().c_str()); + EXPECT_STREQ("secret", data.at(JSON_SECRET_KEY).get().c_str()); + EXPECT_EQ(31U, data.at(JSON_TIMEOUT_MS).get()); + EXPECT_STREQ("url", data.at(JSON_URL).get().c_str()); + EXPECT_TRUE(data.at(JSON_USE_PATH_STYLE).get()); + EXPECT_FALSE(data.at(JSON_USE_REGION_IN_URL).get()); { auto cfg2 = data.get(); @@ -153,7 +159,7 @@ TEST(json_serialize, can_handle_sia_config) { }; json data(cfg); - EXPECT_STREQ("bucket", data.at("Bucket").get().c_str()); + EXPECT_STREQ("bucket", data.at(JSON_BUCKET).get().c_str()); { auto cfg2 = data.get();