Page MenuHomePhabricator

D12753.id42295.diff
No OneTemporary

D12753.id42295.diff

diff --git a/services/tunnelbroker/src/main.rs b/services/tunnelbroker/src/main.rs
--- a/services/tunnelbroker/src/main.rs
+++ b/services/tunnelbroker/src/main.rs
@@ -9,6 +9,7 @@
pub mod websockets;
use crate::notifs::apns::APNsClient;
+use crate::notifs::fcm::FCMClient;
use crate::notifs::NotifClient;
use anyhow::{anyhow, Result};
use config::CONFIG;
@@ -52,8 +53,24 @@
};
let fcm_config = CONFIG.fcm_config.clone();
+ let fcm = match fcm_config {
+ Some(config) => match FCMClient::new(&config) {
+ Ok(apns_client) => {
+ info!("FCM client created successfully");
+ Some(apns_client)
+ }
+ Err(err) => {
+ error!("Error creating FCM client: {}", err);
+ None
+ }
+ },
+ None => {
+ error!("FCM config is missing");
+ None
+ }
+ };
- let notif_client = NotifClient { apns, fcm: None };
+ let notif_client = NotifClient { apns, fcm };
let grpc_server = grpc::run_server(db_client.clone(), &amqp_connection);
let websocket_server = websockets::run_server(
diff --git a/services/tunnelbroker/src/notifs/fcm/error.rs b/services/tunnelbroker/src/notifs/fcm/error.rs
new file mode 100644
--- /dev/null
+++ b/services/tunnelbroker/src/notifs/fcm/error.rs
@@ -0,0 +1,15 @@
+use derive_more::{Display, Error, From};
+
+#[derive(Debug, From, Display, Error)]
+pub enum Error {
+ JWTError,
+ ReqwestError(reqwest::Error),
+ InvalidHeaderValue(reqwest::header::InvalidHeaderValue),
+ SerdeJson(serde_json::Error),
+}
+
+impl From<jsonwebtoken::errors::Error> for Error {
+ fn from(_: jsonwebtoken::errors::Error) -> Self {
+ Self::JWTError
+ }
+}
diff --git a/services/tunnelbroker/src/notifs/fcm/mod.rs b/services/tunnelbroker/src/notifs/fcm/mod.rs
--- a/services/tunnelbroker/src/notifs/fcm/mod.rs
+++ b/services/tunnelbroker/src/notifs/fcm/mod.rs
@@ -1,6 +1,20 @@
+use crate::notifs::fcm::config::FCMConfig;
+
pub mod config;
+mod error;
#[derive(Clone)]
pub struct FCMClient {
- http2_client: reqwest::Client,
+ http_client: reqwest::Client,
+ config: FCMConfig,
+}
+
+impl FCMClient {
+ pub fn new(config: &FCMConfig) -> Result<Self, error::Error> {
+ let http_client = reqwest::Client::builder().build()?;
+ Ok(FCMClient {
+ http_client,
+ config: config.clone(),
+ })
+ }
}

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 29, 9:04 AM (4 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2731371
Default Alt Text
D12753.id42295.diff (2 KB)

Event Timeline