Skip to content

Commit

Permalink
add debug logs to better understand flow between core - proxy - client
Browse files Browse the repository at this point in the history
  • Loading branch information
cpprian committed Aug 8, 2024
1 parent 1f519f2 commit 4706eef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/handlers/enrollment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ 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);
}

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 {:?}",
Expand Down Expand Up @@ -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:?}");
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Payload>) -> Result<Payload, ApiError> {
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
Expand Down

0 comments on commit 4706eef

Please sign in to comment.