-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start working on the APNS router * Use a fork of a2 temporarily to support our use case Changes made in the fork: 1. Support creating a client with the raw cert and key data (no password). 2. Impl Deserialize for the APS struct (and sub-structs) Also improved error handling during APNS router creation, and started on the router impl. * Implement the APNS router happy path * Handle APNS errors * Switch to the "autoendpoint" branch of the a2 fork This branch contains all of the changes made in the fork. * Implement Router::register for ApnsRouter * Remove old TooMuchData error * Abstract the a2 client behind a trait and add a bunch of APNS tests * Convert float values in APS data from DynamoDb into integers Also, if the user has invalid APS data in the DB, an error is returned during routing. * Remove redundant APNS metric * Give APNS an expiration timestamp when routing notifications * Check the final APNS payload against the size limit * Drop the user if APNS says they are unregistered * Add some details about the a2 fork Closes #164
- Loading branch information
1 parent
8c4f23b
commit ce51957
Showing
14 changed files
with
922 additions
and
94 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,13 @@ authors = ["Mark Drobnak <[email protected]>", "jrconlin <[email protected] | |
edition = "2018" | ||
|
||
[dependencies] | ||
# Using a fork temporarily until these three PRs are merged: | ||
# - https://github.com/pimeys/a2/pull/49 | ||
# - https://github.com/pimeys/a2/pull/48 | ||
# - https://github.com/pimeys/a2/pull/47 | ||
# The `autoendpoint` branch merges these three PRs together. | ||
# The version of a2 at the time of the fork is v0.5.3. | ||
a2 = { git = "https://github.com/Mcat12/a2.git", branch = "autoendpoint" } | ||
actix-web = "2.0" | ||
actix-rt = "1.0" | ||
actix-cors = "0.2.0" | ||
|
@@ -38,6 +45,7 @@ slog-mozlog-json = "0.1" | |
slog-scope = "4.3" | ||
slog-stdlog = "4.0" | ||
slog-term = "2.5" | ||
tokio = { version = "0.2", features = ["fs"] } | ||
thiserror = "1.0" | ||
url = "2.1" | ||
uuid = { version = "0.8.1", features = ["serde", "v4"] } | ||
|
@@ -49,4 +57,4 @@ yup-oauth2 = "4.1.2" | |
mockall = "0.7.1" | ||
mockito = "0.26.0" | ||
tempfile = "3.1.0" | ||
tokio = { version = "0.2.12", features = ["macros"] } | ||
tokio = { version = "0.2", features = ["macros"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use crate::error::ApiErrorKind; | ||
use crate::routers::RouterError; | ||
use actix_web::http::StatusCode; | ||
use std::io; | ||
|
||
/// Errors that may occur in the Apple Push Notification Service router | ||
#[derive(thiserror::Error, Debug)] | ||
pub enum ApnsError { | ||
#[error("Failed to decode the channel settings")] | ||
ChannelSettingsDecode(#[from] serde_json::Error), | ||
|
||
#[error("IO Error: {0}")] | ||
Io(#[from] io::Error), | ||
|
||
#[error("Error while setting up APNS clients: {0}")] | ||
ApnsClient(#[source] a2::Error), | ||
|
||
#[error("Error while checking the message size limit: {0}")] | ||
SizeLimit(#[source] a2::Error), | ||
|
||
#[error("APNS error, {0}")] | ||
ApnsUpstream(#[source] a2::Error), | ||
|
||
#[error("No device token found for user")] | ||
NoDeviceToken, | ||
|
||
#[error("No release channel found for user")] | ||
NoReleaseChannel, | ||
|
||
#[error("Release channel is invalid")] | ||
InvalidReleaseChannel, | ||
|
||
#[error("Invalid APS data")] | ||
InvalidApsData, | ||
|
||
#[error("APNS recipient no longer available")] | ||
Unregistered, | ||
} | ||
|
||
impl ApnsError { | ||
/// Get the associated HTTP status code | ||
pub fn status(&self) -> StatusCode { | ||
match self { | ||
ApnsError::InvalidReleaseChannel | ||
| ApnsError::InvalidApsData | ||
| ApnsError::SizeLimit(_) => StatusCode::BAD_REQUEST, | ||
|
||
ApnsError::NoDeviceToken | ApnsError::NoReleaseChannel | ApnsError::Unregistered => { | ||
StatusCode::GONE | ||
} | ||
|
||
ApnsError::ChannelSettingsDecode(_) | ApnsError::Io(_) | ApnsError::ApnsClient(_) => { | ||
StatusCode::INTERNAL_SERVER_ERROR | ||
} | ||
|
||
ApnsError::ApnsUpstream(_) => StatusCode::BAD_GATEWAY, | ||
} | ||
} | ||
|
||
/// Get the associated error number | ||
pub fn errno(&self) -> Option<usize> { | ||
match self { | ||
ApnsError::NoDeviceToken | ApnsError::NoReleaseChannel | ApnsError::Unregistered => { | ||
Some(106) | ||
} | ||
|
||
ApnsError::ChannelSettingsDecode(_) | ||
| ApnsError::Io(_) | ||
| ApnsError::ApnsClient(_) | ||
| ApnsError::ApnsUpstream(_) | ||
| ApnsError::InvalidReleaseChannel | ||
| ApnsError::InvalidApsData | ||
| ApnsError::SizeLimit(_) => None, | ||
} | ||
} | ||
} | ||
|
||
impl From<ApnsError> for ApiErrorKind { | ||
fn from(e: ApnsError) -> Self { | ||
ApiErrorKind::Router(RouterError::Apns(e)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//! A notification router for Apple devices, using Apple Push Notification Service | ||
pub mod error; | ||
pub mod router; | ||
pub mod settings; |
Oops, something went wrong.