From 399ed56b74b60b5a79a0383fc9b51b3ee27a84f8 Mon Sep 17 00:00:00 2001 From: DenebTM Date: Sat, 10 Feb 2024 12:32:01 +0100 Subject: [PATCH] move secrets to secrets.rs --- src/auth.rs | 22 ++++------------------ src/db.rs | 3 +-- src/main.rs | 1 + src/secrets.rs | 18 ++++++++++++++++++ src/server.rs | 2 +- 5 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 src/secrets.rs diff --git a/src/auth.rs b/src/auth.rs index cd79d0d..eeec448 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,26 +1,12 @@ -use secrecy::SecretString; -use serde::Deserialize; use std::sync::Arc; use tokio::sync::Mutex; use tracing::instrument; -use crate::db::{Database, SqliteDatabase}; -#[derive(Debug, Clone, Deserialize)] -pub struct Password(pub SecretString); -impl From for Password { - fn from(value: String) -> Self { - Self(SecretString::new(value)) - } -} - -#[derive(Debug, Clone, Deserialize)] -pub struct UserToken(pub SecretString); -impl From for UserToken { - fn from(value: String) -> Self { - Self(SecretString::new(value)) - } -} +use crate::{ + db::{Database, SqliteDatabase}, + secrets::{Password, UserToken}, +}; #[derive(Debug)] pub struct Authenticator { diff --git a/src/db.rs b/src/db.rs index 045bcd1..7a1b71e 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,7 +1,6 @@ -use secrecy::SecretString; use sqlx::{query, query_as, Connection, SqliteConnection}; -use crate::auth::UserToken; +use crate::secrets::UserToken; // TODO: allow configuring this via envar const DB_URI_DEFAULT: &str = "sqlite://sqlite.db"; diff --git a/src/main.rs b/src/main.rs index ca00b12..88314bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ mod auth; mod db; +mod secrets; mod server; use color_eyre::Result; diff --git a/src/secrets.rs b/src/secrets.rs new file mode 100644 index 0000000..e2a93fb --- /dev/null +++ b/src/secrets.rs @@ -0,0 +1,18 @@ +use secrecy::SecretString; +use serde::Deserialize; + +#[derive(Debug, Clone, Deserialize)] +pub struct Password(pub SecretString); +impl From for Password { + fn from(value: String) -> Self { + Self(SecretString::new(value)) + } +} + +#[derive(Debug, Clone, Deserialize)] +pub struct UserToken(pub SecretString); +impl From for UserToken { + fn from(value: String) -> Self { + Self(SecretString::new(value)) + } +} diff --git a/src/server.rs b/src/server.rs index 8b3a6f1..bbb9e3c 100644 --- a/src/server.rs +++ b/src/server.rs @@ -6,7 +6,7 @@ use axum::{ use serde::{Deserialize, Serialize}; use tracing::{event, instrument, Level}; -use crate::auth::Password; +use crate::secrets::Password; #[instrument] pub async fn run() -> color_eyre::Result<()> {