Implement dummy /api_login
This commit is contained in:
parent
2447786c81
commit
32e99b155c
1 changed files with 44 additions and 5 deletions
|
@ -1,12 +1,51 @@
|
|||
use axum::{routing::get, Router};
|
||||
use color_eyre::Result;
|
||||
use tracing::instrument;
|
||||
use axum::{
|
||||
extract::Query,
|
||||
response::ErrorResponse,
|
||||
routing::{get, post},
|
||||
Form, Json, Router,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::{event, instrument, Level};
|
||||
|
||||
use crate::auth::Password;
|
||||
|
||||
#[instrument]
|
||||
pub async fn run() -> Result<()> {
|
||||
let app = Router::new().route("/tls-check/success", get(|| async { "OK" }));
|
||||
pub async fn run() -> color_eyre::Result<()> {
|
||||
let app = Router::new()
|
||||
.route("/tls-check/success", get(|| async { "OK" }))
|
||||
.route("/api-login", post(api_login));
|
||||
let listener = tokio::net::TcpListener::bind("[::]:8080").await?;
|
||||
axum::serve(listener, app).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||
struct ApiVersion {
|
||||
api_version: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
struct LoginRequest {
|
||||
username: String,
|
||||
password: Password,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
struct LoginResponse {
|
||||
username: String,
|
||||
token: String,
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn api_login(
|
||||
Query(ApiVersion { api_version }): Query<ApiVersion>,
|
||||
Form(LoginRequest { username, password }): Form<LoginRequest>,
|
||||
) -> Result<Json<LoginResponse>, ErrorResponse> {
|
||||
event!(Level::WARN, "Creating dummy token");
|
||||
|
||||
Ok(Json(LoginResponse {
|
||||
username,
|
||||
token: "invalid".to_string(),
|
||||
}))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue