Skip to content

Commit 473dd25

Browse files
committed
Add additional logging to /login
This adds two additional pieces of information to the route: * connecting IP address * status code on error
1 parent 2ee8801 commit 473dd25

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Diff for: crates/atuin-server/src/handlers/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt;
2+
13
use atuin_common::api::{ErrorResponse, IndexResponse};
24
use atuin_server_database::Database;
35
use axum::{extract::State, http, response::IntoResponse, Json};
@@ -32,6 +34,12 @@ pub async fn index<DB: Database>(state: State<AppState<DB>>) -> Json<IndexRespon
3234
})
3335
}
3436

37+
impl<'a> fmt::Display for ErrorResponseStatus<'a> {
38+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39+
write!(f, "status={}", self.status)
40+
}
41+
}
42+
3543
impl<'a> IntoResponse for ErrorResponseStatus<'a> {
3644
fn into_response(self) -> axum::response::Response {
3745
(self.status, Json(self.error)).into_response()

Diff for: crates/atuin-server/src/handlers/user.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use std::borrow::Borrow;
22
use std::collections::HashMap;
3+
use std::net::SocketAddr;
34
use std::time::Duration;
45

56
use argon2::{
67
password_hash::SaltString, Algorithm, Argon2, Params, PasswordHash, PasswordHasher,
78
PasswordVerifier, Version,
89
};
910
use axum::{
10-
extract::{Path, State},
11+
extract::{ConnectInfo, Path, State},
1112
http::StatusCode,
1213
Json,
1314
};
@@ -311,8 +312,9 @@ pub async fn change_password<DB: Database>(
311312
Ok(Json(ChangePasswordResponse {}))
312313
}
313314

314-
#[instrument(skip_all, fields(user.username = login.username.as_str()))]
315+
#[instrument(skip_all, err, fields(ip = addr.ip().to_string(), user.username = login.username.as_str()))]
315316
pub async fn login<DB: Database>(
317+
ConnectInfo(addr): ConnectInfo<SocketAddr>,
316318
state: State<AppState<DB>>,
317319
login: Json<LoginRequest>,
318320
) -> Result<Json<LoginResponse>, ErrorResponseStatus<'static>> {

Diff for: crates/atuin-server/src/lib.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ pub async fn launch_with_tcp_listener<Db: Database>(
7070
) -> Result<()> {
7171
let r = make_router::<Db>(settings).await?;
7272

73-
serve(listener, r.into_make_service())
74-
.with_graceful_shutdown(shutdown)
75-
.await?;
73+
serve(
74+
listener,
75+
r.into_make_service_with_connect_info::<SocketAddr>(),
76+
)
77+
.with_graceful_shutdown(shutdown)
78+
.await?;
7679

7780
Ok(())
7881
}
@@ -102,7 +105,7 @@ async fn launch_with_tls<Db: Database>(
102105

103106
let server = axum_server::bind_rustls(addr, rustls_config)
104107
.handle(handle.clone())
105-
.serve(r.into_make_service());
108+
.serve(r.into_make_service_with_connect_info::<SocketAddr>());
106109

107110
tokio::select! {
108111
_ = server => {}

0 commit comments

Comments
 (0)