You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
Migrate to axum 0.6.0-rc.5
This commit is contained in:
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -678,9 +678,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "axum-extra"
|
||||
version = "0.4.0-rc.2"
|
||||
version = "0.4.0-rc.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa4236821ba5932aa38a08a45e4068ff2318c2882672c30ff26a433bc84b14e6"
|
||||
checksum = "16a35dfc7e1c432f55bc4f5665926651cc34d169ed7db7b6c01a26a20abc47af"
|
||||
dependencies = [
|
||||
"axum 0.6.0-rc.5",
|
||||
"bytes 1.2.1",
|
||||
@ -698,9 +698,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "axum-macros"
|
||||
version = "0.3.0-rc.2"
|
||||
version = "0.3.0-rc.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "414ca6cd8cbe767411488373833ebd9d07a6b470d841250d8d2b8bd69769ca0e"
|
||||
checksum = "f2185fff4d6f14de84dcc01b0ff8eee2ac5331a962cf85e60e080ce7db724cc9"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
|
@ -8,7 +8,7 @@ license = "Apache-2.0"
|
||||
[dependencies]
|
||||
async-trait = "0.1.58"
|
||||
axum = { version = "0.6.0-rc.5", features = ["headers"] }
|
||||
axum-extra = { version = "0.4.0-rc.2", features = ["cookie-private"] }
|
||||
axum-extra = { version = "0.4.0-rc.3", features = ["cookie-private"] }
|
||||
bincode = "1.3.3"
|
||||
chrono = "0.4.23"
|
||||
data-encoding = "2.3.2"
|
||||
|
@ -29,6 +29,7 @@ use mas_storage::MIGRATOR;
|
||||
use mas_tasks::TaskQueue;
|
||||
use mas_templates::Templates;
|
||||
use tokio::signal::unix::SignalKind;
|
||||
use tower::Layer;
|
||||
use tracing::{error, info, log::warn};
|
||||
|
||||
#[derive(Parser, Debug, Default)]
|
||||
@ -215,9 +216,8 @@ impl Options {
|
||||
};
|
||||
|
||||
// and build the router
|
||||
let router = crate::server::build_router(state.clone(), &config.resources)
|
||||
.layer(ServerLayer::new(config.name.clone()))
|
||||
.into_service();
|
||||
let router = crate::server::build_router(state.clone(), &config.resources);
|
||||
let router = ServerLayer::new(config.name.clone()).layer(router);
|
||||
|
||||
// Display some informations about where we'll be serving connections
|
||||
let is_tls = config.tls.is_some();
|
||||
|
@ -19,7 +19,10 @@ use std::{
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use axum::{body::HttpBody, error_handling::HandleErrorLayer, extract::FromRef, Extension, Router};
|
||||
use axum::{
|
||||
body::HttpBody, error_handling::HandleErrorLayer, extract::FromRef, Extension, Router,
|
||||
RouterService,
|
||||
};
|
||||
use hyper::StatusCode;
|
||||
use listenfd::ListenFd;
|
||||
use mas_config::{HttpBindConfig, HttpResource, HttpTlsConfig, UnixOrTcp};
|
||||
@ -33,14 +36,14 @@ use tower::Layer;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
#[allow(clippy::trait_duplication_in_bounds)]
|
||||
pub fn build_router<B>(state: AppState, resources: &[HttpResource]) -> Router<AppState, B>
|
||||
pub fn build_router<B>(state: AppState, resources: &[HttpResource]) -> RouterService<B>
|
||||
where
|
||||
B: HttpBody + Send + 'static,
|
||||
<B as HttpBody>::Data: Into<axum::body::Bytes> + Send,
|
||||
<B as HttpBody>::Error: std::error::Error + Send + Sync,
|
||||
{
|
||||
let templates = Templates::from_ref(&state);
|
||||
let mut router = Router::with_state(state);
|
||||
let mut router = Router::new();
|
||||
|
||||
for resource in resources {
|
||||
router = match resource {
|
||||
@ -106,7 +109,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
router
|
||||
router.with_state(state)
|
||||
}
|
||||
|
||||
pub fn build_tls_server_config(config: &HttpTlsConfig) -> Result<ServerConfig, anyhow::Error> {
|
||||
|
@ -22,8 +22,8 @@ hyper = { version = "0.14.23", features = ["full"] }
|
||||
tower = "0.4.13"
|
||||
tower-http = { version = "0.3.4", features = ["cors"] }
|
||||
axum = { version = "0.6.0-rc.5", features = ["ws"] }
|
||||
axum-macros = "0.3.0-rc.2"
|
||||
axum-extra = { version = "0.4.0-rc.2", features = ["cookie-private"] }
|
||||
axum-macros = "0.3.0-rc.3"
|
||||
axum-extra = { version = "0.4.0-rc.3", features = ["cookie-private"] }
|
||||
|
||||
async-graphql = { version = "4.0.16", features = ["tracing", "apollo_tracing"] }
|
||||
|
||||
|
@ -39,7 +39,7 @@ mod tests {
|
||||
#[sqlx::test(migrator = "mas_storage::MIGRATOR")]
|
||||
async fn test_get_health(pool: PgPool) -> Result<(), anyhow::Error> {
|
||||
let state = crate::test_state(pool).await?;
|
||||
let app = crate::router(state).into_service();
|
||||
let app = crate::healthcheck_router().with_state(state);
|
||||
|
||||
let request = Request::builder().uri("/health").body(Body::empty())?;
|
||||
|
||||
|
@ -58,15 +58,6 @@ pub use compat::MatrixHomeserver;
|
||||
|
||||
pub use self::{app_state::AppState, graphql::schema as graphql_schema};
|
||||
|
||||
#[must_use]
|
||||
pub fn empty_router<S, B>(state: S) -> Router<S, B>
|
||||
where
|
||||
B: HttpBody + Send + 'static,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
Router::with_state(state)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn healthcheck_router<S, B>() -> Router<S, B>
|
||||
where
|
||||
@ -74,7 +65,7 @@ where
|
||||
S: Clone + Send + Sync + 'static,
|
||||
PgPool: FromRef<S>,
|
||||
{
|
||||
Router::inherit_state().route(mas_router::Healthcheck::route(), get(self::health::get))
|
||||
Router::new().route(mas_router::Healthcheck::route(), get(self::health::get))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@ -87,7 +78,7 @@ where
|
||||
mas_graphql::Schema: FromRef<S>,
|
||||
Encrypter: FromRef<S>,
|
||||
{
|
||||
let mut router = Router::inherit_state()
|
||||
let mut router = Router::new()
|
||||
.route(
|
||||
"/graphql",
|
||||
get(self::graphql::get).post(self::graphql::post),
|
||||
@ -109,7 +100,7 @@ where
|
||||
Keystore: FromRef<S>,
|
||||
UrlBuilder: FromRef<S>,
|
||||
{
|
||||
Router::inherit_state()
|
||||
Router::new()
|
||||
.route(
|
||||
mas_router::OidcConfiguration::route(),
|
||||
get(self::oauth2::discovery::get),
|
||||
@ -148,7 +139,7 @@ where
|
||||
Encrypter: FromRef<S>,
|
||||
{
|
||||
// All those routes are API-like, with a common CORS layer
|
||||
Router::inherit_state()
|
||||
Router::new()
|
||||
.route(
|
||||
mas_router::OAuth2Keys::route(),
|
||||
get(self::oauth2::keys::get),
|
||||
@ -199,7 +190,7 @@ where
|
||||
PgPool: FromRef<S>,
|
||||
MatrixHomeserver: FromRef<S>,
|
||||
{
|
||||
Router::inherit_state()
|
||||
Router::new()
|
||||
.route(
|
||||
mas_router::CompatLogin::route(),
|
||||
get(self::compat::login::get).post(self::compat::login::post),
|
||||
@ -243,7 +234,7 @@ where
|
||||
Templates: FromRef<S>,
|
||||
Mailer: FromRef<S>,
|
||||
{
|
||||
Router::inherit_state()
|
||||
Router::new()
|
||||
.route(
|
||||
mas_router::ChangePasswordDiscovery::route(),
|
||||
get(|| async { mas_router::AccountPassword.go() }),
|
||||
@ -324,9 +315,10 @@ where
|
||||
))
|
||||
}
|
||||
|
||||
/*
|
||||
#[must_use]
|
||||
#[allow(clippy::trait_duplication_in_bounds)]
|
||||
pub fn router<S, B>(state: S) -> Router<S, B>
|
||||
pub fn router<S, B>(state: S) -> RouterService<B>
|
||||
where
|
||||
B: HttpBody + Send + 'static,
|
||||
<B as HttpBody>::Data: Into<Bytes> + Send,
|
||||
@ -349,14 +341,16 @@ where
|
||||
let compat_router = compat_router();
|
||||
let human_router = human_router(Templates::from_ref(&state));
|
||||
|
||||
Router::with_state(state)
|
||||
Router::new()
|
||||
.merge(healthcheck_router)
|
||||
.merge(discovery_router)
|
||||
.merge(human_router)
|
||||
.merge(api_router)
|
||||
.merge(graphql_router)
|
||||
.merge(compat_router)
|
||||
.with_state(state)
|
||||
}
|
||||
*/
|
||||
|
||||
#[cfg(test)]
|
||||
async fn test_state(pool: PgPool) -> Result<AppState, anyhow::Error> {
|
||||
|
Reference in New Issue
Block a user