torrust_tracker/bootstrap/
config.rs

1//! Initialize configuration from file or env var.
2//!
3//! All environment variables are prefixed with `TORRUST_TRACKER_`.
4
5use torrust_tracker_configuration::{Configuration, Info};
6
7pub const DEFAULT_PATH_CONFIG: &str = "./share/default/config/tracker.development.sqlite3.toml";
8
9/// It loads the application configuration from the environment.
10///
11/// There are two methods to inject the configuration:
12///
13/// 1. By using a config file: `tracker.toml`.
14/// 2. Environment variable: `TORRUST_TRACKER_CONFIG_TOML`. The variable contains the same contents as the `tracker.toml` file.
15///
16/// Environment variable has priority over the config file.
17///
18/// Refer to the [configuration documentation](https://docs.rs/torrust-tracker-configuration) for the configuration options.
19///
20/// # Panics
21///
22/// Will panic if it can't load the configuration from either
23/// `./tracker.toml` file or the env var `TORRUST_TRACKER_CONFIG_TOML`.
24#[must_use]
25pub fn initialize_configuration() -> Configuration {
26    let info = Info::new(DEFAULT_PATH_CONFIG.to_string()).expect("info to load configuration is not valid");
27    Configuration::load(&info).expect("error loading configuration from sources")
28}
29
30#[cfg(test)]
31mod tests {
32
33    #[test]
34    fn it_should_load_with_default_config() {
35        use crate::bootstrap::config::initialize_configuration;
36
37        drop(initialize_configuration());
38    }
39}