This commit is contained in:
Jacob Lifshay 2024-04-08 18:25:32 -07:00
parent 8b76a51434
commit d6ebd3a4a6
Signed by: programmerjake
SSH key fingerprint: SHA256:B1iRVvUJkvd7upMIiMqn6OyxvD2SgJkAH3ZnUOj6z+c
14 changed files with 276 additions and 24 deletions

View file

@ -9,9 +9,17 @@ use openidconnect::{
ClientId, ClientSecret, IssuerUrl, RedirectUrl, Scope,
};
use serde::{Deserialize, Serialize};
use std::num::NonZeroU16;
pub fn default_db_thread_channel_capacity() -> NonZeroU16 {
NonZeroU16::new(10).unwrap()
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Config {
pub sqlite_db: String,
#[serde(default = "default_db_thread_channel_capacity")]
pub db_thread_channel_capacity: NonZeroU16,
pub oidc: IndexMap<String, OIDCProvider>,
}
@ -27,6 +35,7 @@ impl ValueParserFactory for Config {
}
impl Config {
#[allow(dead_code)]
pub const EXAMPLE: &'static str =
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/config.toml.sample"));
pub fn load_str(input: &str, path: impl ToString) -> eyre::Result<Config> {
@ -35,7 +44,7 @@ impl Config {
pub fn load(input: CachedInput) -> eyre::Result<Config> {
let s = std::str::from_utf8(input.get_data()).wrap_err_with(|| input.path().to_string())?;
toml::from_str(s).wrap_err_with(|| input.path().to_string())
Self::load_str(s, input.path())
}
pub async fn resolve(&mut self) -> eyre::Result<()> {