Page MenuHomePhabricator

D12842.diff
No OneTemporary

D12842.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
@@ -10,6 +10,7 @@
use crate::notifs::apns::APNsClient;
use crate::notifs::fcm::FCMClient;
+use crate::notifs::web_push::WebPushClient;
use crate::notifs::NotifClient;
use anyhow::{anyhow, Result};
use config::CONFIG;
@@ -70,11 +71,27 @@
};
let web_push_config = CONFIG.web_push_config.clone();
+ let web_push = match web_push_config {
+ Some(config) => match WebPushClient::new(&config) {
+ Ok(web_client) => {
+ info!("Web Push client created successfully");
+ Some(web_client)
+ }
+ Err(err) => {
+ error!("Error creating Web Push client: {}", err);
+ None
+ }
+ },
+ None => {
+ error!("Web Push config is missing");
+ None
+ }
+ };
let notif_client = NotifClient {
apns,
fcm,
- web_push: None,
+ web_push,
};
let grpc_server = grpc::run_server(db_client.clone(), &amqp_connection);
diff --git a/services/tunnelbroker/src/notifs/web_push/error.rs b/services/tunnelbroker/src/notifs/web_push/error.rs
new file mode 100644
--- /dev/null
+++ b/services/tunnelbroker/src/notifs/web_push/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/web_push/mod.rs b/services/tunnelbroker/src/notifs/web_push/mod.rs
--- a/services/tunnelbroker/src/notifs/web_push/mod.rs
+++ b/services/tunnelbroker/src/notifs/web_push/mod.rs
@@ -1,6 +1,20 @@
+use crate::notifs::web_push::config::WebPushConfig;
+
pub mod config;
+mod error;
#[derive(Clone)]
pub struct WebPushClient {
http_client: reqwest::Client,
+ config: WebPushConfig,
+}
+
+impl WebPushClient {
+ pub fn new(config: &WebPushConfig) -> Result<Self, error::Error> {
+ let http_client = reqwest::Client::builder().build()?;
+ Ok(WebPushClient {
+ http_client,
+ config: config.clone(),
+ })
+ }
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 9:06 AM (21 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2574778
Default Alt Text
D12842.diff (2 KB)

Event Timeline