You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-06 06:02:40 +03:00
Move the sub-configuration path to an associated constant
This commit is contained in:
@@ -46,9 +46,7 @@ pub struct BrandingConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for BrandingConfig {
|
impl ConfigurationSection for BrandingConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("branding");
|
||||||
"branding"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -181,9 +181,7 @@ impl IntoIterator for ClientsConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for ClientsConfig {
|
impl ConfigurationSection for ClientsConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("clients");
|
||||||
"clients"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -146,9 +146,7 @@ pub struct DatabaseConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for DatabaseConfig {
|
impl ConfigurationSection for DatabaseConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("database");
|
||||||
"database"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -128,9 +128,7 @@ impl Default for EmailConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for EmailConfig {
|
impl ConfigurationSection for EmailConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("email");
|
||||||
"email"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -56,9 +56,7 @@ impl Default for ExperimentalConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for ExperimentalConfig {
|
impl ConfigurationSection for ExperimentalConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("experimental");
|
||||||
"experimental"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -394,9 +394,7 @@ impl Default for HttpConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for HttpConfig {
|
impl ConfigurationSection for HttpConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("http");
|
||||||
"http"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -50,9 +50,7 @@ pub struct MatrixConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for MatrixConfig {
|
impl ConfigurationSection for MatrixConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("matrix");
|
||||||
"matrix"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -116,10 +116,6 @@ pub struct RootConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for RootConfig {
|
impl ConfigurationSection for RootConfig {
|
||||||
fn path() -> &'static str {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
R: Rng + Send,
|
R: Rng + Send,
|
||||||
@@ -195,10 +191,6 @@ pub struct AppConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for AppConfig {
|
impl ConfigurationSection for AppConfig {
|
||||||
fn path() -> &'static str {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
R: Rng + Send,
|
R: Rng + Send,
|
||||||
@@ -251,10 +243,6 @@ pub struct SyncConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for SyncConfig {
|
impl ConfigurationSection for SyncConfig {
|
||||||
fn path() -> &'static str {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
R: Rng + Send,
|
R: Rng + Send,
|
||||||
|
@@ -57,9 +57,7 @@ impl Default for PasswordsConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for PasswordsConfig {
|
impl ConfigurationSection for PasswordsConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("passwords");
|
||||||
"passwords"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -106,9 +106,7 @@ impl Default for PolicyConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for PolicyConfig {
|
impl ConfigurationSection for PolicyConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("policy");
|
||||||
"policy"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -139,9 +139,7 @@ impl SecretsConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for SecretsConfig {
|
impl ConfigurationSection for SecretsConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("secrets");
|
||||||
"secrets"
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
|
||||||
|
@@ -145,9 +145,7 @@ pub struct TelemetryConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for TelemetryConfig {
|
impl ConfigurationSection for TelemetryConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("telemetry");
|
||||||
"telemetry"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -96,9 +96,7 @@ impl Default for TemplatesConfig {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for TemplatesConfig {
|
impl ConfigurationSection for TemplatesConfig {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("templates");
|
||||||
"templates"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -34,9 +34,7 @@ pub struct UpstreamOAuth2Config {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ConfigurationSection for UpstreamOAuth2Config {
|
impl ConfigurationSection for UpstreamOAuth2Config {
|
||||||
fn path() -> &'static str {
|
const PATH: Option<&'static str> = Some("upstream_oauth2");
|
||||||
"upstream_oauth2"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
async fn generate<R>(_rng: R) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
|
@@ -22,7 +22,7 @@ use serde::{de::DeserializeOwned, Serialize};
|
|||||||
/// of the config and generate the sample config.
|
/// of the config and generate the sample config.
|
||||||
pub trait ConfigurationSection: Sized + DeserializeOwned + Serialize {
|
pub trait ConfigurationSection: Sized + DeserializeOwned + Serialize {
|
||||||
/// Specify where this section should live relative to the root.
|
/// 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.
|
/// Generate a sample configuration for this section.
|
||||||
async fn generate<R>(rng: R) -> anyhow::Result<Self>
|
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
|
/// Returns an error if the configuration could not be loaded
|
||||||
fn extract(figment: &Figment) -> Result<Self, FigmentError> {
|
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
|
/// Generate config used in unit tests
|
||||||
|
Reference in New Issue
Block a user