From 510c0bbe51194fe979f77b32ff371fd4a5c0f46d Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Fri, 18 Oct 2024 16:37:42 +0200 Subject: [PATCH] Update to `confique` 0.3 --- backend/Cargo.lock | 66 +++++++++++++++++++++++++++------- backend/Cargo.toml | 2 +- backend/src/auth/config.rs | 1 + backend/src/config/color.rs | 5 +-- backend/src/config/mod.rs | 15 +++----- backend/src/config/opencast.rs | 1 + backend/src/config/theme.rs | 5 --- backend/src/db/mod.rs | 1 + backend/src/main.rs | 3 +- 9 files changed, 63 insertions(+), 36 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 0b0bd374d..922e248b3 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -461,9 +461,9 @@ dependencies = [ [[package]] name = "confique" -version = "0.2.5" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c37945ed2efccb10339a12eea282a5af9ebac77720d088723b2bbbdc44eca964" +checksum = "d011f79ecb68498e94453e133c67cc5c35ab847684c59fa58b9ce0698e272e7b" dependencies = [ "confique-macro", "serde", @@ -472,14 +472,14 @@ dependencies = [ [[package]] name = "confique-macro" -version = "0.0.9" +version = "0.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3821efdaaab3c5297054a90201cc3afa2061fc6ba2bc5d2fa558b850a7dabefe" +checksum = "df20583fae327154743356c4896906bda1aa9b7df30c5aed73a54cf27fede9de" dependencies = [ - "heck 0.3.3", + "heck 0.5.0", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.50", ] [[package]] @@ -1033,12 +1033,9 @@ checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] name = "heck" -version = "0.3.3" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "heck" @@ -2375,6 +2372,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + [[package]] name = "serde_yaml" version = "0.9.34+deprecated" @@ -2837,11 +2843,36 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.11" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap 2.2.3", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", ] [[package]] @@ -3368,6 +3399,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] + [[package]] name = "x509-certificate" version = "0.23.1" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 8a568ed6b..adab1409a 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -25,7 +25,7 @@ bunt = "0.2.7" bytes = "1" chrono = { version = "0.4", default-features = false, features = ["serde", "std"] } clap = { version = "4.2.2", features = ["derive", "string"] } -confique = { version = "0.2.0", default-features = false, features = ["toml"] } +confique = { version = "0.3", features = ["toml"] } cookie = "0.18.0" deadpool = { version = "0.10.0", default-features = false, features = ["managed", "rt_tokio_1"] } deadpool-postgres = { version = "0.12.1", default-features = false, features = ["rt_tokio_1"] } diff --git a/backend/src/auth/config.rs b/backend/src/auth/config.rs index b8aa0e613..81de638c7 100644 --- a/backend/src/auth/config.rs +++ b/backend/src/auth/config.rs @@ -11,6 +11,7 @@ use super::JwtConfig; /// Authentification and authorization #[derive(Debug, Clone, confique::Config)] +#[config(validate = Self::validate)] pub(crate) struct AuthConfig { /// How incoming HTTP requests are authenticated. See the documentation! #[config(default = "none")] diff --git a/backend/src/config/color.rs b/backend/src/config/color.rs index e0787e2b1..f8ea3cd50 100644 --- a/backend/src/config/color.rs +++ b/backend/src/config/color.rs @@ -82,7 +82,7 @@ impl TryFrom for Color { type Vars = Vec<(String, String)>; impl ColorConfig { - pub(crate) fn validate(&self) -> Result<()> { + pub(crate) fn lint(&self) { // Make sure the primary color is in a good range. // // Regarding the minimum of 35: We have two variations, with one being @@ -130,9 +130,6 @@ impl ColorConfig { ); } } - - - Ok(()) } /// Returns the CSS variables for light and dark themes, respectively. diff --git a/backend/src/config/mod.rs b/backend/src/config/mod.rs index f8bbd9d2e..4ecc56e94 100644 --- a/backend/src/config/mod.rs +++ b/backend/src/config/mod.rs @@ -128,22 +128,15 @@ impl Config { let mut config = Config::from_file(path) .context(format!("failed to read config file '{}'", path.display()))?; - config.validate().context("failed to validate configuration")?; config.fix_paths(path)?; Ok(config) } - /// Performs some validation of the configuration to find some - /// illegal or conflicting values. - pub(crate) fn validate(&self) -> Result<()> { - debug!("Validating configuration..."); - self.auth.validate()?; - self.opencast.validate()?; - self.db.validate()?; - self.theme.validate()?; - - Ok(()) + /// Checks the config for problematic things that deserve a warning, but + /// should not bring down Tobira. + pub(crate) fn lint(&self) { + self.theme.color.lint(); } /// Goes through all paths in the configuration and changes relative paths diff --git a/backend/src/config/opencast.rs b/backend/src/config/opencast.rs index 8e8ec3db2..d859ba817 100644 --- a/backend/src/config/opencast.rs +++ b/backend/src/config/opencast.rs @@ -10,6 +10,7 @@ use crate::{ #[derive(Debug, confique::Config)] +#[config(validate = Self::validate)] pub(crate) struct OpencastConfig { /// URL to Opencast. Currently used for all purposes (syncing, Studio, /// upload, ...) unless overwritten below. In the future, Tobira might use diff --git a/backend/src/config/theme.rs b/backend/src/config/theme.rs index 2cdf82090..456ee8cfe 100644 --- a/backend/src/config/theme.rs +++ b/backend/src/config/theme.rs @@ -1,6 +1,5 @@ use std::{path::PathBuf, fmt}; -use crate::prelude::*; use super::color::ColorConfig; @@ -87,10 +86,6 @@ pub(crate) struct FontConfig { } impl ThemeConfig { - pub(crate) fn validate(&self) -> Result<()> { - self.color.validate() - } - /// Returns a string containing CSS that sets lots of variables on the /// `:root` element. pub(crate) fn to_css(&self) -> String { diff --git a/backend/src/db/mod.rs b/backend/src/db/mod.rs index 792339917..b6fad9e4b 100644 --- a/backend/src/db/mod.rs +++ b/backend/src/db/mod.rs @@ -35,6 +35,7 @@ pub(crate) use self::{ #[derive(Debug, confique::Config, Clone)] +#[config(validate = Self::validate)] pub(crate) struct DbConfig { /// The username of the database user. #[config(default = "tobira")] diff --git a/backend/src/main.rs b/backend/src/main.rs index 7b4c0578d..9787b61d8 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -189,8 +189,7 @@ fn load_config_and_init_logger(shared: &args::Shared, args: &Args, cmd: &str) -> info!(source_file = ?path.display(), "Loaded config"); debug!(cmd, "Initialized logger"); - // Call validate again, as some of the checks will only print warnings. - config.validate()?; + config.lint(); Ok(config) }