torrust-tracker
torrust-tracker copied to clipboard
Config Overhaul
- [x] #561
- [x] #563
- [x] #623
- [x] #644
- [x] dev: improve announce ip logic test: (c7b28deb09303783fb6cdff09f773450d179440b)
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 77.71%. Comparing base (
bf71687
) to head (a55c356
).
Additional details and impacted files
@@ Coverage Diff @@
## develop #557 +/- ##
========================================
Coverage 77.71% 77.71%
========================================
Files 158 158
Lines 8711 8711
========================================
Hits 6770 6770
Misses 1941 1941
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Relates to: https://github.com/torrust/torrust-tracker/issues/343
Hi @da2ce7 I think in the past we have discussed having two types of configuration structs:
- The DTO: the ones representing the information in the config files or in general the configuration injected into the app when it was started.
- The domain configuration. After receiving the configuration in most cases the application only fails when it starts using the wrong values. For example, if the configuration for one service is wrong you do not know it unless you start that service. For example, if you want to use TLS for the API service and you don't provide the certificates you would not realise the configuration was wrong until you enable that service.
In the Index I've recently introduced a validation for the configuration:
https://github.com/torrust/torrust-index/blob/develop/src/config.rs#L571-L601
I wanted the application to fail if you use an invalid tracker configuration. In this case, you can't not have a public UDP tracker. We don't support it.
I'm still using the same struct. For the time being, I've just added a validate function.
/// # Errors
///
/// Will return an error if the configuration is invalid.
pub async fn validate(&self) -> Result<(), ValidationError> {
self.validate_tracker_config().await
}
/// # Errors
///
/// Will return an error if the `tracker` configuration section is invalid.
pub async fn validate_tracker_config(&self) -> Result<(), ValidationError> {
let settings_lock = self.settings.read().await;
let tracker_mode = settings_lock.tracker.mode.clone();
let tracker_url = settings_lock.tracker.url.clone();
let tracker_url = match parse_url(&tracker_url) {
Ok(url) => url,
Err(err) => {
return Err(ValidationError::InvalidTrackerUrl {
source: Located(err).into(),
})
}
};
if tracker_mode.is_close() && (tracker_url.scheme() != "http" && tracker_url.scheme() != "https") {
return Err(ValidationError::UdpTrackersInPrivateModeNotSupported);
}
Ok(())
}
Relates to: https://github.com/torrust/torrust-tracker/pull/790
closed by #401