Skip to content

Commit

Permalink
Rewrite all http transport plugins with SimpleTransportWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
GamePad64 committed Dec 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent a3fe5f7 commit a4497ed
Showing 17 changed files with 267 additions and 500 deletions.
1 change: 1 addition & 0 deletions .idea/notifico.iml

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

30 changes: 17 additions & 13 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ members = [
"notifico-project/migration",
"notifico-web",
"notifico-ingest",
"notificox", "transports/notifico-gotify",
"notificox", "transports/notifico-gotify", "notifico-transports",
]

[workspace.dependencies]
16 changes: 16 additions & 0 deletions notifico-transports/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "notifico-transports"
version = "0.1.0"
edition = "2021"

[dependencies]
notifico-core = { path = "../notifico-core" }
notifico-template = { path = "../notifico-template" }
# Transports
notifico-telegram = { path = "../transports/notifico-telegram" }
notifico-smtp = { path = "../transports/notifico-smtp" }
notifico-whatsapp = { path = "../transports/notifico-whatsapp" }
notifico-smpp = { path = "../transports/notifico-smpp" }
notifico-slack = { path = "../transports/notifico-slack" }
notifico-pushover = { path = "../transports/notifico-pushover" }
notifico-gotify = { path = "../transports/notifico-gotify" }
72 changes: 72 additions & 0 deletions notifico-transports/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use notifico_core::credentials::CredentialStorage;
use notifico_core::engine::EnginePlugin;
use notifico_core::recorder::Recorder;
use notifico_core::simpletransport::SimpleTransportWrapper;
use notifico_core::transport::Transport;
use notifico_gotify::GotifyTransport;
use notifico_pushover::PushoverTransport;
use notifico_slack::SlackTransport;
use notifico_smpp::SmppPlugin;
use notifico_smtp::EmailPlugin;
use notifico_telegram::TelegramTransport;
use notifico_whatsapp::WabaTransport;
use std::sync::Arc;

pub fn all_transports(
credentials: Arc<dyn CredentialStorage>,
recorder: Arc<dyn Recorder>,
) -> Vec<(Arc<dyn EnginePlugin>, Arc<dyn Transport>)> {
let mut plugins: Vec<(Arc<dyn EnginePlugin>, Arc<dyn Transport>)> = vec![];

// Complicated transports
let email_plugin = Arc::new(EmailPlugin::new(credentials.clone(), recorder.clone()));
plugins.push((email_plugin.clone(), email_plugin.clone()));

let smpp_plugin = Arc::new(SmppPlugin::new(credentials.clone()));
plugins.push((smpp_plugin.clone(), smpp_plugin.clone()));

// Simple transports
let telegram_transport = Arc::new(TelegramTransport::new());
let telegram_plugin = Arc::new(SimpleTransportWrapper::new(
telegram_transport,
credentials.clone(),
recorder.clone(),
));
plugins.push((telegram_plugin.clone(), telegram_plugin.clone()));

let waba_transport = Arc::new(WabaTransport::new());
let waba_plugin = Arc::new(SimpleTransportWrapper::new(
waba_transport,
credentials.clone(),
recorder.clone(),
));
plugins.push((waba_plugin.clone(), waba_plugin.clone()));

let slack_transport = Arc::new(SlackTransport::new());
let slack_plugin = Arc::new(SimpleTransportWrapper::new(
slack_transport,
credentials.clone(),
recorder.clone(),
));
plugins.push((slack_plugin.clone(), slack_plugin.clone()));

let pushover_transport = Arc::new(PushoverTransport::new());
let pushover_plugin = Arc::new(SimpleTransportWrapper::new(
pushover_transport,
credentials.clone(),
recorder.clone(),
));
plugins.push((pushover_plugin.clone(), pushover_plugin.clone()));

let gotify_transport = Arc::new(GotifyTransport::new());
let gotify_plugin = Arc::new(SimpleTransportWrapper::new(
gotify_transport,
credentials.clone(),
recorder.clone(),
));
plugins.push((gotify_plugin.clone(), gotify_plugin.clone()));

// Add more transports here...

plugins
}
7 changes: 1 addition & 6 deletions notifico-worker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -5,12 +5,7 @@ edition = "2021"

