Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notifications): add email client #4002

Merged
merged 17 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
a906fae
feat(notifications): boilerplate for email client
thevaibhav-dixit Feb 15, 2024
a6b2ccd
chore(deps): add openssl to flake.nix
thevaibhav-dixit Feb 15, 2024
283e570
chore(notifications): some more boilerplate
thevaibhav-dixit Feb 15, 2024
9ae5995
chore(notifications): remove option on EMAIL_PASSWORD
thevaibhav-dixit Feb 15, 2024
0a97039
chore(notifications): remove dependency on openssl
thevaibhav-dixit Feb 15, 2024
169269f
chore(notifications): add Email as new notification channel
thevaibhav-dixit Feb 15, 2024
875971e
chore(notifications): rename lettre to smtp
thevaibhav-dixit Feb 15, 2024
45909ba
chore(notifications): remove Email from UserNotificationChannel
thevaibhav-dixit Feb 15, 2024
26c975a
chore(notifications): pass email_executor config in notifications.yml
thevaibhav-dixit Feb 16, 2024
244c106
chore(notifications): remove password from notifications.yml
thevaibhav-dixit Feb 16, 2024
0816c57
chore(notifications): complete the logic for sending email
thevaibhav-dixit Feb 18, 2024
216d215
chore(notifications): rename executor -> push_executor in app config
thevaibhav-dixit Feb 19, 2024
9d6313c
chore(notifications): provide default value of EMAIL_PASSWORD
thevaibhav-dixit Feb 19, 2024
5cc1373
chore(notifications): fix deps
UncleSamtoshi Feb 19, 2024
32b9f41
chore(notifications): do not send emails
UncleSamtoshi Feb 19, 2024
fb853aa
chore(notifications): rename messages
UncleSamtoshi Feb 19, 2024
2992369
chore(notifications): add LocalizedEmail
UncleSamtoshi Feb 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 132 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ prost = "0.12"
rust-i18n = "3"
google-fcm1 = "5.0.3"
sqlxmq = { version = "0.5", default-features = false, features = ["runtime-tokio-rustls"] }
lettre = { version = "0.11.4", default-features = false, features = ["builder", "tokio1", "tokio1-rustls-tls", "smtp-transport"] }

1 change: 1 addition & 0 deletions core/notifications/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ galoy_rust_bin(
"//third-party/rust:prost",
"//third-party/rust:rust-i18n",
"//third-party/rust:google-fcm1",
"//third-party/rust:lettre",
],
extra_tests = [
"//lib/tracing-rs:tracing",
Expand Down
1 change: 1 addition & 0 deletions core/notifications/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ tonic-health = { workspace = true }
prost = { workspace = true }
rust-i18n = { workspace = true }
google-fcm1 = { workspace = true }
lettre = { workspace = true }

[build-dependencies]
tonic-build = { workspace = true }
7 changes: 6 additions & 1 deletion core/notifications/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
# grpc_server:
# port: 6685
app:
executor:
push_executor:
fcm:
google_application_credentials_path: "./config/notifications/fake_service_account.json"
email_executor:
smtp:
username: ""
from_email: ""
relay: ""
# kratos_import:
# execute_import: true
5 changes: 3 additions & 2 deletions core/notifications/src/app/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use serde::{Deserialize, Serialize};

use crate::push_executor::PushExecutorConfig;
use crate::{email_executor::EmailExecutorConfig, push_executor::PushExecutorConfig};

#[derive(Clone, Default, Serialize, Deserialize)]
pub struct AppConfig {
pub executor: PushExecutorConfig,
pub push_executor: PushExecutorConfig,
pub email_executor: EmailExecutorConfig,
}
5 changes: 4 additions & 1 deletion core/notifications/src/app/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use thiserror::Error;

use crate::{
job::error::JobError, push_executor::error::PushExecutorError,
email_executor::error::EmailExecutorError, job::error::JobError,
push_executor::error::PushExecutorError,
user_notification_settings::error::UserNotificationSettingsError,
};

Expand All @@ -14,5 +15,7 @@ pub enum ApplicationError {
#[error("{0}")]
PushExecutorError(#[from] PushExecutorError),
#[error("{0}")]
EmailExecutorError(#[from] EmailExecutorError),
#[error("{0}")]
Sqlx(#[from] sqlx::Error),
}
12 changes: 9 additions & 3 deletions core/notifications/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use tracing::instrument;
use std::sync::Arc;

use crate::{
job, notification_event::*, primitives::*, push_executor::*, user_notification_settings::*,
email_executor::EmailExecutor, job, notification_event::*, primitives::*, push_executor::*,
user_notification_settings::*,
};

pub use config::*;
Expand All @@ -25,8 +26,10 @@ pub struct NotificationsApp {
impl NotificationsApp {
pub async fn init(pool: Pool<Postgres>, config: AppConfig) -> Result<Self, ApplicationError> {
let settings = UserNotificationSettingsRepo::new(&pool);
let executor = PushExecutor::init(config.executor.clone(), settings.clone()).await?;
let runner = job::start_job_runner(&pool, executor).await?;
let push_executor =
PushExecutor::init(config.push_executor.clone(), settings.clone()).await?;
let email_executor = EmailExecutor::init(config.email_executor.clone(), settings.clone())?;
let runner = job::start_job_runner(&pool, push_executor, email_executor).await?;
Ok(Self {
_config: config,
pool,
Expand Down Expand Up @@ -173,6 +176,9 @@ impl NotificationsApp {
event: T,
) -> Result<(), ApplicationError> {
let mut tx = self.pool.begin().await?;
if event.should_send_email() {
job::spawn_send_email_notification(&mut tx, event.clone().into()).await?;
}
job::spawn_send_push_notification(&mut tx, event.into()).await?;
tx.commit().await?;
Ok(())
Expand Down
5 changes: 4 additions & 1 deletion core/notifications/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ fn default_tracing_config() -> TracingConfig {
pub struct EnvOverride {
pub db_con: String,
pub kratos_pg_con: Option<String>,
pub email_password: String,
}

impl Config {
pub fn from_path(
path: Option<impl AsRef<Path>>,
EnvOverride {
db_con,
email_password,
kratos_pg_con,
}: EnvOverride,
) -> anyhow::Result<Self> {
Expand All @@ -53,8 +55,9 @@ impl Config {
};
config.db.pg_con = db_con;
config.kratos_import.pg_con = kratos_pg_con;
config.app.email_executor.smtp.password = email_password;

config.app.executor.fcm.load_creds()?;
config.app.push_executor.fcm.load_creds()?;

Ok(config)
}
Expand Down
Loading
Loading