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