add cli override for any configuration item

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-25 02:59:54 +00:00
parent 4e975887cf
commit c423a83656
8 changed files with 68 additions and 14 deletions

View file

@ -86,6 +86,7 @@ tikv-jemalloc-sys.optional = true
tikv-jemalloc-sys.workspace = true
tokio.workspace = true
tokio-metrics.workspace = true
toml.workspace = true
tracing-core.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true

View file

@ -9,10 +9,8 @@ use either::{
Either,
Either::{Left, Right},
};
use figment::{
providers::{Env, Format, Toml},
Figment,
};
use figment::providers::{Env, Format, Toml};
pub use figment::{value::Value as FigmentValue, Figment};
use itertools::Itertools;
use regex::RegexSet;
use ruma::{
@ -408,8 +406,8 @@ const DEPRECATED_KEYS: &[&str; 9] = &[
];
impl Config {
/// Initialize config
pub fn new(path: &Option<PathBuf>) -> Result<Self> {
/// Pre-initialize config
pub fn load(path: &Option<PathBuf>) -> Result<Figment> {
let raw_config = if let Some(config_file_env) = Env::var("CONDUIT_CONFIG") {
Figment::new()
.merge(Toml::file(config_file_env).nested())
@ -431,13 +429,18 @@ impl Config {
.merge(Env::prefixed("CONDUWUIT_").global().split("__"))
};
Ok(raw_config)
}
/// Finalize config
pub fn new(raw_config: &Figment) -> Result<Self> {
let config = match raw_config.extract::<Self>() {
Err(e) => return Err!("There was a problem with your configuration file: {e}"),
Ok(config) => config,
};
// don't start if we're listening on both UNIX sockets and TCP at same time
check::is_dual_listening(&raw_config)?;
check::is_dual_listening(raw_config)?;
Ok(config)
}

View file

@ -57,6 +57,12 @@ pub enum Error {
HttpHeader(#[from] http::header::InvalidHeaderValue),
#[error("{0}")]
CargoToml(#[from] cargo_toml::Error),
#[error("{0}")]
FigmentError(#[from] figment::error::Error),
#[error("{0}")]
TomlSerError(#[from] toml::ser::Error),
#[error("{0}")]
TomlDeError(#[from] toml::de::Error),
// ruma
#[error("{0}")]

View file

@ -10,6 +10,7 @@ pub mod pdu;
pub mod server;
pub mod utils;
pub use ::toml;
pub use config::Config;
pub use error::Error;
pub use info::{rustc_flags_capture, version, version::version};