implement more routes with default empty responses
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
8ada363a92
commit
277d7111c8
@ -25,13 +25,14 @@ use ruma::api::client::{
|
|||||||
|
|
||||||
pub fn routes() -> axum::Router {
|
pub fn routes() -> axum::Router {
|
||||||
axum::Router::new()
|
axum::Router::new()
|
||||||
.route("/r0/login", get(get_login).post(post_login))
|
.route("/r0/login", get(get_login_types).post(login))
|
||||||
.route("/r0/register", post(post_register))
|
.route("/r0/register", post(post_register))
|
||||||
.route("/r0/register/available", get(get_username_available))
|
.route("/r0/register/available", get(get_username_available))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
async fn get_login() -> Result<RumaResponse<session::get_login_types::v3::Response>, ApiError> {
|
async fn get_login_types() -> Result<RumaResponse<session::get_login_types::v3::Response>, ApiError>
|
||||||
|
{
|
||||||
use session::get_login_types::v3::*;
|
use session::get_login_types::v3::*;
|
||||||
|
|
||||||
Ok(RumaResponse(session::get_login_types::v3::Response::new(
|
Ok(RumaResponse(session::get_login_types::v3::Response::new(
|
||||||
@ -40,7 +41,7 @@ async fn get_login() -> Result<RumaResponse<session::get_login_types::v3::Respon
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn post_login(
|
async fn login(
|
||||||
Extension(config): Extension<Arc<Config>>,
|
Extension(config): Extension<Arc<Config>>,
|
||||||
Extension(db): Extension<SqlitePool>,
|
Extension(db): Extension<SqlitePool>,
|
||||||
RumaRequest(req): RumaRequest<session::login::v3::IncomingRequest>,
|
RumaRequest(req): RumaRequest<session::login::v3::IncomingRequest>,
|
||||||
@ -118,7 +119,6 @@ async fn post_register(
|
|||||||
RumaRequest(req): RumaRequest<account::register::v3::IncomingRequest>,
|
RumaRequest(req): RumaRequest<account::register::v3::IncomingRequest>,
|
||||||
) -> Result<RumaResponse<account::register::v3::Response>, ApiError> {
|
) -> Result<RumaResponse<account::register::v3::Response>, ApiError> {
|
||||||
use account::register::v3::*;
|
use account::register::v3::*;
|
||||||
tracing::debug!("Register hit");
|
|
||||||
|
|
||||||
config
|
config
|
||||||
.enable_registration()
|
.enable_registration()
|
||||||
@ -179,7 +179,7 @@ async fn post_register(
|
|||||||
let password = req
|
let password = req
|
||||||
.password
|
.password
|
||||||
.ok_or("password missing")
|
.ok_or("password missing")
|
||||||
.map_err(|e| anyhow::anyhow!(e))?;
|
.map_err(|_| RegistrationError::AdditionalAuthenticationInformation)?;
|
||||||
let user_id = if let Some(username) = req.username {
|
let user_id = if let Some(username) = req.username {
|
||||||
let user_id = UserId::new(&username, config.server_name())?;
|
let user_id = UserId::new(&username, config.server_name())?;
|
||||||
|
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
use axum::routing::post;
|
|
||||||
|
|
||||||
use crate::api::client_server::errors::api_error::ApiError;
|
|
||||||
use crate::ruma_wrapper::RumaRequest;
|
|
||||||
|
|
||||||
use ruma::api::client::room;
|
|
||||||
|
|
||||||
pub fn routes() -> axum::Router {
|
|
||||||
axum::Router::new()
|
|
||||||
.route("/r0/createRoom", post(post_create_room))
|
|
||||||
.layer(axum::middleware::from_fn(super::authentication_middleware))
|
|
||||||
}
|
|
||||||
async fn post_create_room(
|
|
||||||
RumaRequest(_req): RumaRequest<room::create_room::v3::IncomingRequest>,
|
|
||||||
) -> Result<String, ApiError> {
|
|
||||||
Ok("".into())
|
|
||||||
}
|
|
@ -13,7 +13,9 @@ use crate::{models::sessions::Session, types::error_code::ErrorCode};
|
|||||||
use super::errors::ErrorResponse;
|
use super::errors::ErrorResponse;
|
||||||
|
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod create_room;
|
pub mod room;
|
||||||
|
pub mod presence;
|
||||||
|
pub mod push;
|
||||||
pub mod thirdparty;
|
pub mod thirdparty;
|
||||||
|
|
||||||
async fn authentication_middleware<B>(mut req: Request<B>, next: Next<B>) -> impl IntoResponse {
|
async fn authentication_middleware<B>(mut req: Request<B>, next: Next<B>) -> impl IntoResponse {
|
||||||
|
@ -19,7 +19,6 @@ pub fn routes() -> axum::Router {
|
|||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn get_thirdparty_protocols(
|
async fn get_thirdparty_protocols(
|
||||||
Extension(_user): Extension<Arc<User>>,
|
Extension(_user): Extension<Arc<User>>,
|
||||||
RumaRequest(_req): RumaRequest<thirdparty::get_protocols::v3::IncomingRequest>,
|
|
||||||
) -> Result<RumaResponse<thirdparty::get_protocols::v3::Response>, ApiError> {
|
) -> Result<RumaResponse<thirdparty::get_protocols::v3::Response>, ApiError> {
|
||||||
Ok(RumaResponse(thirdparty::get_protocols::v3::Response::new(
|
Ok(RumaResponse(thirdparty::get_protocols::v3::Response::new(
|
||||||
BTreeMap::new(),
|
BTreeMap::new(),
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use axum::routing::get;
|
use axum::routing::get;
|
||||||
|
|
||||||
use crate::ruma_wrapper::RumaResponse;
|
use crate::ruma_wrapper::RumaResponse;
|
||||||
|
use ruma::api::client::discovery;
|
||||||
|
|
||||||
pub fn routes() -> axum::Router {
|
pub fn routes() -> axum::Router {
|
||||||
axum::Router::new().route("/versions", get(get_client_versions))
|
axum::Router::new().route("/versions", get(get_client_versions))
|
||||||
}
|
}
|
||||||
|
|
||||||
use ruma::api::client::discovery;
|
|
||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
async fn get_client_versions() -> RumaResponse<discovery::get_supported_versions::Response> {
|
async fn get_client_versions() -> RumaResponse<discovery::get_supported_versions::Response> {
|
||||||
|
11
src/main.rs
11
src/main.rs
@ -19,7 +19,7 @@ mod types;
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
if std::env::var("RUST_LOG").is_err() {
|
if std::env::var("RUST_LOG").is_err() {
|
||||||
std::env::set_var("RUST_LOG", "debug");
|
std::env::set_var("RUST_LOG", "debug,hyper=info");
|
||||||
}
|
}
|
||||||
|
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
@ -28,6 +28,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let pool = sqlx::SqlitePool::connect(config.db_path()).await?;
|
let pool = sqlx::SqlitePool::connect(config.db_path()).await?;
|
||||||
|
|
||||||
|
// TODO: set correct CORS headers
|
||||||
let cors = CorsLayer::new()
|
let cors = CorsLayer::new()
|
||||||
.allow_origin(tower_http::cors::Any)
|
.allow_origin(tower_http::cors::Any)
|
||||||
.allow_methods(tower_http::cors::Any)
|
.allow_methods(tower_http::cors::Any)
|
||||||
@ -39,15 +40,17 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
.merge(api::client_server::versions::routes())
|
.merge(api::client_server::versions::routes())
|
||||||
.merge(api::client_server::r0::auth::routes())
|
.merge(api::client_server::r0::auth::routes())
|
||||||
.merge(api::client_server::r0::thirdparty::routes())
|
.merge(api::client_server::r0::thirdparty::routes())
|
||||||
.merge(api::client_server::r0::create_room::routes());
|
.merge(api::client_server::r0::room::routes())
|
||||||
|
.merge(api::client_server::r0::presence::routes())
|
||||||
|
.merge(api::client_server::r0::push::routes());
|
||||||
|
|
||||||
let router = Router::new()
|
let router = Router::new()
|
||||||
.nest("/_matrix/client", client_server)
|
.nest("/_matrix/client", client_server)
|
||||||
.layer(cors)
|
.layer(cors)
|
||||||
.layer(tracing_layer)
|
.layer(tracing_layer)
|
||||||
|
.fallback(fallback.into_service())
|
||||||
.layer(Extension(pool))
|
.layer(Extension(pool))
|
||||||
.layer(Extension(config))
|
.layer(Extension(config));
|
||||||
.fallback(fallback.into_service());
|
|
||||||
|
|
||||||
let _ = axum::Server::bind(&"127.0.0.1:3000".parse().unwrap())
|
let _ = axum::Server::bind(&"127.0.0.1:3000".parse().unwrap())
|
||||||
.serve(router.into_make_service())
|
.serve(router.into_make_service())
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
use super::{flow::Flow, identifier::Identifier};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Deserialize)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
pub enum AuthenticationData {
|
|
||||||
Password(AuthenticationPassword),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Deserialize)]
|
|
||||||
pub struct AuthenticationPassword {
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
_type: Flow,
|
|
||||||
identifier: Identifier,
|
|
||||||
password: String,
|
|
||||||
user: Option<String>,
|
|
||||||
device_id: Option<String>,
|
|
||||||
initial_device_display_name: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AuthenticationPassword {
|
|
||||||
/// Get a reference to the authentication password's identifier.
|
|
||||||
#[must_use]
|
|
||||||
pub fn identifier(&self) -> &Identifier {
|
|
||||||
&self.identifier
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a reference to the authentication password's password.
|
|
||||||
#[must_use]
|
|
||||||
pub fn password(&self) -> &str {
|
|
||||||
self.password.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a reference to the authentication password's user.
|
|
||||||
#[must_use]
|
|
||||||
pub fn user(&self) -> Option<&String> {
|
|
||||||
self.user.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a reference to the authentication password's device id.
|
|
||||||
#[must_use]
|
|
||||||
pub fn device_id(&self) -> Option<&String> {
|
|
||||||
self.device_id.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a mutable reference to the authentication password's initial device display name.
|
|
||||||
#[must_use]
|
|
||||||
pub fn initial_device_display_name(&self) -> Option<&String> {
|
|
||||||
self.initial_device_display_name.as_ref()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
use super::identifier_type::IdentifierType;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Deserialize)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
pub enum Identifier {
|
|
||||||
User(IdentifierUser),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Deserialize)]
|
|
||||||
pub struct IdentifierUser {
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
_type: IdentifierType,
|
|
||||||
user: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IdentifierUser {
|
|
||||||
/// Get a reference to the identifier user's user.
|
|
||||||
#[must_use]
|
|
||||||
pub fn user(&self) -> Option<&String> {
|
|
||||||
self.user.as_ref()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum IdentifierType {
|
|
||||||
User,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl serde::Serialize for IdentifierType {
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: serde::Serializer,
|
|
||||||
{
|
|
||||||
serializer.serialize_str(match self {
|
|
||||||
IdentifierType::User => "m.id.user",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> serde::Deserialize<'de> for IdentifierType {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: serde::Deserializer<'de>,
|
|
||||||
{
|
|
||||||
struct IdentifierVisitor;
|
|
||||||
|
|
||||||
impl<'de> serde::de::Visitor<'de> for IdentifierVisitor {
|
|
||||||
type Value = IdentifierType;
|
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
||||||
formatter.write_str("Identifier")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
|
|
||||||
where
|
|
||||||
E: serde::de::Error,
|
|
||||||
{
|
|
||||||
match v {
|
|
||||||
"m.id.user" => Ok(IdentifierType::User),
|
|
||||||
_ => Err(serde::de::Error::custom("Unknown identifier")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deserializer.deserialize_str(IdentifierVisitor {})
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,6 @@
|
|||||||
pub mod authentication_data;
|
|
||||||
pub mod error_code;
|
pub mod error_code;
|
||||||
pub mod event_type;
|
pub mod event_type;
|
||||||
pub mod flow;
|
pub mod flow;
|
||||||
pub mod identifier;
|
|
||||||
pub mod identifier_type;
|
|
||||||
pub mod server_name;
|
pub mod server_name;
|
||||||
pub mod user_id;
|
pub mod user_id;
|
||||||
pub mod user_interactive_authorization;
|
pub mod user_interactive_authorization;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user