Add more instrument macros
This commit is contained in:
parent
5bdf8d0f2d
commit
d37c09d8d9
2 changed files with 9 additions and 0 deletions
|
@ -76,6 +76,7 @@ impl UserAuthenticator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct ServerPadlockGenerator {
|
pub struct ServerPadlockGenerator {
|
||||||
secret: PadlockGenerationSecret,
|
secret: PadlockGenerationSecret,
|
||||||
}
|
}
|
||||||
|
@ -85,11 +86,13 @@ impl ServerPadlockGenerator {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub fn generate_padlock(&self, server_hash: &ServerHash) -> ServerPadlock {
|
pub fn generate_padlock(&self, server_hash: &ServerHash) -> ServerPadlock {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct UserServerKeyGenerator {
|
pub struct UserServerKeyGenerator {
|
||||||
user_authenticator: Arc<UserAuthenticator>,
|
user_authenticator: Arc<UserAuthenticator>,
|
||||||
padlock_generator: Arc<ServerPadlockGenerator>,
|
padlock_generator: Arc<ServerPadlockGenerator>,
|
||||||
|
@ -100,6 +103,7 @@ impl UserServerKeyGenerator {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub async fn generate_user_server_key(
|
pub async fn generate_user_server_key(
|
||||||
&self,
|
&self,
|
||||||
username: &str,
|
username: &str,
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::str::FromStr;
|
||||||
|
|
||||||
use secrecy::ExposeSecret;
|
use secrecy::ExposeSecret;
|
||||||
use sqlx::{query, query_as, sqlite::SqliteConnectOptions, Connection, SqliteConnection};
|
use sqlx::{query, query_as, sqlite::SqliteConnectOptions, Connection, SqliteConnection};
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
use crate::secrets::UserToken;
|
use crate::secrets::UserToken;
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ pub struct SqliteDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SqliteDatabase {
|
impl SqliteDatabase {
|
||||||
|
#[instrument]
|
||||||
pub async fn open() -> Self {
|
pub async fn open() -> Self {
|
||||||
let options = SqliteConnectOptions::from_str(DB_URI_DEFAULT)
|
let options = SqliteConnectOptions::from_str(DB_URI_DEFAULT)
|
||||||
.expect("Invalid database URI")
|
.expect("Invalid database URI")
|
||||||
|
@ -38,6 +40,7 @@ impl SqliteDatabase {
|
||||||
db
|
db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
pub async fn init(&mut self) {
|
pub async fn init(&mut self) {
|
||||||
query(&format!(
|
query(&format!(
|
||||||
"CREATE TABLE IF NOT EXISTS {TABLE_USER_TOKENS} (
|
"CREATE TABLE IF NOT EXISTS {TABLE_USER_TOKENS} (
|
||||||
|
@ -56,6 +59,7 @@ impl SqliteDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Database for SqliteDatabase {
|
impl Database for SqliteDatabase {
|
||||||
|
#[instrument]
|
||||||
async fn get_token(&mut self, username: &str) -> Result<Option<UserToken>, sqlx::Error> {
|
async fn get_token(&mut self, username: &str) -> Result<Option<UserToken>, sqlx::Error> {
|
||||||
let row: Option<(String,)> = query_as(
|
let row: Option<(String,)> = query_as(
|
||||||
"SELECT token
|
"SELECT token
|
||||||
|
@ -73,6 +77,7 @@ impl Database for SqliteDatabase {
|
||||||
Ok(row.map(|(token_str, ..)| UserToken::from(token_str)))
|
Ok(row.map(|(token_str, ..)| UserToken::from(token_str)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
async fn save_token(&mut self, username: &str, token: &UserToken) -> Result<(), sqlx::Error> {
|
async fn save_token(&mut self, username: &str, token: &UserToken) -> Result<(), sqlx::Error> {
|
||||||
query(&format!(
|
query(&format!(
|
||||||
"INSERT INTO {TABLE_USER_TOKENS}
|
"INSERT INTO {TABLE_USER_TOKENS}
|
||||||
|
|
Loading…
Reference in a new issue