Skip to content

Commit

Permalink
Switch router_data back to serde_json::Value
Browse files Browse the repository at this point in the history
This allows us to use DynamoDbUser with any version of rusoto.
  • Loading branch information
AzureMarker committed Jul 13, 2020
1 parent 79db7e9 commit 405d04a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions autoendpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ lazy_static = "1.4.0"
openssl = "0.10"
regex = "1.3"
reqwest = "0.10.6"
rusoto_dynamodb = "0.42.0"
sentry = { version = "0.18", features = ["with_curl_transport"] }
serde = { version = "1.0", features = ["derive"] }
serde_dynamodb = "0.4.1"
serde_json = "1.0"
slog = { version = "2.5", features = ["max_level_trace", "release_max_level_error", "dynamic-keys"] }
slog-async = "2.4"
Expand Down
32 changes: 17 additions & 15 deletions autoendpoint/src/server/routers/fcm/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::server::FcmSettings;
use async_trait::async_trait;
use autopush_common::util::InsertOpt;
use cadence::{Counted, StatsdClient};
use serde_json::Value;
use std::collections::HashMap;
use url::Url;

Expand Down Expand Up @@ -173,11 +174,11 @@ impl Router for FcmRouter {
.ok_or(FcmError::NoRegistrationToken)?;
let fcm_token = router_data
.get("token")
.and_then(|t| t.s.as_deref())
.and_then(Value::as_str)
.ok_or(FcmError::NoRegistrationToken)?;
let app_id = router_data
.get("app_id")
.and_then(|t| t.s.as_deref())
.and_then(Value::as_str)
.ok_or(FcmError::NoAppId)?;
let ttl = MAX_TTL.min(self.settings.ttl.max(notification.headers.ttl as usize));
let message_data = self.build_message_data(notification)?;
Expand Down Expand Up @@ -220,7 +221,6 @@ mod tests {
use crate::server::FcmSettings;
use autopush_common::db::DynamoDbUser;
use cadence::StatsdClient;
use rusoto_dynamodb::AttributeValue;
use std::collections::HashMap;
use std::path::PathBuf;
use url::Url;
Expand Down Expand Up @@ -255,17 +255,19 @@ mod tests {
}

/// Create default user router data
fn default_router_data() -> HashMap<String, AttributeValue> {
serde_dynamodb::to_hashmap(&serde_json::json!({
"token": FCM_TOKEN,
"app_id": "dev"
}))
.unwrap()
fn default_router_data() -> HashMap<String, serde_json::Value> {
let mut map = HashMap::new();
map.insert(
"token".to_string(),
serde_json::to_value(FCM_TOKEN).unwrap(),
);
map.insert("app_id".to_string(), serde_json::to_value("dev").unwrap());
map
}

/// Create a notification
fn make_notification(
router_data: HashMap<String, AttributeValue>,
router_data: HashMap<String, serde_json::Value>,
data: Option<String>,
) -> Notification {
Notification {
Expand Down Expand Up @@ -374,11 +376,11 @@ mod tests {
let router = make_router(service_file.path().to_owned()).await;
let _token_mock = mock_token_endpoint();
let fcm_mock = mock_fcm_endpoint_builder().expect(0).create();
let router_data = serde_dynamodb::to_hashmap(&serde_json::json!({
"token": FCM_TOKEN,
"app_id": "unknown-app-id"
}))
.unwrap();
let mut router_data = default_router_data();
router_data.insert(
"app_id".to_string(),
serde_json::to_value("unknown-app-id").unwrap(),
);
let notification = make_notification(router_data, None);

let result = router.route_notification(&notification).await;
Expand Down
3 changes: 1 addition & 2 deletions autopush-common/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::result::Result as StdResult;

use lazy_static::lazy_static;
use regex::RegexSet;
use rusoto_dynamodb::AttributeValue;
use serde::Serializer;
use serde_derive::{Deserialize, Serialize};
use uuid::Uuid;
Expand Down Expand Up @@ -74,7 +73,7 @@ pub struct DynamoDbUser {
// Router type of the user
pub router_type: String,
// Router-specific data
pub router_data: Option<HashMap<String, AttributeValue>>,
pub router_data: Option<HashMap<String, serde_json::Value>>,
// Keyed time in a month the user last connected at with limited key range for indexing
#[serde(skip_serializing_if = "Option::is_none")]
pub last_connect: Option<u64>,
Expand Down

0 comments on commit 405d04a

Please sign in to comment.