Skip to content

Commit

Permalink
WIP: feat: add Windows Push Notification Services (WNS) router. (mozi…
Browse files Browse the repository at this point in the history
…lla-services#775)

The relevant settings are like:
```
[wns]

credentials = """{
    "nightly": {
        "project_id": "3e776f1c-927b-4918-9924-c7d292ddf732",
        "credential": "{\\"client_id\\": \\"1f39a2f4-4621-49e7-bde8-fc4c90b9e783\\", \\"client_secret\\": \\"REDACTED\\"}"
    }
}"""
```

Here `project_id` is my personal account's Microsoft Entra "tenant ID"
and `client_id` is my personal account's Microsoft Entra "application
ID".  Different Firefox channels would share a single `project_id`
value while having varying `client_id` values.
  • Loading branch information
ncalexan committed Oct 7, 2024
1 parent a6db959 commit b5209d2
Show file tree
Hide file tree
Showing 11 changed files with 1,126 additions and 2 deletions.
2 changes: 1 addition & 1 deletion autoendpoint/src/extractors/router_data_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl FromRequest for RouterDataInput {
// Validate the token according to each router's token schema
let is_valid = match path_args.router_type {
RouterType::WebPush => true,
RouterType::FCM | RouterType::GCM | RouterType::APNS => {
RouterType::FCM | RouterType::GCM | RouterType::APNS | RouterType::WNS => {
VALID_TOKEN.is_match(&data.token)
}
#[cfg(feature = "stub")]
Expand Down
7 changes: 7 additions & 0 deletions autoendpoint/src/extractors/routers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error::{ApiError, ApiResult};
use crate::routers::apns::router::ApnsRouter;
use crate::routers::fcm::router::FcmRouter;
use crate::routers::wns::router::WnsRouter;
#[cfg(feature = "stub")]
use crate::routers::stub::router::StubRouter;
use crate::routers::webpush::WebPushRouter;
Expand All @@ -21,6 +22,7 @@ pub enum RouterType {
FCM,
GCM,
APNS,
WNS,
#[cfg(feature = "stub")]
STUB,
}
Expand All @@ -34,6 +36,7 @@ impl FromStr for RouterType {
"fcm" => Ok(RouterType::FCM),
"gcm" => Ok(RouterType::GCM),
"apns" => Ok(RouterType::APNS),
"wns" => Ok(RouterType::WNS),
#[cfg(feature = "stub")]
"stub" => Ok(RouterType::STUB),
_ => Err(()),
Expand All @@ -48,6 +51,7 @@ impl Display for RouterType {
RouterType::FCM => "fcm",
RouterType::GCM => "gcm",
RouterType::APNS => "apns",
RouterType::WNS => "wns",
#[cfg(feature = "stub")]
RouterType::STUB => "stub",
})
Expand All @@ -60,6 +64,7 @@ pub struct Routers {
webpush: WebPushRouter,
fcm: Arc<FcmRouter>,
apns: Arc<ApnsRouter>,
wns: Arc<WnsRouter>,
#[cfg(feature = "stub")]
stub: Arc<StubRouter>,
}
Expand All @@ -82,6 +87,7 @@ impl FromRequest for Routers {
},
fcm: app_state.fcm_router.clone(),
apns: app_state.apns_router.clone(),
wns: app_state.wns_router.clone(),
#[cfg(feature = "stub")]
stub: app_state.stub_router.clone(),
})
Expand All @@ -95,6 +101,7 @@ impl Routers {
RouterType::WebPush => &self.webpush,
RouterType::FCM | RouterType::GCM => self.fcm.as_ref(),
RouterType::APNS => self.apns.as_ref(),
RouterType::WNS => self.wns.as_ref(),
#[cfg(feature = "stub")]
RouterType::STUB => self.stub.as_ref(),
}
Expand Down
11 changes: 11 additions & 0 deletions autoendpoint/src/routers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::extractors::notification::Notification;
use crate::extractors::router_data_input::RouterDataInput;
use crate::routers::apns::error::ApnsError;
use crate::routers::fcm::error::FcmError;
use crate::routers::wns::error::WnsError;

use autopush_common::db::error::DbError;

Expand All @@ -23,6 +24,7 @@ pub mod fcm;
#[cfg(feature = "stub")]
pub mod stub;
pub mod webpush;
pub mod wns;

#[async_trait(?Send)]
pub trait Router {
Expand Down Expand Up @@ -82,6 +84,9 @@ pub enum RouterError {
#[error(transparent)]
Fcm(#[from] FcmError),

#[error(transparent)]
Wns(#[from] WnsError),

#[cfg(feature = "stub")]
#[error(transparent)]
Stub(#[from] StubError),
Expand Down Expand Up @@ -123,6 +128,7 @@ impl RouterError {
match self {
RouterError::Apns(e) => e.status(),
RouterError::Fcm(e) => StatusCode::from_u16(e.status().as_u16()).unwrap_or_default(),
RouterError::Wns(e) => StatusCode::from_u16(e.status().as_u16()).unwrap_or_default(),

RouterError::SaveDb(e, _) => e.status(),
#[cfg(feature = "stub")]
Expand All @@ -145,6 +151,7 @@ impl RouterError {
match self {
RouterError::Apns(e) => e.errno(),
RouterError::Fcm(e) => e.errno(),
RouterError::Wns(e) => e.errno(),

#[cfg(feature = "stub")]
RouterError::Stub(e) => e.errno(),
Expand Down Expand Up @@ -175,6 +182,7 @@ impl ReportableError for RouterError {
match &self {
RouterError::Apns(e) => Some(e),
RouterError::Fcm(e) => Some(e),
RouterError::Wns(e) => Some(e),
RouterError::SaveDb(e, _) => Some(e),
_ => None,
}
Expand All @@ -185,6 +193,7 @@ impl ReportableError for RouterError {
// apns handle_error emits a metric for ApnsError::Unregistered
RouterError::Apns(e) => e.is_sentry_event(),
RouterError::Fcm(e) => e.is_sentry_event(),
RouterError::Wns(e) => e.is_sentry_event(),
// common handle_error emits metrics for these
RouterError::Authentication
| RouterError::GCMAuthentication
Expand All @@ -205,6 +214,7 @@ impl ReportableError for RouterError {
match self {
RouterError::Apns(e) => e.metric_label(),
RouterError::Fcm(e) => e.metric_label(),
RouterError::Wns(e) => e.metric_label(),
RouterError::TooMuchData(_) => Some("notification.bridge.error.too_much_data"),
_ => None,
}
Expand All @@ -214,6 +224,7 @@ impl ReportableError for RouterError {
match &self {
RouterError::Apns(e) => e.extras(),
RouterError::Fcm(e) => e.extras(),
RouterError::Wns(e) => e.extras(),
RouterError::SaveDb(e, sub) => {
let mut extras = e.extras();
if let Some(sub) = sub {
Expand Down
Loading

0 comments on commit b5209d2

Please sign in to comment.