From de323cbecb24bb4393db7271c5870ee6a8f7e8eb Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Thu, 10 Oct 2024 16:02:39 +0100 Subject: [PATCH] re-add well-known table, while still allowing individual values to be set with env vars without double underscores --- docs/configuration.md | 5 ++--- docs/delegation.md | 12 ++++++------ src/config/mod.rs | 4 +--- src/main.rs | 18 +++++++++++++++++- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index b2b4f3a4..9687ead1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -6,7 +6,7 @@ > **Note:** If you update the configuration file, you must restart Conduit for the changes to take effect -> **Note:** You can also configure Conduit by using `CONDUIT_{field_name}` environment variables. To set values inside a table, use `CONDUIT_{table_name}__{field_name}`. Example: `CONDUIT_SERVER_NAME="example.org"` +> **Note:** You can also configure Conduit by using `CONDUIT_{field_name}` environment variables. To set values inside a table, use `CONDUIT_{table_name}_{field_name}`. Example: `CONDUIT_WELL_KNOWN_CLIENT="https://matrix.example.org"` Conduit's configuration file is divided into the following sections: @@ -58,8 +58,7 @@ The `global` section contains the following fields: | `turn_secret` | `string` | The TURN secret | `""` | | `turn_ttl` | `integer` | The TURN TTL in seconds | `86400` | | `emergency_password` | `string` | Set a password to login as the `conduit` user in case of emergency | N/A | -| `well_known_client` | `string` | Used for [delegation](delegation.md) | See [delegation](delegation.md) | -| `well_known_server` | `string` | Used for [delegation](delegation.md) | See [delegation](delegation.md) | +| `well_known` | `table` | Used for [delegation](delegation.md) | See [delegation](delegation.md) | ### TLS diff --git a/docs/delegation.md b/docs/delegation.md index 28d962f7..c8e5391c 100644 --- a/docs/delegation.md +++ b/docs/delegation.md @@ -16,18 +16,18 @@ are connected to the server running Conduit using something like a VPN. > **Note**: this will automatically allow you to use [sliding sync][0] without any extra configuration -To configure it, use the following options: +To configure it, use the following options in the `global.well_known` table: | Field | Type | Description | Default | | --- | --- | --- | --- | -| `well_known_client` | `String` | The URL that clients should use to connect to Conduit | `https://` | -| `well_known_server` | `String` | The hostname and port servers should use to connect to Conduit | `:443` | +| `client` | `String` | The URL that clients should use to connect to Conduit | `https://` | +| `server` | `String` | The hostname and port servers should use to connect to Conduit | `:443` | ### Example ```toml -[global] -well_known_client = "https://matrix.example.org" -well_known_server = "matrix.example.org:443" +[global.well_known] +client = "https://matrix.example.org" +server = "matrix.example.org:443" ``` ## Manual diff --git a/src/config/mod.rs b/src/config/mod.rs index 7cac2ed8..378ab929 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -59,7 +59,7 @@ pub struct Config { pub allow_unstable_room_versions: bool, #[serde(default = "default_default_room_version")] pub default_room_version: RoomVersionId, - #[serde(default, flatten)] + #[serde(default)] pub well_known: WellKnownConfig, #[serde(default = "false_fn")] pub allow_jaeger: bool, @@ -97,9 +97,7 @@ pub struct TlsConfig { #[derive(Clone, Debug, Deserialize, Default)] pub struct WellKnownConfig { - #[serde(rename = "well_known_client")] pub client: Option, - #[serde(rename = "well_known_server")] pub server: Option, } diff --git a/src/main.rs b/src/main.rs index c765401d..9a65fe5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerH use conduit::api::{client_server, server_server}; use figment::{ providers::{Env, Format, Toml}, + value::Uncased, Figment, }; use http::{ @@ -44,6 +45,8 @@ use tikv_jemallocator::Jemalloc; #[global_allocator] static GLOBAL: Jemalloc = Jemalloc; +static SUB_TABLES: [&str; 2] = ["well_known", "tls"]; // Not doing `proxy` cause setting that with env vars would be a pain + #[tokio::main] async fn main() { clap::parse(); @@ -57,7 +60,20 @@ async fn main() { )) .nested(), ) - .merge(Env::prefixed("CONDUIT_").global().split("__")); + .merge(Env::prefixed("CONDUIT_").global().map(|k| { + let mut key: Uncased = k.into(); + + for table in SUB_TABLES { + if k.starts_with(&(table.to_owned() + "_")) { + key = Uncased::from( + table.to_owned() + "." + k[table.len() + 1..k.len()].as_str(), + ); + break; + } + } + + key + })); let config = match raw_config.extract::() { Ok(s) => s,