Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to confique 0.3 #1261

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 126 additions & 95 deletions backend/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
1 change: 1 addition & 0 deletions backend/src/auth/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
5 changes: 1 addition & 4 deletions backend/src/config/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl TryFrom<String> 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
Expand Down Expand Up @@ -130,9 +130,6 @@ impl ColorConfig {
);
}
}


Ok(())
}

/// Returns the CSS variables for light and dark themes, respectively.
Expand Down
15 changes: 4 additions & 11 deletions backend/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions backend/src/config/opencast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions backend/src/config/theme.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{path::PathBuf, fmt};

use crate::prelude::*;
use super::color::ColorConfig;


Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions backend/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
3 changes: 1 addition & 2 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading