pub mod admin; pub mod authn; use crate::client::{ email, sqldb::{PgClient, SqliteClient}, }; use crate::{AuthEmail, AuthStore, Secd, SecdError}; use log::error; use std::sync::Arc; impl Secd { /// init /// /// Initialize SecD with the specified configuration, established the necessary /// constraints, persistance stores, and options. pub async fn init( auth_store: AuthStore, conn_string: Option<&str>, email_messenger: AuthEmail, email_template_login: Option, email_template_signup: Option, ) -> Result { let store = match auth_store { AuthStore::Sqlite => { SqliteClient::new( sqlx::sqlite::SqlitePoolOptions::new() .connect(conn_string.unwrap_or("sqlite::memory:".into())) .await .map_err(|e| SecdError::InitializationFailure(e))?, ) .await } AuthStore::Postgres => { PgClient::new( sqlx::postgres::PgPoolOptions::new() .connect(conn_string.expect("No postgres connection string provided.")) .await .map_err(|e| SecdError::InitializationFailure(e))?, ) .await } rest @ _ => { error!( "requested an AuthStore which has not yet been implemented: {:?}", rest ); unimplemented!() } }; let email_sender = match email_messenger { // TODO: initialize email and SMS templates with secd AuthEmail::LocalStub => email::LocalEmailStubber { email_template_login, email_template_signup, }, _ => unimplemented!(), }; Ok(Secd { store, email_messenger: Arc::new(email_sender), }) } }