You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-20 12:02:22 +03:00
Working legacy login endpoint
This commit is contained in:
82
crates/config/src/sections/matrix.rs
Normal file
82
crates/config/src/sections/matrix.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright 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.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::serde_as;
|
||||
|
||||
use super::ConfigurationSection;
|
||||
|
||||
fn default_homeserver() -> String {
|
||||
"localhost:8008".to_string()
|
||||
}
|
||||
|
||||
/// Configuration related to the Matrix homeserver
|
||||
#[serde_as]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct MatrixConfig {
|
||||
/// Time-to-live of a CSRF token in seconds
|
||||
#[serde(default = "default_homeserver")]
|
||||
pub homeserver: String,
|
||||
}
|
||||
|
||||
impl Default for MatrixConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
homeserver: default_homeserver(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ConfigurationSection<'_> for MatrixConfig {
|
||||
fn path() -> &'static str {
|
||||
"matrix"
|
||||
}
|
||||
|
||||
async fn generate() -> anyhow::Result<Self> {
|
||||
Ok(Self::default())
|
||||
}
|
||||
|
||||
fn test() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use figment::Jail;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn load_config() {
|
||||
Jail::expect_with(|jail| {
|
||||
jail.create_file(
|
||||
"config.yaml",
|
||||
r#"
|
||||
matrix:
|
||||
homeserver: matrix.org
|
||||
"#,
|
||||
)?;
|
||||
|
||||
let config = MatrixConfig::load_from_file("config.yaml")?;
|
||||
|
||||
assert_eq!(config.homeserver, "matrix.org".to_string());
|
||||
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ mod csrf;
|
||||
mod database;
|
||||
mod email;
|
||||
mod http;
|
||||
mod matrix;
|
||||
mod secrets;
|
||||
mod telemetry;
|
||||
mod templates;
|
||||
@@ -31,6 +32,7 @@ pub use self::{
|
||||
database::DatabaseConfig,
|
||||
email::{EmailConfig, EmailSmtpMode, EmailTransportConfig},
|
||||
http::HttpConfig,
|
||||
matrix::MatrixConfig,
|
||||
secrets::{Encrypter, SecretsConfig},
|
||||
telemetry::{
|
||||
MetricsConfig, MetricsExporterConfig, Propagator, TelemetryConfig, TracingConfig,
|
||||
@@ -73,6 +75,10 @@ pub struct RootConfig {
|
||||
|
||||
/// Application secrets
|
||||
pub secrets: SecretsConfig,
|
||||
|
||||
/// Configuration related to the homeserver
|
||||
#[serde(default)]
|
||||
pub matrix: MatrixConfig,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -91,6 +97,7 @@ impl ConfigurationSection<'_> for RootConfig {
|
||||
csrf: CsrfConfig::generate().await?,
|
||||
email: EmailConfig::generate().await?,
|
||||
secrets: SecretsConfig::generate().await?,
|
||||
matrix: MatrixConfig::generate().await?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -104,6 +111,7 @@ impl ConfigurationSection<'_> for RootConfig {
|
||||
csrf: CsrfConfig::test(),
|
||||
email: EmailConfig::test(),
|
||||
secrets: SecretsConfig::test(),
|
||||
matrix: MatrixConfig::test(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user