mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-03-31 02:19:36 +03:00
warn on deprecated keys
This commit is contained in:
parent
3260ae01b8
commit
b89cffed34
3 changed files with 25 additions and 26 deletions
|
@ -26,9 +26,9 @@ use rocket::{
|
||||||
try_outcome, State,
|
try_outcome, State,
|
||||||
};
|
};
|
||||||
use ruma::{DeviceId, ServerName, UserId};
|
use ruma::{DeviceId, ServerName, UserId};
|
||||||
use serde::Deserialize;
|
use serde::{de::IgnoredAny, Deserialize};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::{BTreeMap, HashMap},
|
||||||
fs::{self, remove_dir_all},
|
fs::{self, remove_dir_all},
|
||||||
io::Write,
|
io::Write,
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
|
@ -42,8 +42,8 @@ use self::proxy::ProxyConfig;
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
server_name: Box<ServerName>,
|
server_name: Box<ServerName>,
|
||||||
database_path: String,
|
database_path: String,
|
||||||
cache_capacity: Option<u32>, // deprecated
|
#[serde(default = "default_db_cache_capacity")]
|
||||||
db_cache_capacity: Option<u32>,
|
db_cache_capacity: u32,
|
||||||
#[serde(default = "default_sqlite_read_pool_size")]
|
#[serde(default = "default_sqlite_read_pool_size")]
|
||||||
sqlite_read_pool_size: usize,
|
sqlite_read_pool_size: usize,
|
||||||
#[serde(default = "false_fn")]
|
#[serde(default = "false_fn")]
|
||||||
|
@ -71,28 +71,28 @@ pub struct Config {
|
||||||
trusted_servers: Vec<Box<ServerName>>,
|
trusted_servers: Vec<Box<ServerName>>,
|
||||||
#[serde(default = "default_log")]
|
#[serde(default = "default_log")]
|
||||||
pub log: String,
|
pub log: String,
|
||||||
|
|
||||||
|
#[serde(flatten)]
|
||||||
|
catchall: BTreeMap<String, IgnoredAny>,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! deprecate_with {
|
const DEPRECATED_KEYS: &[&str] = &["cache_capacity"];
|
||||||
($self:expr ; $from:ident -> $to:ident) => {
|
|
||||||
if let Some(v) = $self.$from {
|
|
||||||
let from = stringify!($from);
|
|
||||||
let to = stringify!($to);
|
|
||||||
log::warn!("{} is deprecated, use {} instead", from, to);
|
|
||||||
|
|
||||||
$self.$to.get_or_insert(v);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
($self:expr ; $from:ident -> $to:ident or $default:expr) => {
|
|
||||||
deprecate_with!($self ; $from -> $to);
|
|
||||||
$self.$to.get_or_insert_with($default);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn process_fallbacks(&mut self) {
|
pub fn warn_deprecated(&self) {
|
||||||
// TODO: have a proper way handle into above struct (maybe serde supports something like this?)
|
let mut was_deprecated = false;
|
||||||
deprecate_with!(self ; cache_capacity -> db_cache_capacity or default_db_cache_capacity);
|
for key in self
|
||||||
|
.catchall
|
||||||
|
.keys()
|
||||||
|
.filter(|key| DEPRECATED_KEYS.iter().any(|s| s == key))
|
||||||
|
{
|
||||||
|
log::warn!("Config parameter {} is deprecated", key);
|
||||||
|
was_deprecated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if was_deprecated {
|
||||||
|
log::warn!("Read conduit documentation and check your configuration if any new configuration parameters should be adjusted");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ impl DatabaseEngine for Engine {
|
||||||
let pool = Pool::new(
|
let pool = Pool::new(
|
||||||
Path::new(&config.database_path).join("conduit.db"),
|
Path::new(&config.database_path).join("conduit.db"),
|
||||||
config.sqlite_read_pool_size,
|
config.sqlite_read_pool_size,
|
||||||
config.db_cache_capacity.expect("fallbacks hasn't been called") / 1024, // bytes -> kb
|
config.db_cache_capacity / 1024, // bytes -> kb
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
pool.write_lock()
|
pool.write_lock()
|
||||||
|
|
|
@ -196,7 +196,7 @@ async fn main() {
|
||||||
|
|
||||||
std::env::set_var("RUST_LOG", "warn");
|
std::env::set_var("RUST_LOG", "warn");
|
||||||
|
|
||||||
let mut config = raw_config
|
let config = raw_config
|
||||||
.extract::<Config>()
|
.extract::<Config>()
|
||||||
.expect("It looks like your config is invalid. Please take a look at the error");
|
.expect("It looks like your config is invalid. Please take a look at the error");
|
||||||
|
|
||||||
|
@ -218,8 +218,7 @@ async fn main() {
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Required here to process fallbacks while logging is enabled, but before config is actually used for anything
|
config.warn_deprecated();
|
||||||
config.process_fallbacks();
|
|
||||||
|
|
||||||
let db = Database::load_or_create(config)
|
let db = Database::load_or_create(config)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in a new issue