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:
template <typename dest>
auto get_value(const json &data, const std::string &name, dest &dst,
bool &success) -> bool;
bool &found) -> 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_S3_CONFIG);
} break;
default:
throw std::runtime_error(
fmt::format("unsupported provider type|{}", get_provider_name(prov_)));
}
return ret;
@ -863,25 +866,24 @@ auto app_config::get_provider_name(const provider_type &prov) -> std::string {
template <typename dest>
auto app_config::get_value(const json &data, const std::string &name, dest &dst,
bool &success) -> bool {
bool &found) -> 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;
if (data.find(name) == data.end()) {
found = false;
return ret;
}
data.at(name).get_to(dst);
return true;
} 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;
found = false;
return false;
}
auto app_config::get_value_by_name(const std::string &name) const
@ -927,82 +929,82 @@ auto app_config::load() -> bool {
return false;
}
auto ret{false};
auto found{true};
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_API_AUTH, api_auth_, found);
get_value(json_document, JSON_API_PORT, api_port_, found);
get_value(json_document, JSON_API_USER, api_user_, found);
get_value(json_document, JSON_BACKGROUND_DOWNLOAD_TIMEOUT_SECS,
download_timeout_secs_, ret);
get_value(json_document, JSON_DATABASE_TYPE, db_type_, ret);
download_timeout_secs_, found);
get_value(json_document, JSON_DATABASE_TYPE, db_type_, found);
get_value(json_document, JSON_EVICTION_DELAY_MINS, eviction_delay_mins_,
ret);
found);
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,
enable_chunk_downloader_timeout_, ret);
enable_chunk_downloader_timeout_, found);
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_,
ret);
found);
if (json_document.find(JSON_ENCRYPT_CONFIG) != json_document.end()) {
json_document.at(JSON_ENCRYPT_CONFIG)
.get_to<atomic<encrypt_config>>(encrypt_config_);
} 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()) {
json_document.at(JSON_HOST_CONFIG)
.get_to<atomic<host_config>>(host_config_);
} else {
ret = false;
found = false;
}
if (json_document.find(JSON_S3_CONFIG) != json_document.end()) {
json_document.at(JSON_S3_CONFIG).get_to<atomic<s3_config>>(s3_config_);
} else {
ret = false;
found = false;
}
if (json_document.find(JSON_SIA_CONFIG) != json_document.end()) {
json_document.at(JSON_SIA_CONFIG).get_to<atomic<sia_config>>(sia_config_);
} else {
ret = false;
found = 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);
found);
get_value(json_document, JSON_TASK_WAIT_MS, task_wait_ms_, found);
#if defined(_WIN32)
get_value(json_document, JSON_ENABLE_MOUNT_MANAGER, enable_mount_manager_,
ret);
found);
#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);
found);
get_value(json_document, JSON_MAX_UPLOAD_COUNT, max_upload_count_, found);
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,
high_freq_interval_secs_, ret);
high_freq_interval_secs_, found);
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,
med_freq_interval_secs_, ret);
med_freq_interval_secs_, found);
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,
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);
preferred_download_type_, found);
get_value(json_document, JSON_RETRY_READ_COUNT, retry_read_count_, found);
get_value(json_document, JSON_REMOTE_CONFIG, remote_config_, found);
get_value(json_document, JSON_REMOTE_MOUNT, remote_mount_, found);
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
if (version != REPERTORY_CONFIG_VERSION) {
@ -1011,11 +1013,11 @@ auto app_config::load() -> bool {
}
version_ = version;
ret = false;
found = false;
}
config_changed_ = not ret;
return ret;
config_changed_ = not found;
return found;
} catch (const std::exception &ex) {
utils::error::raise_error(
function_name, ex,