Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3353601
D12842.id42635.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D12842.id42635.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 10:28 AM (20 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2574778
Default Alt Text
D12842.id42635.diff (2 KB)
Attached To
Mode
D12842: [Tunnelbroker] implement creating Web Push client
Attached
Detach File
Event Timeline
Log In to Comment