From 7434766800129153e93f61bd8ee17db37eb01ab3 Mon Sep 17 00:00:00 2001 From: Delta1925 Date: Tue, 18 Apr 2023 23:53:15 +0200 Subject: [PATCH] Improve logging --- backend/src/main.rs | 6 +++++- backend/src/management.rs | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/main.rs b/backend/src/main.rs index 0527a9e..4fa040c 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -10,7 +10,7 @@ use crate::errors::SpecialErrors; use crate::management::{clean_stale, store_pending_addition, store_pending_deletion, Action}; use crate::settings::{ROOT_FOLDER, SETTINGS}; use crate::utils::{ - gen_random_token, get_email_from_cert, is_email_allowed, parse_pem, read_file, return_outcome, + gen_random_token, get_email_from_cert, is_email_allowed, parse_pem, read_file, return_outcome, key_exists, }; use actix_files::Files; @@ -102,6 +102,7 @@ async fn index(req: HttpRequest) -> Result { async fn submit(pem: web::Form) -> Result { let cert = parse_pem(&pem.key)?; let email = get_email_from_cert(&cert)?; + debug!("Handling user {} request to add a key...", email); is_email_allowed(&email)?; let token = gen_random_token(); store_pending_addition(pem.key.clone(), &email, &token)?; @@ -113,6 +114,7 @@ async fn submit(pem: web::Form) -> Result { #[get("/api/confirm")] async fn confirm(token: web::Query) -> Result { + debug!("Handling token {}...", token.token); let (action, email) = confirm_action(&token.token)?; info!("User {} confirmed to {} his key successfully!", email, action.to_string().to_lowercase()); match action { @@ -123,6 +125,8 @@ async fn confirm(token: web::Query) -> Result { #[get("/api/delete")] async fn delete(email: web::Query) -> Result { + debug!("Handling user {} request to add a key...", email.email); + key_exists(&email.email)?; let token = gen_random_token(); store_pending_deletion(email.email.clone(), &token)?; debug!("Sending email to {} to add a key... (Request token: {})", email.email, token); diff --git a/backend/src/management.rs b/backend/src/management.rs index 3b15bb6..493c2b3 100644 --- a/backend/src/management.rs +++ b/backend/src/management.rs @@ -1,6 +1,6 @@ use crate::log_err; use crate::settings::{ERROR_TEXT, ROOT_FOLDER}; -use crate::utils::{get_user_file_path, key_exists, pending_path, read_file}; +use crate::utils::{get_user_file_path, pending_path, read_file}; use anyhow::Result; use chrono::Utc; @@ -67,7 +67,6 @@ pub fn store_pending_addition(pem: String, _email: &str, token: &str) -> Result< } pub fn store_pending_deletion(email: String, token: &str) -> Result<()> { - key_exists(&email)?; let pending = Pending::build_delete(email); store_pending(&pending, token)?; Ok(())