1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

Reorganise config crate

This commit is contained in:
Quentin Gliech
2022-02-01 09:34:17 +01:00
parent 66ff7376f7
commit f96c5b0cec
10 changed files with 119 additions and 102 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2021 The Matrix.org Foundation C.I.C.
// Copyright 2021, 2022 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -22,99 +22,8 @@
//! Application configuration logic
use async_trait::async_trait;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
mod cookies;
mod csrf;
mod database;
mod email;
mod http;
mod oauth2;
pub(crate) mod schema;
mod telemetry;
mod templates;
mod util;
mod sections;
pub(crate) mod util;
pub use self::{
cookies::CookiesConfig,
csrf::CsrfConfig,
database::DatabaseConfig,
email::{EmailConfig, EmailSmtpMode, EmailTransportConfig},
http::HttpConfig,
oauth2::{OAuth2ClientAuthMethodConfig, OAuth2ClientConfig, OAuth2Config},
telemetry::{
MetricsConfig, MetricsExporterConfig, Propagator, TelemetryConfig, TracingConfig,
TracingExporterConfig,
},
templates::TemplatesConfig,
util::ConfigurationSection,
};
/// Application configuration root
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct RootConfig {
/// Configuration related to OAuth 2.0/OIDC operations
pub oauth2: OAuth2Config,
/// Configuration of the HTTP server
#[serde(default)]
pub http: HttpConfig,
/// Database connection configuration
#[serde(default)]
pub database: DatabaseConfig,
/// Configuration related to cookies
pub cookies: CookiesConfig,
/// Configuration related to sending monitoring data
#[serde(default)]
pub telemetry: TelemetryConfig,
/// Configuration related to templates
#[serde(default)]
pub templates: TemplatesConfig,
/// Configuration related to Cross-Site Request Forgery protections
#[serde(default)]
pub csrf: CsrfConfig,
/// Configuration related to sending emails
#[serde(default)]
pub email: EmailConfig,
}
#[async_trait]
impl ConfigurationSection<'_> for RootConfig {
fn path() -> &'static str {
""
}
async fn generate() -> anyhow::Result<Self> {
Ok(Self {
oauth2: OAuth2Config::generate().await?,
http: HttpConfig::generate().await?,
database: DatabaseConfig::generate().await?,
cookies: CookiesConfig::generate().await?,
telemetry: TelemetryConfig::generate().await?,
templates: TemplatesConfig::generate().await?,
csrf: CsrfConfig::generate().await?,
email: EmailConfig::generate().await?,
})
}
fn test() -> Self {
Self {
oauth2: OAuth2Config::test(),
http: HttpConfig::test(),
database: DatabaseConfig::test(),
cookies: CookiesConfig::test(),
telemetry: TelemetryConfig::test(),
templates: TemplatesConfig::test(),
csrf: CsrfConfig::test(),
email: EmailConfig::test(),
}
}
}
pub use self::{sections::*, util::ConfigurationSection};