diff --git a/backend/src/auth_service/client_record.rs b/backend/src/auth_service/client_record.rs index f011e9ac..14ef7b4e 100644 --- a/backend/src/auth_service/client_record.rs +++ b/backend/src/auth_service/client_record.rs @@ -11,7 +11,7 @@ use phnxtypes::{ }; use sqlx::{Connection, PgConnection}; -use crate::persistence::StorageError; +use crate::errors::StorageError; use super::queue::Queue; diff --git a/backend/src/auth_service/connection_package/persistence.rs b/backend/src/auth_service/connection_package/persistence.rs index 42db5862..2e71edc9 100644 --- a/backend/src/auth_service/connection_package/persistence.rs +++ b/backend/src/auth_service/connection_package/persistence.rs @@ -10,7 +10,7 @@ use phnxtypes::{ use sqlx::{postgres::PgArguments, Arguments, Connection, PgConnection, PgExecutor}; use uuid::Uuid; -use crate::persistence::StorageError; +use crate::errors::StorageError; use super::StorableConnectionPackage; diff --git a/backend/src/auth_service/credentials/intermediate_signing_key.rs b/backend/src/auth_service/credentials/intermediate_signing_key.rs index b11f285f..771f2518 100644 --- a/backend/src/auth_service/credentials/intermediate_signing_key.rs +++ b/backend/src/auth_service/credentials/intermediate_signing_key.rs @@ -15,7 +15,7 @@ use phnxtypes::{ use serde::{Deserialize, Serialize}; use sqlx::{Connection, PgConnection}; -use crate::persistence::StorageError; +use crate::errors::StorageError; use super::{signing_key::StorableSigningKey, CredentialGenerationError}; @@ -102,7 +102,7 @@ mod persistence { }; use sqlx::PgExecutor; - use crate::{auth_service::credentials::CredentialType, persistence::StorageError}; + use crate::{auth_service::credentials::CredentialType, errors::StorageError}; use super::{IntermediateCredential, IntermediateSigningKey}; diff --git a/backend/src/auth_service/credentials/mod.rs b/backend/src/auth_service/credentials/mod.rs index 4f7b8b4a..7ffe9de2 100644 --- a/backend/src/auth_service/credentials/mod.rs +++ b/backend/src/auth_service/credentials/mod.rs @@ -5,7 +5,7 @@ use phnxtypes::crypto::errors::KeyGenerationError; use thiserror::Error; -use crate::persistence::StorageError; +use crate::errors::StorageError; pub(in crate::auth_service) mod intermediate_signing_key; pub(in crate::auth_service) mod signing_key; diff --git a/backend/src/auth_service/credentials/signing_key.rs b/backend/src/auth_service/credentials/signing_key.rs index 4e95ba75..c61167c9 100644 --- a/backend/src/auth_service/credentials/signing_key.rs +++ b/backend/src/auth_service/credentials/signing_key.rs @@ -68,7 +68,7 @@ impl StorableSigningKey { mod persistence { use phnxtypes::codec::PhnxCodec; - use crate::{auth_service::credentials::CredentialType, persistence::StorageError}; + use crate::{auth_service::credentials::CredentialType, errors::StorageError}; use super::*; diff --git a/backend/src/auth_service/mod.rs b/backend/src/auth_service/mod.rs index 63c2e499..50b1867b 100644 --- a/backend/src/auth_service/mod.rs +++ b/backend/src/auth_service/mod.rs @@ -30,7 +30,10 @@ use thiserror::Error; use tls_codec::{TlsSerialize, TlsSize}; use tokio::sync::Mutex; -use crate::persistence::{DatabaseError, InfraService, ServiceCreationError, StorageError}; +use crate::{ + errors::{DatabaseError, StorageError}, + infra_service::{InfraService, ServiceCreationError}, +}; pub mod client_api; mod client_record; diff --git a/backend/src/auth_service/opaque.rs b/backend/src/auth_service/opaque.rs index 0eefafef..3b940fcb 100644 --- a/backend/src/auth_service/opaque.rs +++ b/backend/src/auth_service/opaque.rs @@ -11,7 +11,7 @@ use opaque_ke::{ use phnxtypes::crypto::OpaqueCiphersuite; use sqlx::PgExecutor; -use crate::persistence::StorageError; +use crate::errors::StorageError; pub(super) struct OpaqueSetup(ServerSetup); diff --git a/backend/src/auth_service/queue.rs b/backend/src/auth_service/queue.rs index fe318798..641e6fc4 100644 --- a/backend/src/auth_service/queue.rs +++ b/backend/src/auth_service/queue.rs @@ -5,7 +5,7 @@ use phnxtypes::identifiers::AsClientId; use sqlx::PgConnection; -use crate::persistence::StorageError; +use crate::errors::StorageError; pub(super) struct Queue { queue_id: AsClientId, @@ -31,7 +31,7 @@ mod persistence { use sqlx::{Connection, Row}; use uuid::Uuid; - use crate::persistence::QueueError; + use crate::errors::QueueError; use super::*; diff --git a/backend/src/auth_service/user_record.rs b/backend/src/auth_service/user_record.rs index 0be790e4..12eed37d 100644 --- a/backend/src/auth_service/user_record.rs +++ b/backend/src/auth_service/user_record.rs @@ -5,7 +5,7 @@ use opaque_ke::ServerRegistration; use phnxtypes::{crypto::OpaqueCiphersuite, identifiers::QualifiedUserName}; -use crate::persistence::StorageError; +use crate::errors::StorageError; #[derive(Debug, Clone)] pub(super) struct UserRecord { @@ -46,7 +46,7 @@ mod persistence { }; use sqlx::PgExecutor; - use crate::persistence::StorageError; + use crate::errors::StorageError; use super::UserRecord; diff --git a/backend/src/ds/group_state/mod.rs b/backend/src/ds/group_state/mod.rs index b448c20e..5d772b1e 100644 --- a/backend/src/ds/group_state/mod.rs +++ b/backend/src/ds/group_state/mod.rs @@ -35,7 +35,7 @@ use sqlx::PgExecutor; use thiserror::Error; use uuid::Uuid; -use crate::persistence::StorageError; +use crate::errors::StorageError; use super::{process::ExternalCommitInfo, ReservedGroupId, GROUP_STATE_EXPIRATION}; diff --git a/backend/src/ds/group_state/persistence.rs b/backend/src/ds/group_state/persistence.rs index 2a2ae0b9..4805200b 100644 --- a/backend/src/ds/group_state/persistence.rs +++ b/backend/src/ds/group_state/persistence.rs @@ -9,7 +9,7 @@ use sqlx::{ PgExecutor, }; -use crate::persistence::StorageError; +use crate::errors::StorageError; use super::StorableDsGroupData; @@ -108,7 +108,7 @@ mod test { group_state::{EncryptedDsGroupState, StorableDsGroupData}, Ds, }, - persistence::InfraService, + infra_service::InfraService, }; #[sqlx::test] diff --git a/backend/src/ds/mod.rs b/backend/src/ds/mod.rs index a79a4d0a..444c5a9f 100644 --- a/backend/src/ds/mod.rs +++ b/backend/src/ds/mod.rs @@ -10,7 +10,7 @@ use sqlx::PgPool; use tokio::sync::Mutex; use uuid::Uuid; -use crate::persistence::{InfraService, ServiceCreationError}; +use crate::infra_service::{InfraService, ServiceCreationError}; mod add_clients; mod add_users; diff --git a/backend/src/ds/process.rs b/backend/src/ds/process.rs index 307a5256..cf41a131 100644 --- a/backend/src/ds/process.rs +++ b/backend/src/ds/process.rs @@ -177,8 +177,8 @@ use phnxtypes::{ use crate::{ ds::ReservedGroupId, + errors::StorageError, messages::intra_backend::{DsFanOutMessage, DsFanOutPayload}, - persistence::StorageError, qs::QsConnector, }; diff --git a/backend/src/errors.rs b/backend/src/errors.rs new file mode 100644 index 00000000..12d2430e --- /dev/null +++ b/backend/src/errors.rs @@ -0,0 +1,58 @@ +// SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum StorageError { + #[error(transparent)] + Database(#[from] DatabaseError), + #[error("Error deserializing column: {0}")] + Serde(#[from] phnxtypes::codec::Error), +} + +impl From for StorageError { + fn from(e: sqlx::Error) -> Self { + Self::Database(e.into()) + } +} + +impl From> for StorageError { + fn from(e: Box) -> Self { + Self::Database(e.into()) + } +} + +#[derive(Debug, Error)] +pub enum DatabaseError { + #[error(transparent)] + Sqlx(#[from] sqlx::Error), + #[error(transparent)] + Dynamic(#[from] Box), +} + +/// General error while accessing the requested queue. +#[derive(Error, Debug)] +pub(super) enum QueueError { + #[error(transparent)] + Storage(#[from] StorageError), + /// Mismatching sequence numbers. + #[error("Mismatching sequence numbers.")] + SequenceNumberMismatch, + /// Unrecoverable implementation error + #[error("Library Error")] + LibraryError, +} + +impl From for QueueError { + fn from(e: sqlx::Error) -> Self { + Self::Storage(e.into()) + } +} + +impl From for QueueError { + fn from(e: phnxtypes::codec::Error) -> Self { + Self::Storage(e.into()) + } +} diff --git a/backend/src/persistence.rs b/backend/src/infra_service.rs similarity index 50% rename from backend/src/persistence.rs rename to backend/src/infra_service.rs index d62edafc..81f40d42 100644 --- a/backend/src/persistence.rs +++ b/backend/src/infra_service.rs @@ -7,58 +7,7 @@ use phnxtypes::identifiers::Fqdn; use sqlx::{Executor, PgPool}; use thiserror::Error; -#[derive(Debug, Error)] -pub enum StorageError { - #[error(transparent)] - Database(#[from] DatabaseError), - #[error("Error deserializing column: {0}")] - Serde(#[from] phnxtypes::codec::Error), -} - -impl From for StorageError { - fn from(e: sqlx::Error) -> Self { - Self::Database(e.into()) - } -} - -impl From> for StorageError { - fn from(e: Box) -> Self { - Self::Database(e.into()) - } -} - -#[derive(Debug, Error)] -pub enum DatabaseError { - #[error(transparent)] - Sqlx(#[from] sqlx::Error), - #[error(transparent)] - Dynamic(#[from] Box), -} - -/// General error while accessing the requested queue. -#[derive(Error, Debug)] -pub(super) enum QueueError { - #[error(transparent)] - Storage(#[from] StorageError), - /// Mismatching sequence numbers. - #[error("Mismatching sequence numbers.")] - SequenceNumberMismatch, - /// Unrecoverable implementation error - #[error("Library Error")] - LibraryError, -} - -impl From for QueueError { - fn from(e: sqlx::Error) -> Self { - Self::Storage(e.into()) - } -} - -impl From for QueueError { - fn from(e: phnxtypes::codec::Error) -> Self { - Self::Storage(e.into()) - } -} +use crate::{errors::StorageError, settings::DatabaseSettings}; #[derive(Debug, Error)] pub enum ServiceCreationError { @@ -77,12 +26,13 @@ impl> From for ServiceCreationError { #[async_trait] pub trait InfraService: Sized { async fn new( - connection_string: &str, - db_name: &str, + database_settings: &DatabaseSettings, domain: Fqdn, ) -> Result { - let connection = PgPool::connect(connection_string).await?; + let connection = + PgPool::connect(&database_settings.connection_string_without_database()).await?; + let db_name = database_settings.name.as_str(); let db_exists = sqlx::query!( "select exists ( SELECT datname FROM pg_catalog.pg_database WHERE datname = $1 @@ -98,11 +48,9 @@ pub trait InfraService: Sized { .await?; } - let connection_string_with_db = format!("{}/{}", connection_string, db_name); tracing::info!("Successfully created database {}", db_name); - tracing::info!("Connecting to postgres {}", connection_string_with_db); - let db_pool = PgPool::connect(&connection_string_with_db).await?; + let db_pool = PgPool::connect(&database_settings.connection_string()).await?; Self::new_from_pool(db_pool, domain).await } diff --git a/backend/src/lib.rs b/backend/src/lib.rs index b3563a91..d6cdc735 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -6,8 +6,10 @@ pub mod auth_service; pub mod ds; +pub mod errors; +pub mod infra_service; pub mod messages; -pub mod persistence; pub mod qs; +pub mod settings; pub use mls_assist::messages::{AssistedGroupInfo, AssistedMessageOut}; diff --git a/backend/src/qs/add_package.rs b/backend/src/qs/add_package.rs index c125ebfe..d7c29e89 100644 --- a/backend/src/qs/add_package.rs +++ b/backend/src/qs/add_package.rs @@ -25,7 +25,7 @@ mod persistence { }; use sqlx::{postgres::PgArguments, Arguments, Connection, PgConnection, PgExecutor}; - use crate::persistence::StorageError; + use crate::errors::StorageError; use super::*; impl StorableEncryptedAddPackage { diff --git a/backend/src/qs/client_id_decryption_key.rs b/backend/src/qs/client_id_decryption_key.rs index 906f85ce..b2a0682b 100644 --- a/backend/src/qs/client_id_decryption_key.rs +++ b/backend/src/qs/client_id_decryption_key.rs @@ -35,7 +35,7 @@ impl StorableClientIdDecryptionKey { mod persistence { use sqlx::PgExecutor; - use crate::persistence::StorageError; + use crate::errors::StorageError; use super::StorableClientIdDecryptionKey; diff --git a/backend/src/qs/client_record.rs b/backend/src/qs/client_record.rs index 54e01e82..6cf232a0 100644 --- a/backend/src/qs/client_record.rs +++ b/backend/src/qs/client_record.rs @@ -24,8 +24,8 @@ use phnxtypes::{ }; use crate::{ + errors::StorageError, messages::intra_backend::DsFanOutPayload, - persistence::StorageError, qs::{PushNotificationError, WsNotification}, }; @@ -96,7 +96,7 @@ mod persistence { use super::*; - use crate::persistence::StorageError; + use crate::errors::StorageError; impl QsClientRecord { pub(super) async fn store( diff --git a/backend/src/qs/errors.rs b/backend/src/qs/errors.rs index 6ef72edb..61c226c0 100644 --- a/backend/src/qs/errors.rs +++ b/backend/src/qs/errors.rs @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later -use crate::persistence::StorageError; +use crate::errors::StorageError; use super::network_provider_trait::NetworkProvider; use phnxtypes::crypto::errors::{DecryptionError, KeyGenerationError}; diff --git a/backend/src/qs/mod.rs b/backend/src/qs/mod.rs index af79bb3b..b9edfd5c 100644 --- a/backend/src/qs/mod.rs +++ b/backend/src/qs/mod.rs @@ -74,8 +74,9 @@ use sqlx::PgPool; use thiserror::Error; use crate::{ + errors::StorageError, + infra_service::{InfraService, ServiceCreationError}, messages::intra_backend::DsFanOutMessage, - persistence::{InfraService, ServiceCreationError, StorageError}, }; mod add_package; diff --git a/backend/src/qs/queue.rs b/backend/src/qs/queue.rs index d8038e3a..740452c7 100644 --- a/backend/src/qs/queue.rs +++ b/backend/src/qs/queue.rs @@ -5,7 +5,7 @@ use phnxtypes::{codec::PhnxCodec, identifiers::QsClientId, messages::QueueMessage}; use sqlx::{Connection, PgConnection, PgExecutor}; -use crate::persistence::{QueueError, StorageError}; +use crate::errors::{QueueError, StorageError}; pub(super) struct Queue { queue_id: QsClientId, diff --git a/backend/src/qs/signing_key.rs b/backend/src/qs/signing_key.rs index 983c92a4..8da50bdb 100644 --- a/backend/src/qs/signing_key.rs +++ b/backend/src/qs/signing_key.rs @@ -33,7 +33,7 @@ impl StorableQsSigningKey { } mod persistence { - use crate::persistence::StorageError; + use crate::errors::StorageError; use super::*; diff --git a/backend/src/qs/user_record.rs b/backend/src/qs/user_record.rs index 1e8f060a..4cf85f61 100644 --- a/backend/src/qs/user_record.rs +++ b/backend/src/qs/user_record.rs @@ -7,7 +7,7 @@ use phnxtypes::{ }; use sqlx::PgExecutor; -use crate::persistence::StorageError; +use crate::errors::StorageError; #[derive(Debug, Clone, PartialEq)] pub(super) struct UserRecord { @@ -37,7 +37,7 @@ mod persistence { use phnxtypes::identifiers::QsUserId; use sqlx::PgExecutor; - use crate::persistence::StorageError; + use crate::errors::StorageError; use super::*; diff --git a/backend/src/settings.rs b/backend/src/settings.rs new file mode 100644 index 00000000..85f6a2ab --- /dev/null +++ b/backend/src/settings.rs @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: 2024 Phoenix R&D GmbH +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use serde::Deserialize; + +/// Configuration for the server. +#[derive(Deserialize, Clone, Debug)] +pub struct Settings { + pub database: DatabaseSettings, + pub application: ApplicationSettings, + // If this isn't present, the provider will not send push notifications to + // apple devices. + pub apns: Option, +} + +/// Configuration for the application. +#[derive(serde::Deserialize, Clone, Debug)] +pub struct ApplicationSettings { + pub port: u16, + pub host: String, + pub domain: String, +} + +/// Configuration for the database. +#[derive(Deserialize, Clone, Debug)] +pub struct DatabaseSettings { + pub username: String, + pub password: String, + pub port: u16, + pub host: String, + pub name: String, + pub cacertpath: Option, +} + +#[derive(Debug, Deserialize, Clone)] +pub struct ApnsSettings { + pub keyid: String, + pub teamid: String, + pub privatekeypath: String, +} + +impl DatabaseSettings { + /// Add the TLS mode to the connection string if the CA certificate path is + /// set. + fn add_tls_mode(&self, mut connection_string: String) -> String { + if let Some(ref ca_cert_path) = self.cacertpath { + connection_string.push_str(&format!("?sslmode=verify-ca&sslrootcert={}", ca_cert_path)); + } + connection_string + } + + /// Get the connection string for the database. + pub fn connection_string(&self) -> String { + let connection_string = format!( + "postgres://{}:{}@{}:{}/{}", + self.username, self.password, self.host, self.port, self.name + ); + self.add_tls_mode(connection_string) + } + + /// Get the connection string for the database without the database name. + pub fn connection_string_without_database(&self) -> String { + let connection_string = format!( + "postgres://{}:{}@{}:{}", + self.username, self.password, self.host, self.port + ); + self.add_tls_mode(connection_string) + } +} diff --git a/server/src/configurations.rs b/server/src/configurations.rs index 40b8392c..2c1ac0d5 100644 --- a/server/src/configurations.rs +++ b/server/src/configurations.rs @@ -3,72 +3,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later use config::{Config, ConfigError}; -use serde::Deserialize; - -/// Configuration for the server. -#[derive(Deserialize, Clone, Debug)] -pub struct Settings { - pub database: DatabaseSettings, - pub application: ApplicationSettings, - // If this isn't present, the provider will not send push notifications to - // apple devices. - pub apns: Option, -} - -/// Configuration for the application. -#[derive(serde::Deserialize, Clone, Debug)] -pub struct ApplicationSettings { - pub port: u16, - pub host: String, - pub domain: String, -} - -/// Configuration for the database. -#[derive(Deserialize, Clone, Debug)] -pub struct DatabaseSettings { - pub username: String, - pub password: String, - pub port: u16, - pub host: String, - pub name: String, - pub cacertpath: Option, -} - -#[derive(Debug, Deserialize, Clone)] -pub struct ApnsSettings { - pub keyid: String, - pub teamid: String, - pub privatekeypath: String, -} - -impl DatabaseSettings { - /// Add the TLS mode to the connection string if the CA certificate path is - /// set. - fn add_tls_mode(&self, mut connection_string: String) -> String { - if let Some(ref ca_cert_path) = self.cacertpath { - connection_string.push_str(&format!("?sslmode=verify-ca&sslrootcert={}", ca_cert_path)); - } - connection_string - } - - /// Get the connection string for the database. - pub fn connection_string(&self) -> String { - let connection_string = format!( - "postgres://{}:{}@{}:{}/{}", - self.username, self.password, self.host, self.port, self.name - ); - self.add_tls_mode(connection_string) - } - - /// Get the connection string for the database without the database name. - pub fn connection_string_without_database(&self) -> String { - let connection_string = format!( - "postgres://{}:{}@{}:{}", - self.username, self.password, self.host, self.port - ); - self.add_tls_mode(connection_string) - } -} +use phnxbackend::settings::Settings; /// The possible runtime environment for our application. pub enum Environment { diff --git a/server/src/endpoints/qs/push_notification_provider.rs b/server/src/endpoints/qs/push_notification_provider.rs index ebf5641b..cb33d14f 100644 --- a/server/src/endpoints/qs/push_notification_provider.rs +++ b/server/src/endpoints/qs/push_notification_provider.rs @@ -4,7 +4,10 @@ use async_trait::async_trait; use jsonwebtoken::{encode, Algorithm, EncodingKey, Header}; -use phnxbackend::qs::{PushNotificationError, PushNotificationProvider}; +use phnxbackend::{ + qs::{PushNotificationError, PushNotificationProvider}, + settings::ApnsSettings, +}; use phnxtypes::messages::push_token::{PushToken, PushTokenOperator}; use reqwest::{Client, StatusCode}; use serde::{Deserialize, Serialize}; @@ -15,8 +18,6 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; -use crate::configurations::ApnsSettings; - #[derive(Debug, Serialize, Deserialize)] struct Claims { iss: String, diff --git a/server/src/main.rs b/server/src/main.rs index 8c508c86..578f6be7 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -4,7 +4,7 @@ use std::net::TcpListener; -use phnxbackend::{auth_service::AuthService, ds::Ds, persistence::InfraService, qs::Qs}; +use phnxbackend::{auth_service::AuthService, ds::Ds, infra_service::InfraService, qs::Qs}; use phnxserver::{ configurations::*, endpoints::qs::{ @@ -53,12 +53,7 @@ async fn main() -> std::io::Result<()> { configuration.database.host ); let mut counter = 0; - let mut ds_result = Ds::new( - &configuration.database.connection_string_without_database(), - &configuration.database.name, - domain.clone(), - ) - .await; + let mut ds_result = Ds::new(&configuration.database, domain.clone()).await; // Try again for 10 times each second in case the postgres server is coming up. while let Err(e) = ds_result { @@ -68,35 +63,22 @@ async fn main() -> std::io::Result<()> { if counter > 10 { panic!("Database not ready after 10 seconds."); } - ds_result = Ds::new( - &configuration.database.connection_string_without_database(), - &configuration.database.name, - domain.clone(), - ) - .await; + ds_result = Ds::new(&configuration.database, domain.clone()).await; } let ds = ds_result.unwrap(); // New database name for the QS provider configuration.database.name = format!("{}_qs", base_db_name); // QS storage provider - let qs = Qs::new( - &configuration.database.connection_string_without_database(), - &configuration.database.name, - domain.clone(), - ) - .await - .expect("Failed to connect to database."); + let qs = Qs::new(&configuration.database, domain.clone()) + .await + .expect("Failed to connect to database."); // New database name for the AS provider configuration.database.name = format!("{}_as", base_db_name); - let auth_service = AuthService::new( - &configuration.database.connection_string_without_database(), - &configuration.database.name, - domain.clone(), - ) - .await - .expect("Failed to connect to database."); + let auth_service = AuthService::new(&configuration.database, domain.clone()) + .await + .expect("Failed to connect to database."); let ws_dispatch_notifier = DispatchWebsocketNotifier::default_addr(); let push_notification_provider = ProductionPushNotificationProvider::new(configuration.apns) diff --git a/test_harness/src/utils/mod.rs b/test_harness/src/utils/mod.rs index 272a2616..9ae4714e 100644 --- a/test_harness/src/utils/mod.rs +++ b/test_harness/src/utils/mod.rs @@ -9,7 +9,7 @@ use std::net::{SocketAddr, TcpListener}; pub mod setup; use once_cell::sync::Lazy; -use phnxbackend::{auth_service::AuthService, ds::Ds, persistence::InfraService, qs::Qs}; +use phnxbackend::{auth_service::AuthService, ds::Ds, infra_service::InfraService, qs::Qs}; use phnxserver::{ configurations::get_configuration, endpoints::qs::{ @@ -64,35 +64,23 @@ pub async fn spawn_app( let ws_dispatch_notifier = DispatchWebsocketNotifier::default_addr(); // DS storage provider - let ds = Ds::new( - &configuration.database.connection_string_without_database(), - &configuration.database.name, - domain.clone(), - ) - .await - .expect("Failed to connect to database."); + let ds = Ds::new(&configuration.database, domain.clone()) + .await + .expect("Failed to connect to database."); // New database name for the AS provider configuration.database.name = Uuid::new_v4().to_string(); - let auth_service = AuthService::new( - &configuration.database.connection_string_without_database(), - &configuration.database.name, - domain.clone(), - ) - .await - .expect("Failed to connect to database."); + let auth_service = AuthService::new(&configuration.database, domain.clone()) + .await + .expect("Failed to connect to database."); // New database name for the QS provider configuration.database.name = Uuid::new_v4().to_string(); - let qs = Qs::new( - &configuration.database.connection_string_without_database(), - &configuration.database.name, - domain.clone(), - ) - .await - .expect("Failed to connect to database."); + let qs = Qs::new(&configuration.database, domain.clone()) + .await + .expect("Failed to connect to database."); let push_notification_provider = ProductionPushNotificationProvider::new(None).unwrap();