Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add debug logs #75

Merged
merged 5 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
cpprian marked this conversation as resolved.
Show resolved Hide resolved
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...");
cpprian marked this conversation as resolved.
Show resolved Hide resolved
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);
cpprian marked this conversation as resolved.
Show resolved Hide resolved
return Err(core_error.into());
};
core_response
Expand Down
Loading