diff --git a/guest_list/src/auth/mod.rs b/guest_list/src/auth/mod.rs index 86926ad..ff4fa34 100644 --- a/guest_list/src/auth/mod.rs +++ b/guest_list/src/auth/mod.rs @@ -25,7 +25,7 @@ pub(crate) mod authenticated_user; const SESSION_LIFETIME: time::Duration = time::Duration::days(30); const SIGNIN_ATTEMPT_LIFETIME: time::Duration = time::Duration::minutes(15); -pub(crate)const USER_HOME_PAGE: &str = "/apps"; +pub(crate) const USER_HOME_PAGE: &str = "/apps"; #[derive(Deserialize, Debug)] struct CreateAccountRequest { @@ -35,11 +35,11 @@ struct CreateAccountRequest { async fn create_account( State(AppState { - connection, - configuration, - client, + connection, + configuration, + client, secrets, - }): State, + }): State, Form(request): Form, ) -> impl IntoResponse { //TODO check if user already exists @@ -79,8 +79,8 @@ async fn create_account( configuration.server_url, secrets.resend_auth_token, ) - .await - .unwrap(); + .await + .unwrap(); Redirect::to("/signup/completed") } @@ -176,11 +176,11 @@ struct SignInRequest { async fn sign_in( State(AppState { - connection, - configuration, - client, - secrets - }): State, + connection, + configuration, + client, + secrets, + }): State, Form(request): Form, ) -> Redirect { // Get user id @@ -226,8 +226,8 @@ async fn sign_in( configuration.server_url, secrets.resend_auth_token, ) - .await - .unwrap(); + .await + .unwrap(); Redirect::to("/signin/completed") } diff --git a/guest_list/src/database.rs b/guest_list/src/database.rs index 8433f89..2c4c0a2 100644 --- a/guest_list/src/database.rs +++ b/guest_list/src/database.rs @@ -1,5 +1,5 @@ -use std::env; use libsql::{Builder, Connection, Database}; +use std::env; // Use local database for debugging #[cfg(debug_assertions)] @@ -9,9 +9,8 @@ async fn create_database() -> Database { #[cfg(not(debug_assertions))] async fn create_database() -> Database { - - let url = todo!("Set up loading secrets from Bitwarden"); - let token = todo!("Set up loading secrets from Bitwarden"); + let url = todo!("Set up loading secrets from Bitwarden"); + let token = todo!("Set up loading secrets from Bitwarden"); Builder::new_remote(url, token) .build() @@ -21,7 +20,6 @@ async fn create_database() -> Database { /// Creates the database and initializes it with the tables pub(super) async fn initialize_database() -> Connection { - let database = create_database().await; let connection = database.connect().unwrap(); @@ -35,4 +33,4 @@ pub(super) async fn initialize_database() -> Connection { tracing::debug!("Tables created"); connection -} \ No newline at end of file +} diff --git a/guest_list/src/email.rs b/guest_list/src/email.rs index aa3cb82..b96526d 100644 --- a/guest_list/src/email.rs +++ b/guest_list/src/email.rs @@ -1,7 +1,7 @@ -use std::sync::Arc; use axum::http::{uri, Uri}; use reqwest::Client; use serde::Serialize; +use std::sync::Arc; #[derive(Serialize, Debug)] struct SendEmailRequest { diff --git a/guest_list/src/main.rs b/guest_list/src/main.rs index ed2c5aa..07e9643 100644 --- a/guest_list/src/main.rs +++ b/guest_list/src/main.rs @@ -1,10 +1,12 @@ -use std::{env, net::Ipv4Addr, time::Duration}; use std::env::VarError; +use std::{env, net::Ipv4Addr, time::Duration}; use crate::auth::authenticated_user::AuthenticatedUser; +use crate::auth::USER_HOME_PAGE; +use crate::secrets::Secrets; use askama_axum::{IntoResponse, Template}; -use axum::{extract::State, http::Uri, response::Redirect, routing::get, Form, Router, http}; use axum::http::uri::InvalidUri; +use axum::{extract::State, http, http::Uri, response::Redirect, routing::get, Form, Router}; use dotenv::dotenv; use libsql::{named_params, Builder, Connection, Database}; use serde::{self, Deserialize}; @@ -12,12 +14,10 @@ use thiserror::Error; use tower_http::services::ServeDir; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; -use crate::auth::USER_HOME_PAGE; -use crate::secrets::Secrets; mod auth; -mod email; mod database; +mod email; mod routes; mod secrets; @@ -45,7 +45,7 @@ async fn main() -> Result<(), Error> { .with(tracing_subscriber::fmt::layer()) .init(); - let secrets = secrets::get_secrets().await?; + let secrets = secrets::get_secrets().await?; // Set up database let connection = database::initialize_database().await; @@ -92,7 +92,6 @@ async fn main() -> Result<(), Error> { Ok(()) } - #[derive(Clone)] pub(crate) struct Configuration { /// The server URL under which the server can be reached publicly for clients. @@ -100,7 +99,6 @@ pub(crate) struct Configuration { server_url: Uri, } - #[derive(Clone)] pub(crate) struct AppState { connection: Connection, @@ -109,7 +107,6 @@ pub(crate) struct AppState { secrets: Secrets, } - #[derive(Template)] #[template(path = "apps.html")] struct AppsTemplate {} @@ -118,8 +115,7 @@ async fn get_apps_page( user: AuthenticatedUser, State(app_state): State, ) -> impl IntoResponse { - - let apps_template = AppsTemplate { }; + let apps_template = AppsTemplate {}; apps_template } @@ -131,6 +127,5 @@ async fn collect_garbage(connection: Connection) { loop { interval.tick().await; let now = time::OffsetDateTime::now_utc().unix_timestamp(); - } } diff --git a/guest_list/src/routes/index.rs b/guest_list/src/routes/index.rs index d221844..fc610fe 100644 --- a/guest_list/src/routes/index.rs +++ b/guest_list/src/routes/index.rs @@ -1,6 +1,6 @@ +use crate::auth::authenticated_user::AuthenticatedUser; use askama::Template; use askama_axum::IntoResponse; -use crate::auth::authenticated_user::AuthenticatedUser; #[derive(Template)] #[template(path = "index.html")] diff --git a/guest_list/src/routes/mod.rs b/guest_list/src/routes/mod.rs index 3993d49..aae031a 100644 --- a/guest_list/src/routes/mod.rs +++ b/guest_list/src/routes/mod.rs @@ -1,2 +1 @@ pub(crate) mod index; - diff --git a/guest_list/src/secrets.rs b/guest_list/src/secrets.rs index 8b2f4f6..2ff1a58 100644 --- a/guest_list/src/secrets.rs +++ b/guest_list/src/secrets.rs @@ -1,15 +1,17 @@ // 🤫 -use std::sync::Arc; use bitwarden::auth::login::AccessTokenLoginRequest; +use bitwarden::secrets_manager::secrets::{ + SecretGetRequest, SecretIdentifiersRequest, SecretIdentifiersResponse, +}; use bitwarden::Client; -use bitwarden::secrets_manager::secrets::{SecretGetRequest, SecretIdentifiersRequest, SecretIdentifiersResponse}; use dotenv::dotenv; +use std::sync::Arc; use thiserror::Error; -use uuid::{Uuid, uuid}; +use uuid::{uuid, Uuid}; #[derive(Debug, Error)] -pub(super)enum GetSecretsError { +pub(super) enum GetSecretsError { #[cfg(debug_assertions)] #[error("Error loading dotenv file")] DotEnvError(#[from] dotenv::Error), @@ -21,10 +23,8 @@ pub(super)enum GetSecretsError { NoResendSecretId(std::env::VarError), #[error("Error parsing secret id. Is it a valid UUID?")] InvalidSecretId(#[from] uuid::Error), - } - #[derive(Clone)] pub(crate) struct Secrets { pub(crate) resend_auth_token: Arc, @@ -45,12 +45,17 @@ pub(super) async fn get_secrets() -> Result { } let token = std::env::var("BWS_TOKEN").map_err(GetSecretsError::NoBwsToken)?; - let token = AccessTokenLoginRequest { access_token: token, state_file: None }; + let token = AccessTokenLoginRequest { + access_token: token, + state_file: None, + }; client.auth().login_access_token(&token).await?; // Ids are not a secret but should still be avoided to be shared where possible (obfuscation) - let resend_secret_id = std::env::var("BWS_RESEND_SECRET_ID").map_err(GetSecretsError::NoResendSecretId)?.parse::()?; - let request = SecretGetRequest{ + let resend_secret_id = std::env::var("BWS_RESEND_SECRET_ID") + .map_err(GetSecretsError::NoResendSecretId)? + .parse::()?; + let request = SecretGetRequest { id: resend_secret_id, }; @@ -62,4 +67,3 @@ pub(super) async fn get_secrets() -> Result { Ok(secrets) } -