From d37c09d8d9fc1abead7007be1d2d6cff03a4e6e3 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 10 Feb 2024 12:51:53 +0000 Subject: [PATCH] Add more instrument macros --- src/auth.rs | 4 ++++ src/db.rs | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/auth.rs b/src/auth.rs index 8d584a3..7d38afd 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -76,6 +76,7 @@ impl UserAuthenticator { } } +#[derive(Debug)] pub struct ServerPadlockGenerator { secret: PadlockGenerationSecret, } @@ -85,11 +86,13 @@ impl ServerPadlockGenerator { todo!() } + #[instrument] pub fn generate_padlock(&self, server_hash: &ServerHash) -> ServerPadlock { todo!() } } +#[derive(Debug)] pub struct UserServerKeyGenerator { user_authenticator: Arc, padlock_generator: Arc, @@ -100,6 +103,7 @@ impl UserServerKeyGenerator { todo!() } + #[instrument] pub async fn generate_user_server_key( &self, username: &str, diff --git a/src/db.rs b/src/db.rs index fbc222b..6c55dfb 100644 --- a/src/db.rs +++ b/src/db.rs @@ -2,6 +2,7 @@ use std::str::FromStr; use secrecy::ExposeSecret; use sqlx::{query, query_as, sqlite::SqliteConnectOptions, Connection, SqliteConnection}; +use tracing::instrument; use crate::secrets::UserToken; @@ -22,6 +23,7 @@ pub struct SqliteDatabase { } impl SqliteDatabase { + #[instrument] pub async fn open() -> Self { let options = SqliteConnectOptions::from_str(DB_URI_DEFAULT) .expect("Invalid database URI") @@ -38,6 +40,7 @@ impl SqliteDatabase { db } + #[instrument] pub async fn init(&mut self) { query(&format!( "CREATE TABLE IF NOT EXISTS {TABLE_USER_TOKENS} ( @@ -56,6 +59,7 @@ impl SqliteDatabase { } impl Database for SqliteDatabase { + #[instrument] async fn get_token(&mut self, username: &str) -> Result, sqlx::Error> { let row: Option<(String,)> = query_as( "SELECT token @@ -73,6 +77,7 @@ impl Database for SqliteDatabase { Ok(row.map(|(token_str, ..)| UserToken::from(token_str))) } + #[instrument] async fn save_token(&mut self, username: &str, token: &UserToken) -> Result<(), sqlx::Error> { query(&format!( "INSERT INTO {TABLE_USER_TOKENS}