feat(email): integrate email service using AWS SES (#1158)

This commit is contained in:
Chethan Rao
2023-05-17 15:12:32 +05:30
committed by GitHub
parent ea98145318
commit 07e0fcbe06
9 changed files with 226 additions and 33 deletions

View File

@ -7,6 +7,8 @@ use std::{
use api_models::enums;
use common_utils::ext_traits::ConfigExt;
use config::{Environment, File};
#[cfg(feature = "email")]
use external_services::email::EmailSettings;
#[cfg(feature = "kms")]
use external_services::kms;
use redis_interface::RedisSettings;
@ -69,6 +71,8 @@ pub struct Settings {
pub connector_customer: ConnectorCustomer,
#[cfg(feature = "dummy_connector")]
pub dummy_connector: DummyConnector,
#[cfg(feature = "email")]
pub email: EmailSettings,
}
#[derive(Debug, Deserialize, Clone, Default)]

View File

@ -1,4 +1,6 @@
use actix_web::{web, Scope};
#[cfg(feature = "email")]
use external_services::email::{AwsSes, EmailClient};
use tokio::sync::oneshot;
#[cfg(feature = "dummy_connector")]
@ -22,12 +24,16 @@ pub struct AppState {
pub flow_name: String,
pub store: Box<dyn StorageInterface>,
pub conf: Settings,
#[cfg(feature = "email")]
pub email_client: Box<dyn EmailClient>,
}
pub trait AppStateInfo {
fn conf(&self) -> Settings;
fn flow_name(&self) -> String;
fn store(&self) -> Box<dyn StorageInterface>;
#[cfg(feature = "email")]
fn email_client(&self) -> Box<dyn EmailClient>;
}
impl AppStateInfo for AppState {
@ -40,6 +46,10 @@ impl AppStateInfo for AppState {
fn store(&self) -> Box<dyn StorageInterface> {
self.store.to_owned()
}
#[cfg(feature = "email")]
fn email_client(&self) -> Box<dyn EmailClient> {
self.email_client.to_owned()
}
}
impl AppState {
@ -56,10 +66,15 @@ impl AppState {
StorageImpl::Mock => Box::new(MockDb::new(&conf).await),
};
#[cfg(feature = "email")]
#[allow(clippy::expect_used)]
let email_client = Box::new(AwsSes::new(&conf.email).await);
Self {
flow_name: String::from("default"),
store,
conf,
#[cfg(feature = "email")]
email_client,
}
}