This commit is contained in:
Scott E. Graves 2024-12-20 13:54:36 -06:00
parent edb57903bc
commit 4fd1e7507a
2 changed files with 47 additions and 45 deletions

View File

@ -108,7 +108,7 @@ private:
private: private:
template <typename dest> template <typename dest>
auto get_value(const json &data, const std::string &name, dest &dst, auto get_value(const json &data, const std::string &name, dest &dst,
bool &success) -> bool; bool &found) -> bool;
[[nodiscard]] auto load() -> bool; [[nodiscard]] auto load() -> bool;

View File

@ -824,6 +824,9 @@ auto app_config::get_json() const -> json {
ret.erase(JSON_REMOTE_CONFIG); ret.erase(JSON_REMOTE_CONFIG);
ret.erase(JSON_S3_CONFIG); ret.erase(JSON_S3_CONFIG);
} break; } break;
default:
throw std::runtime_error(
fmt::format("unsupported provider type|{}", get_provider_name(prov_)));
} }
return ret; return ret;
@ -863,25 +866,24 @@ auto app_config::get_provider_name(const provider_type &prov) -> std::string {
template <typename dest> template <typename dest>
auto app_config::get_value(const json &data, const std::string &name, dest &dst, auto app_config::get_value(const json &data, const std::string &name, dest &dst,
bool &success) -> bool { bool &found) -> bool {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto ret{false};
try { try {
if (data.find(name) != data.end()) { if (data.find(name) == data.end()) {
data.at(name).get_to(dst); found = false;
ret = true; return ret;
} else {
success = false;
} }
data.at(name).get_to(dst);
return true;
} catch (const std::exception &ex) { } catch (const std::exception &ex) {
utils::error::raise_error(function_name, ex, utils::error::raise_error(function_name, ex,
fmt::format("failed to get value|name|{}", name)); fmt::format("failed to get value|name|{}", name));
success = false;
ret = false;
} }
return ret; found = false;
return false;
} }
auto app_config::get_value_by_name(const std::string &name) const auto app_config::get_value_by_name(const std::string &name) const
@ -927,82 +929,82 @@ auto app_config::load() -> bool {
return false; return false;
} }
auto ret{false}; auto found{true};
auto json_document = json::parse(json_text); auto json_document = json::parse(json_text);
get_value(json_document, JSON_API_AUTH, api_auth_, ret); get_value(json_document, JSON_API_AUTH, api_auth_, found);
get_value(json_document, JSON_API_PORT, api_port_, ret); get_value(json_document, JSON_API_PORT, api_port_, found);
get_value(json_document, JSON_API_USER, api_user_, ret); get_value(json_document, JSON_API_USER, api_user_, found);
get_value(json_document, JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS, get_value(json_document, JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS,
download_timeout_secs_, ret); download_timeout_secs_, found);
get_value(json_document, JSON_DATABASE_TYPE, db_type_, ret); get_value(json_document, JSON_DATABASE_TYPE, db_type_, found);
get_value(json_document, JSON_EVICTION_DELAY_MINS, eviction_delay_mins_, get_value(json_document, JSON_EVICTION_DELAY_MINS, eviction_delay_mins_,
ret); found);
get_value(json_document, JSON_EVICTION_USE_ACCESS_TIME, get_value(json_document, JSON_EVICTION_USE_ACCESS_TIME,
eviction_uses_accessed_time_, ret); eviction_uses_accessed_time_, found);
get_value(json_document, JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT, get_value(json_document, JSON_ENABLE_CHUNK_DOWNLOADER_TIMEOUT,
enable_chunk_downloader_timeout_, ret); enable_chunk_downloader_timeout_, found);
get_value(json_document, JSON_ENABLE_COMM_DURATION_EVENTS, get_value(json_document, JSON_ENABLE_COMM_DURATION_EVENTS,
enable_comm_duration_events_, ret); enable_comm_duration_events_, found);
get_value(json_document, JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_, get_value(json_document, JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_,
ret); found);
if (json_document.find(JSON_ENCRYPT_CONFIG) != json_document.end()) { if (json_document.find(JSON_ENCRYPT_CONFIG) != json_document.end()) {
json_document.at(JSON_ENCRYPT_CONFIG) json_document.at(JSON_ENCRYPT_CONFIG)
.get_to<atomic<encrypt_config>>(encrypt_config_); .get_to<atomic<encrypt_config>>(encrypt_config_);
} else { } else {
ret = false; found = false;
} }
get_value(json_document, JSON_EVENT_LEVEL, event_level_, ret); get_value(json_document, JSON_EVENT_LEVEL, event_level_, found);
if (json_document.find(JSON_HOST_CONFIG) != json_document.end()) { if (json_document.find(JSON_HOST_CONFIG) != json_document.end()) {
json_document.at(JSON_HOST_CONFIG) json_document.at(JSON_HOST_CONFIG)
.get_to<atomic<host_config>>(host_config_); .get_to<atomic<host_config>>(host_config_);
} else { } else {
ret = false; found = false;
} }
if (json_document.find(JSON_S3_CONFIG) != json_document.end()) { if (json_document.find(JSON_S3_CONFIG) != json_document.end()) {
json_document.at(JSON_S3_CONFIG).get_to<atomic<s3_config>>(s3_config_); json_document.at(JSON_S3_CONFIG).get_to<atomic<s3_config>>(s3_config_);
} else { } else {
ret = false; found = false;
} }
if (json_document.find(JSON_SIA_CONFIG) != json_document.end()) { if (json_document.find(JSON_SIA_CONFIG) != json_document.end()) {
json_document.at(JSON_SIA_CONFIG).get_to<atomic<sia_config>>(sia_config_); json_document.at(JSON_SIA_CONFIG).get_to<atomic<sia_config>>(sia_config_);
} else { } else {
ret = false; found = false;
} }
get_value(json_document, JSON_RING_BUFFER_FILE_SIZE, ring_buffer_file_size_, get_value(json_document, JSON_RING_BUFFER_FILE_SIZE, ring_buffer_file_size_,
ret); found);
get_value(json_document, JSON_TASK_WAIT_MS, task_wait_ms_, ret); get_value(json_document, JSON_TASK_WAIT_MS, task_wait_ms_, found);
#if defined(_WIN32) #if defined(_WIN32)
get_value(json_document, JSON_ENABLE_MOUNT_MANAGER, enable_mount_manager_, get_value(json_document, JSON_ENABLE_MOUNT_MANAGER, enable_mount_manager_,
ret); found);
#endif // defined(_WIN32) #endif // defined(_WIN32)
get_value(json_document, JSON_MAX_CACHE_SIZE_BYTES, max_cache_size_bytes_, get_value(json_document, JSON_MAX_CACHE_SIZE_BYTES, max_cache_size_bytes_,
ret); found);
get_value(json_document, JSON_MAX_UPLOAD_COUNT, max_upload_count_, ret); get_value(json_document, JSON_MAX_UPLOAD_COUNT, max_upload_count_, found);
get_value(json_document, JSON_ONLINE_CHECK_RETRY_SECS, get_value(json_document, JSON_ONLINE_CHECK_RETRY_SECS,
online_check_retry_secs_, ret); online_check_retry_secs_, found);
get_value(json_document, JSON_HIGH_FREQ_INTERVAL_SECS, get_value(json_document, JSON_HIGH_FREQ_INTERVAL_SECS,
high_freq_interval_secs_, ret); high_freq_interval_secs_, found);
get_value(json_document, JSON_LOW_FREQ_INTERVAL_SECS, get_value(json_document, JSON_LOW_FREQ_INTERVAL_SECS,
low_freq_interval_secs_, ret); low_freq_interval_secs_, found);
get_value(json_document, JSON_MED_FREQ_INTERVAL_SECS, get_value(json_document, JSON_MED_FREQ_INTERVAL_SECS,
med_freq_interval_secs_, ret); med_freq_interval_secs_, found);
get_value(json_document, JSON_ORPHANED_FILE_RETENTION_DAYS, get_value(json_document, JSON_ORPHANED_FILE_RETENTION_DAYS,
orphaned_file_retention_days_, ret); orphaned_file_retention_days_, found);
get_value(json_document, JSON_PREFERRED_DOWNLOAD_TYPE, get_value(json_document, JSON_PREFERRED_DOWNLOAD_TYPE,
preferred_download_type_, ret); preferred_download_type_, found);
get_value(json_document, JSON_RETRY_READ_COUNT, retry_read_count_, ret); get_value(json_document, JSON_RETRY_READ_COUNT, retry_read_count_, found);
get_value(json_document, JSON_REMOTE_CONFIG, remote_config_, ret); get_value(json_document, JSON_REMOTE_CONFIG, remote_config_, found);
get_value(json_document, JSON_REMOTE_MOUNT, remote_mount_, ret); get_value(json_document, JSON_REMOTE_MOUNT, remote_mount_, found);
std::uint64_t version{}; std::uint64_t version{};
get_value(json_document, JSON_VERSION, version, ret); get_value(json_document, JSON_VERSION, version, found);
// Handle configuration defaults for new config versions // Handle configuration defaults for new config versions
if (version != REPERTORY_CONFIG_VERSION) { if (version != REPERTORY_CONFIG_VERSION) {
@ -1011,11 +1013,11 @@ auto app_config::load() -> bool {
} }
version_ = version; version_ = version;
ret = false; found = false;
} }
config_changed_ = not ret; config_changed_ = not found;
return ret; return found;
} catch (const std::exception &ex) { } catch (const std::exception &ex) {
utils::error::raise_error( utils::error::raise_error(
function_name, ex, function_name, ex,