1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-31 09:24:31 +03:00

Move the sub-configuration path to an associated constant

This commit is contained in:
Quentin Gliech
2024-03-20 15:57:24 +01:00
parent 1cf283337b
commit 48b6013c4f
15 changed files with 19 additions and 53 deletions

View File

@ -46,9 +46,7 @@ pub struct BrandingConfig {
#[async_trait]
impl ConfigurationSection for BrandingConfig {
fn path() -> &'static str {
"branding"
}
const PATH: Option<&'static str> = Some("branding");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -181,9 +181,7 @@ impl IntoIterator for ClientsConfig {
#[async_trait]
impl ConfigurationSection for ClientsConfig {
fn path() -> &'static str {
"clients"
}
const PATH: Option<&'static str> = Some("clients");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -146,9 +146,7 @@ pub struct DatabaseConfig {
#[async_trait]
impl ConfigurationSection for DatabaseConfig {
fn path() -> &'static str {
"database"
}
const PATH: Option<&'static str> = Some("database");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -128,9 +128,7 @@ impl Default for EmailConfig {
#[async_trait]
impl ConfigurationSection for EmailConfig {
fn path() -> &'static str {
"email"
}
const PATH: Option<&'static str> = Some("email");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -56,9 +56,7 @@ impl Default for ExperimentalConfig {
#[async_trait]
impl ConfigurationSection for ExperimentalConfig {
fn path() -> &'static str {
"experimental"
}
const PATH: Option<&'static str> = Some("experimental");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -394,9 +394,7 @@ impl Default for HttpConfig {
#[async_trait]
impl ConfigurationSection for HttpConfig {
fn path() -> &'static str {
"http"
}
const PATH: Option<&'static str> = Some("http");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -50,9 +50,7 @@ pub struct MatrixConfig {
#[async_trait]
impl ConfigurationSection for MatrixConfig {
fn path() -> &'static str {
"matrix"
}
const PATH: Option<&'static str> = Some("matrix");
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
where

View File

@ -116,10 +116,6 @@ pub struct RootConfig {
#[async_trait]
impl ConfigurationSection for RootConfig {
fn path() -> &'static str {
""
}
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
where
R: Rng + Send,
@ -195,10 +191,6 @@ pub struct AppConfig {
#[async_trait]
impl ConfigurationSection for AppConfig {
fn path() -> &'static str {
""
}
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
where
R: Rng + Send,
@ -251,10 +243,6 @@ pub struct SyncConfig {
#[async_trait]
impl ConfigurationSection for SyncConfig {
fn path() -> &'static str {
""
}
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
where
R: Rng + Send,

View File

@ -57,9 +57,7 @@ impl Default for PasswordsConfig {
#[async_trait]
impl ConfigurationSection for PasswordsConfig {
fn path() -> &'static str {
"passwords"
}
const PATH: Option<&'static str> = Some("passwords");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -106,9 +106,7 @@ impl Default for PolicyConfig {
#[async_trait]
impl ConfigurationSection for PolicyConfig {
fn path() -> &'static str {
"policy"
}
const PATH: Option<&'static str> = Some("policy");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -139,9 +139,7 @@ impl SecretsConfig {
#[async_trait]
impl ConfigurationSection for SecretsConfig {
fn path() -> &'static str {
"secrets"
}
const PATH: Option<&'static str> = Some("secrets");
#[tracing::instrument(skip_all)]
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>

View File

@ -145,9 +145,7 @@ pub struct TelemetryConfig {
#[async_trait]
impl ConfigurationSection for TelemetryConfig {
fn path() -> &'static str {
"telemetry"
}
const PATH: Option<&'static str> = Some("telemetry");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -96,9 +96,7 @@ impl Default for TemplatesConfig {
#[async_trait]
impl ConfigurationSection for TemplatesConfig {
fn path() -> &'static str {
"templates"
}
const PATH: Option<&'static str> = Some("templates");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -34,9 +34,7 @@ pub struct UpstreamOAuth2Config {
#[async_trait]
impl ConfigurationSection for UpstreamOAuth2Config {
fn path() -> &'static str {
"upstream_oauth2"
}
const PATH: Option<&'static str> = Some("upstream_oauth2");
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
where

View File

@ -22,7 +22,7 @@ use serde::{de::DeserializeOwned, Serialize};
/// of the config and generate the sample config.
pub trait ConfigurationSection: Sized + DeserializeOwned + Serialize {
/// Specify where this section should live relative to the root.
fn path() -> &'static str;
const PATH: Option<&'static str> = None;
/// Generate a sample configuration for this section.
async fn generate<R>(rng: R) -> anyhow::Result<Self>
@ -35,7 +35,11 @@ pub trait ConfigurationSection: Sized + DeserializeOwned + Serialize {
///
/// Returns an error if the configuration could not be loaded
fn extract(figment: &Figment) -> Result<Self, FigmentError> {
figment.extract_inner(Self::path())
if let Some(path) = Self::PATH {
figment.extract_inner(path)
} else {
figment.extract()
}
}
/// Generate config used in unit tests