[dependencies]
notifico-core = { path = "../notifico-core" }
notifico-telegram = { path = "../transports/notifico-telegram" }
notifico-smtp = { path = "../transports/notifico-smtp" }
notifico-whatsapp = { path = "../transports/notifico-whatsapp" }
notifico-smpp = { path = "../transports/notifico-smpp" }
notifico-slack = { path = "../transports/notifico-slack" }
notifico-pushover = { path = "../transports/notifico-pushover" }
notifico-transports = { path = "../notifico-transports" }

notifico-template = { path = "../notifico-template" }
notifico-subscription = { path = "../notifico-subscription" }
34 changes: 7 additions & 27 deletions notifico-worker/src/main.rs
Original file line number Diff line number Diff line change
@@ -12,16 +12,12 @@ use notifico_core::pipeline::event::EventHandler;
use notifico_core::pipeline::executor::PipelineExecutor;
use notifico_core::queue::ReceiverChannel;
use notifico_core::recorder::BaseRecorder;
use notifico_core::transport::TransportRegistry;
use notifico_dbpipeline::DbPipelineStorage;
use notifico_pushover::PushoverPlugin;
use notifico_slack::SlackPlugin;
use notifico_smpp::SmppPlugin;
use notifico_smtp::EmailPlugin;
use notifico_subscription::SubscriptionManager;
use notifico_telegram::TelegramPlugin;
use notifico_template::db::DbTemplateSource;
use notifico_template::Templater;
use notifico_whatsapp::WaBusinessPlugin;
use notifico_transports::all_transports;
use sea_orm::{ConnectOptions, Database};
use std::path::PathBuf;
use std::sync::Arc;
@@ -115,27 +111,11 @@ async fn main() {
let templater_source = Arc::new(DbTemplateSource::new(db_connection.clone()));
engine.add_plugin(Arc::new(Templater::new(templater_source.clone())));

engine.add_plugin(Arc::new(TelegramPlugin::new(
credentials.clone(),
recorder.clone(),
)));
engine.add_plugin(Arc::new(EmailPlugin::new(
credentials.clone(),
recorder.clone(),
)));
engine.add_plugin(Arc::new(WaBusinessPlugin::new(
credentials.clone(),
recorder.clone(),
)));
engine.add_plugin(Arc::new(SmppPlugin::new(credentials.clone())));
engine.add_plugin(Arc::new(SlackPlugin::new(
credentials.clone(),
recorder.clone(),
)));
engine.add_plugin(Arc::new(PushoverPlugin::new(
credentials.clone(),
recorder.clone(),
)));
let mut transport_registry = TransportRegistry::new();
for (engine_plugin, transport_plugin) in all_transports(credentials.clone(), recorder.clone()) {
engine.add_plugin(engine_plugin);
transport_registry.register(transport_plugin);
}

let subman = Arc::new(SubscriptionManager::new(
db_connection,
9 changes: 1 addition & 8 deletions notificox/Cargo.toml
Original file line number Diff line number Diff line change
@@ -6,14 +6,7 @@ edition = "2021"
[dependencies]
notifico-core = { path = "../notifico-core" }
notifico-template = { path = "../notifico-template" }
# Transports
notifico-telegram = { path = "../transports/notifico-telegram" }
notifico-smtp = { path = "../transports/notifico-smtp" }
notifico-whatsapp = { path = "../transports/notifico-whatsapp" }
notifico-smpp = { path = "../transports/notifico-smpp" }
notifico-slack = { path = "../transports/notifico-slack" }
notifico-pushover = { path = "../transports/notifico-pushover" }
notifico-gotify = { path = "../transports/notifico-gotify" }
notifico-transports = { path = "../notifico-transports" }
# Other deps
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.133"
65 changes: 9 additions & 56 deletions notificox/src/main.rs
Original file line number Diff line number Diff line change
@@ -2,27 +2,20 @@ use clap::{Parser, Subcommand};
use log::info;
use notifico_core::config::credentials::MemoryCredentialStorage;
use notifico_core::contact::Contact;
use notifico_core::credentials::{Credential, CredentialStorage};
use notifico_core::credentials::Credential;
use notifico_core::engine::plugin::core::CorePlugin;
use notifico_core::engine::Engine;
use notifico_core::pipeline::event::{EventHandler, ProcessEventRequest, RecipientSelector};
use notifico_core::pipeline::executor::PipelineExecutor;
use notifico_core::pipeline::storage::SinglePipelineStorage;
use notifico_core::pipeline::Pipeline;
use notifico_core::recipient::Recipient;
use notifico_core::recorder::{BaseRecorder, Recorder};
use notifico_core::simpletransport::SimpleTransportWrapper;
use notifico_core::recorder::BaseRecorder;
use notifico_core::step::SerializedStep;
use notifico_core::transport::TransportRegistry;
use notifico_gotify::GotifyTransport;
use notifico_pushover::PushoverPlugin;
use notifico_slack::SlackPlugin;
use notifico_smpp::SmppPlugin;
use notifico_smtp::EmailPlugin;
use notifico_telegram::TelegramPlugin;
use notifico_template::source::DummyTemplateSource;
use notifico_template::Templater;
use notifico_whatsapp::WaBusinessPlugin;
use notifico_transports::all_transports;
use serde_json::{json, Map, Value};
use std::sync::Arc;
use tokio::task::JoinSet;
@@ -89,12 +82,12 @@ async fn main() {
Arc::new(credentials)
};

add_transports(
&mut engine,
&mut transport_registry,
credentials.clone(),
recorder.clone(),
);
for (engine_plugin, transport_plugin) in
all_transports(credentials.clone(), recorder.clone())
{
engine.add_plugin(engine_plugin);
transport_registry.register(transport_plugin);
}

let pipeline = {
let mut pipeline = Pipeline {
@@ -189,43 +182,3 @@ async fn main() {
}
}
}

fn add_transports(
engine: &mut Engine,
transport_registry: &mut TransportRegistry,
credentials: Arc<dyn CredentialStorage>,
recorder: Arc<dyn Recorder>,
) {
let telegram_plugin = Arc::new(TelegramPlugin::new(credentials.clone(), recorder.clone()));
engine.add_plugin(telegram_plugin.clone());
transport_registry.register(telegram_plugin);

let email_plugin = Arc::new(EmailPlugin::new(credentials.clone(), recorder.clone()));
engine.add_plugin(email_plugin.clone());
transport_registry.register(email_plugin);

let whatsapp_plugin = Arc::new(WaBusinessPlugin::new(credentials.clone(), recorder.clone()));
engine.add_plugin(whatsapp_plugin.clone());
transport_registry.register(whatsapp_plugin);

let smpp_plugin = Arc::new(SmppPlugin::new(credentials.clone()));
engine.add_plugin(smpp_plugin.clone());
transport_registry.register(smpp_plugin);

let slack_plugin = Arc::new(SlackPlugin::new(credentials.clone(), recorder.clone()));
engine.add_plugin(slack_plugin.clone());
transport_registry.register(slack_plugin);

let pushover_plugin = Arc::new(PushoverPlugin::new(credentials.clone(), recorder.clone()));
engine.add_plugin(pushover_plugin.clone());
transport_registry.register(pushover_plugin);

let gotify_transport = Arc::new(GotifyTransport::new());
let gotify_plugin = Arc::new(SimpleTransportWrapper::new(
gotify_transport.clone(),
credentials.clone(),
recorder.clone(),
));
engine.add_plugin(gotify_plugin.clone());
transport_registry.register(gotify_plugin);
}
Loading

0 comments on commit a4497ed

Please sign in to comment.