chore: update deps

This commit is contained in:
Aravinth Manivannan
2023-10-20 14:31:21 +05:30
parent 88fbc99a5e
commit 0e0637bfa4
3 changed files with 218 additions and 149 deletions

View File

@ -50,39 +50,35 @@ pub struct Settings {
#[cfg(not(tarpaulin_include))]
impl Settings {
pub fn new() -> Result<Self, ConfigError> {
let mut s = Config::new();
let mut s = Config::builder();
// setting default values
#[cfg(test)]
s.set_default("database.pool", 2.to_string())
.expect("Couldn't get the number of CPUs");
const CURRENT_DIR: &str = "./config/default.toml";
const ETC: &str = "/etc/libmedium/config.toml";
if let Ok(path) = env::var("LIBMEDIUM") {
s.merge(File::with_name(&path))?;
s = s.add_source(File::with_name(&path));
} else if Path::new(CURRENT_DIR).exists() {
// merging default config from file
s.merge(File::with_name(CURRENT_DIR))?;
s = s.add_source(File::with_name(CURRENT_DIR));
} else if Path::new(ETC).exists() {
s.merge(File::with_name(ETC))?;
s = s.add_source(File::with_name(ETC));
} else {
log::warn!("configuration file not found");
}
s.merge(Environment::with_prefix("PAGES").separator("__"))?;
s = s.add_source(Environment::with_prefix("PAGES").separator("__"));
check_url(&s);
match env::var("PORT") {
Ok(val) => {
s.set("server.port", val).unwrap();
s = s.set_override("server.port", val).unwrap();
}
Err(e) => warn!("couldn't interpret PORT: {}", e),
}
let mut settings: Settings = s.try_into()?;
let mut settings: Settings = s.build()?.try_deserialize::<Settings>()?;
settings.check_url();
if settings.cache.is_none() {
let tmp = env::temp_dir().join("libmedium_cache_path");
@ -105,13 +101,9 @@ impl Settings {
}
Ok(settings)
}
}
#[cfg(not(tarpaulin_include))]
fn check_url(s: &Config) {
let url = s
.get::<String>("source_code")
.expect("Couldn't access source_code");
Url::parse(&url).expect("Please enter a URL for source_code in settings");
#[cfg(not(tarpaulin_include))]
fn check_url(&self) {
Url::parse(&self.source_code).expect("Please enter a URL for source_code in settings");
}
}