move secrets to secrets.rs

This commit is contained in:
deneb 2024-02-10 12:32:01 +01:00
parent e4aa6c1909
commit 399ed56b74
5 changed files with 25 additions and 21 deletions

View file

@ -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<String> for Password {
fn from(value: String) -> Self {
Self(SecretString::new(value))
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct UserToken(pub SecretString);
impl From<String> for UserToken {
fn from(value: String) -> Self {
Self(SecretString::new(value))
}
}
use crate::{
db::{Database, SqliteDatabase},
secrets::{Password, UserToken},
};
#[derive(Debug)]
pub struct Authenticator<DB: Database> {

View file

@ -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";

View file

@ -21,6 +21,7 @@
mod auth;
mod db;
mod secrets;
mod server;
use color_eyre::Result;

18
src/secrets.rs Normal file
View file

@ -0,0 +1,18 @@
use secrecy::SecretString;
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct Password(pub SecretString);
impl From<String> for Password {
fn from(value: String) -> Self {
Self(SecretString::new(value))
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct UserToken(pub SecretString);
impl From<String> for UserToken {
fn from(value: String) -> Self {
Self(SecretString::new(value))
}
}

View file

@ -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<()> {