1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-07 17:03:01 +03:00

Make the HomeserverConnection available in handlers

This commit is contained in:
Quentin Gliech
2024-02-28 09:58:27 +01:00
parent 20dd5ca311
commit 4aeb446061
8 changed files with 96 additions and 65 deletions

View File

@@ -21,10 +21,12 @@ use axum::{
use ipnetwork::IpNetwork;
use mas_handlers::{
passwords::PasswordManager, ActivityTracker, BoundActivityTracker, CookieManager, ErrorWrapper,
HttpClientFactory, MatrixHomeserver, MetadataCache, SiteConfig,
HttpClientFactory, MetadataCache, SiteConfig,
};
use mas_i18n::Translator;
use mas_keystore::{Encrypter, Keystore};
use mas_matrix::BoxHomeserverConnection;
use mas_matrix_synapse::SynapseConnection;
use mas_policy::{Policy, PolicyFactory};
use mas_router::UrlBuilder;
use mas_storage::{BoxClock, BoxRepository, BoxRng, Repository, SystemClock};
@@ -45,7 +47,7 @@ pub struct AppState {
pub cookie_manager: CookieManager,
pub encrypter: Encrypter,
pub url_builder: UrlBuilder,
pub homeserver: MatrixHomeserver,
pub homeserver_connection: SynapseConnection,
pub policy_factory: Arc<PolicyFactory>,
pub graphql_schema: mas_graphql::Schema,
pub http_client_factory: HttpClientFactory,
@@ -177,12 +179,6 @@ impl FromRef<AppState> for UrlBuilder {
}
}
impl FromRef<AppState> for MatrixHomeserver {
fn from_ref(input: &AppState) -> Self {
input.homeserver.clone()
}
}
impl FromRef<AppState> for HttpClientFactory {
fn from_ref(input: &AppState) -> Self {
input.http_client_factory.clone()
@@ -213,6 +209,12 @@ impl FromRef<AppState> for SiteConfig {
}
}
impl FromRef<AppState> for BoxHomeserverConnection {
fn from_ref(input: &AppState) -> Self {
Box::new(input.homeserver_connection.clone())
}
}
#[async_trait]
impl FromRequestParts<AppState> for BoxClock {
type Rejection = Infallible;

View File

@@ -18,9 +18,7 @@ use anyhow::Context;
use clap::Parser;
use itertools::Itertools;
use mas_config::AppConfig;
use mas_handlers::{
ActivityTracker, CookieManager, HttpClientFactory, MatrixHomeserver, MetadataCache, SiteConfig,
};
use mas_handlers::{ActivityTracker, CookieManager, HttpClientFactory, MetadataCache, SiteConfig};
use mas_listener::{server::Server, shutdown::ShutdownStream};
use mas_matrix_synapse::SynapseConnection;
use mas_router::UrlBuilder;
@@ -123,6 +121,13 @@ impl Options {
let http_client_factory = HttpClientFactory::new().await?;
let homeserver_connection = SynapseConnection::new(
config.matrix.homeserver.clone(),
config.matrix.endpoint.clone(),
config.matrix.secret.clone(),
http_client_factory.clone(),
);
if !self.no_worker {
let mailer = mailer_from_config(&config.email, &templates)?;
mailer.test_connection().await?;
@@ -132,19 +137,13 @@ impl Options {
let worker_name = Alphanumeric.sample_string(&mut rng, 10);
info!(worker_name, "Starting task worker");
let conn = SynapseConnection::new(
config.matrix.homeserver.clone(),
config.matrix.endpoint.clone(),
config.matrix.secret.clone(),
http_client_factory.clone(),
);
let monitor = mas_tasks::init(&worker_name, &pool, &mailer, conn).await?;
let monitor =
mas_tasks::init(&worker_name, &pool, &mailer, homeserver_connection.clone())
.await?;
// TODO: grab the handle
tokio::spawn(monitor.run());
}
let homeserver = MatrixHomeserver::new(config.matrix.homeserver.clone());
let listeners_config = config.http.listeners.clone();
let password_manager = password_manager_from_config(&config.passwords).await?;
@@ -152,13 +151,6 @@ impl Options {
// The upstream OIDC metadata cache
let metadata_cache = MetadataCache::new();
let conn = SynapseConnection::new(
config.matrix.homeserver.clone(),
config.matrix.endpoint.clone(),
config.matrix.secret.clone(),
http_client_factory.clone(),
);
let site_config = SiteConfig {
tos_uri: config.branding.tos_uri.clone(),
access_token_ttl: config.experimental.access_token_ttl,
@@ -176,7 +168,8 @@ impl Options {
// Listen for SIGHUP
register_sighup(&templates, &activity_tracker)?;
let graphql_schema = mas_handlers::graphql_schema(&pool, &policy_factory, conn);
let graphql_schema =
mas_handlers::graphql_schema(&pool, &policy_factory, homeserver_connection.clone());
let state = {
let mut s = AppState {
@@ -187,7 +180,7 @@ impl Options {
cookie_manager,
encrypter,
url_builder,
homeserver,
homeserver_connection,
policy_factory,
graphql_schema,
http_client_factory,