diff --git a/services/tunnelbroker/rust-lib/src/lib.rs b/services/tunnelbroker/rust-lib/src/lib.rs --- a/services/tunnelbroker/rust-lib/src/lib.rs +++ b/services/tunnelbroker/rust-lib/src/lib.rs @@ -3,6 +3,7 @@ use env_logger; use lazy_static::lazy_static; use log::info; +use std::sync::RwLock; use tokio::runtime::Runtime; pub mod notifications; @@ -24,6 +25,14 @@ } #[namespace = "rust::notifications"] extern "Rust" { + #[cxx_name = "init"] + fn notifications_init( + fcm_api_key: &str, + apns_certificate_path: &str, + apns_certificate_password: &str, + apns_topic: &str, + is_sandbox: bool, + ) -> Result<()>; #[cxx_name = "sendNotifToAPNS"] fn send_notif_to_apns( certificate_path: &str, @@ -50,6 +59,26 @@ info!("Tokio runtime initialization"); Runtime::new().unwrap() }; + static ref NOTIFICATIONS_CONFIG: RwLock = + RwLock::new(notifications::config::Config::default()); +} + +pub fn notifications_init( + fcm_api_key: &str, + apns_certificate_path: &str, + apns_certificate_password: &str, + apns_topic: &str, + is_sandbox: bool, +) -> Result<()> { + let mut config = NOTIFICATIONS_CONFIG + .write() + .expect("Unable to write notification config"); + config.fcm_api_key = String::from(fcm_api_key); + config.apns_certificate_path = String::from(apns_certificate_path); + config.apns_certificate_password = String::from(apns_certificate_password); + config.apns_topic = String::from(apns_topic); + config.is_sandbox = is_sandbox; + Ok(()) } pub fn send_notif_to_apns( diff --git a/services/tunnelbroker/rust-lib/src/notifications/config.rs b/services/tunnelbroker/rust-lib/src/notifications/config.rs new file mode 100644 --- /dev/null +++ b/services/tunnelbroker/rust-lib/src/notifications/config.rs @@ -0,0 +1,8 @@ +#[derive(Default)] +pub struct Config { + pub fcm_api_key: String, + pub apns_certificate_path: String, + pub apns_certificate_password: String, + pub apns_topic: String, + pub is_sandbox: bool, +} diff --git a/services/tunnelbroker/rust-lib/src/notifications/mod.rs b/services/tunnelbroker/rust-lib/src/notifications/mod.rs --- a/services/tunnelbroker/rust-lib/src/notifications/mod.rs +++ b/services/tunnelbroker/rust-lib/src/notifications/mod.rs @@ -1,2 +1,3 @@ pub mod apns; +pub mod config; pub mod fcm;