From 4706eef2f8983186aed48eac2f0635db0e386c66 Mon Sep 17 00:00:00 2001 From: cpprian Date: Thu, 8 Aug 2024 11:59:27 +0200 Subject: [PATCH 1/4] add debug logs to better understand flow between core - proxy - client --- src/handlers/enrollment.rs | 6 ++++++ src/handlers/mod.rs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/handlers/enrollment.rs b/src/handlers/enrollment.rs index b8a0a21..8c2b824 100644 --- a/src/handlers/enrollment.rs +++ b/src/handlers/enrollment.rs @@ -29,6 +29,7 @@ pub async fn start_enrollment_process( info!("Starting enrollment process"); // clear session cookies if already populated + debug!("Try to remove previous session cookie if it still exists."); if let Some(cookie) = private_cookies.get(ENROLLMENT_COOKIE_NAME) { debug!("Removing previous session cookie"); private_cookies = private_cookies.remove(cookie); @@ -36,10 +37,12 @@ pub async fn start_enrollment_process( let token = req.token.clone(); + debug!("Sending the enrollment process request to core service."); let rx = state .grpc_server .send(Some(core_request::Payload::EnrollmentStart(req)), None)?; let payload = get_core_response(rx).await?; + debug!("Receving payload from the core service. Try to set private cookie for starting enrollment process for user {:?} by admin {:?}.", response.user, response.admin); if let core_response::Payload::EnrollmentStart(response) = payload { info!( "Started enrollment process for user {:?} by admin {:?}", @@ -67,14 +70,17 @@ pub async fn activate_user( info!("Activating user - phone number {phone:?}"); // set auth info + debug!("Set private cookie for the request."); req.token = private_cookies .get(ENROLLMENT_COOKIE_NAME) .map(|cookie| cookie.value().to_string()); + debug!("Sending the activate user request to core service."); let rx = state .grpc_server .send(Some(core_request::Payload::ActivateUser(req)), device_info)?; let payload = get_core_response(rx).await?; + debug!("Receving payload from the core service. Try remove private cookie..."); if let core_response::Payload::Empty(()) = payload { if let Some(cookie) = private_cookies.get(ENROLLMENT_COOKIE_NAME) { info!("Activated user - phone number {phone:?}"); diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 2d1c62f..7b921f0 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -46,9 +46,11 @@ where /// /// Waits for core response with a given timeout and returns the response payload. async fn get_core_response(rx: Receiver) -> Result { + debug!("Fetching core response..."); if let Ok(core_response) = timeout(Duration::from_secs(CORE_RESPONSE_TIMEOUT), rx).await { debug!("Got gRPC response from Defguard core: {core_response:?}"); if let Ok(Payload::CoreError(core_error)) = core_response { + error!("Response from core service meets an error that can't finish the request correctly. | status code: {} msg {}", core_error.status_code, core_error.message); return Err(core_error.into()); }; core_response From df3944dcb9d81f6507e27e7ee4ee47f29a7494fc Mon Sep 17 00:00:00 2001 From: Cyprian <46838495+cpprian@users.noreply.github.com> Date: Tue, 13 Aug 2024 15:57:03 +0200 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Aleksander <170264518+t-aleksander@users.noreply.github.com> --- src/handlers/enrollment.rs | 4 ++-- src/handlers/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/handlers/enrollment.rs b/src/handlers/enrollment.rs index 8c2b824..7cf9e15 100644 --- a/src/handlers/enrollment.rs +++ b/src/handlers/enrollment.rs @@ -29,7 +29,7 @@ pub async fn start_enrollment_process( info!("Starting enrollment process"); // clear session cookies if already populated - debug!("Try to remove previous session cookie if it still exists."); + debug!("Trying to remove previous session cookie if it still exists."); if let Some(cookie) = private_cookies.get(ENROLLMENT_COOKIE_NAME) { debug!("Removing previous session cookie"); private_cookies = private_cookies.remove(cookie); @@ -80,7 +80,7 @@ pub async fn activate_user( .grpc_server .send(Some(core_request::Payload::ActivateUser(req)), device_info)?; let payload = get_core_response(rx).await?; - debug!("Receving payload from the core service. Try remove private cookie..."); + debug!("Receving payload from the core service. Trying to remove private cookie..."); if let core_response::Payload::Empty(()) = payload { if let Some(cookie) = private_cookies.get(ENROLLMENT_COOKIE_NAME) { info!("Activated user - phone number {phone:?}"); diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 7b921f0..cd3100e 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -50,7 +50,7 @@ async fn get_core_response(rx: Receiver) -> Result { if let Ok(core_response) = timeout(Duration::from_secs(CORE_RESPONSE_TIMEOUT), rx).await { debug!("Got gRPC response from Defguard core: {core_response:?}"); if let Ok(Payload::CoreError(core_error)) = core_response { - error!("Response from core service meets an error that can't finish the request correctly. | status code: {} msg {}", core_error.status_code, core_error.message); + error!("Received an error response from the core service. | status code: {} message: {}", core_error.status_code, core_error.message); return Err(core_error.into()); }; core_response From c6b3e73dba97f9737548a2d13c9dedbf60ca840f Mon Sep 17 00:00:00 2001 From: cpprian Date: Tue, 13 Aug 2024 16:24:36 +0200 Subject: [PATCH 3/4] cargo fmt --- src/handlers/enrollment.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/enrollment.rs b/src/handlers/enrollment.rs index 7cf9e15..9a7c4ec 100644 --- a/src/handlers/enrollment.rs +++ b/src/handlers/enrollment.rs @@ -42,7 +42,7 @@ pub async fn start_enrollment_process( .grpc_server .send(Some(core_request::Payload::EnrollmentStart(req)), None)?; let payload = get_core_response(rx).await?; - debug!("Receving payload from the core service. Try to set private cookie for starting enrollment process for user {:?} by admin {:?}.", response.user, response.admin); + debug!("Receving payload from the core service. Try to set private cookie for starting enrollment process."); if let core_response::Payload::EnrollmentStart(response) = payload { info!( "Started enrollment process for user {:?} by admin {:?}", From 77799f1ad24b94ebe90b04ae5701e81db802a8e1 Mon Sep 17 00:00:00 2001 From: cpprian Date: Tue, 13 Aug 2024 16:24:36 +0200 Subject: [PATCH 4/4] cargo fmt --- src/handlers/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index cd3100e..1fb53e9 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -50,7 +50,10 @@ async fn get_core_response(rx: Receiver) -> Result { if let Ok(core_response) = timeout(Duration::from_secs(CORE_RESPONSE_TIMEOUT), rx).await { debug!("Got gRPC response from Defguard core: {core_response:?}"); if let Ok(Payload::CoreError(core_error)) = core_response { - error!("Received an error response from the core service. | status code: {} message: {}", core_error.status_code, core_error.message); + error!( + "Received an error response from the core service. | status code: {} message: {}", + core_error.status_code, core_error.message + ); return Err(core_error.into()); }; core_response