From 405d04ae22e5e89397f4a9c4e21f7c2c122b56e8 Mon Sep 17 00:00:00 2001 From: Mark Drobnak Date: Thu, 9 Jul 2020 16:39:26 -0400 Subject: [PATCH] Switch router_data back to serde_json::Value This allows us to use DynamoDbUser with any version of rusoto. --- Cargo.lock | 2 -- autoendpoint/Cargo.toml | 2 -- autoendpoint/src/server/routers/fcm/router.rs | 32 ++++++++++--------- autopush-common/src/db/models.rs | 3 +- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd189b31a..aa2f637b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -356,10 +356,8 @@ dependencies = [ "openssl 0.10.29 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.10.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rusoto_dynamodb 0.42.0 (registry+https://github.com/rust-lang/crates.io-index)", "sentry 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_dynamodb 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "slog-async 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/autoendpoint/Cargo.toml b/autoendpoint/Cargo.toml index 8c8399cf5..2d4872958 100644 --- a/autoendpoint/Cargo.toml +++ b/autoendpoint/Cargo.toml @@ -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" diff --git a/autoendpoint/src/server/routers/fcm/router.rs b/autoendpoint/src/server/routers/fcm/router.rs index d5e741d2e..54c768a9e 100644 --- a/autoendpoint/src/server/routers/fcm/router.rs +++ b/autoendpoint/src/server/routers/fcm/router.rs @@ -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; @@ -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)?; @@ -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; @@ -255,17 +255,19 @@ mod tests { } /// Create default user router data - fn default_router_data() -> HashMap { - serde_dynamodb::to_hashmap(&serde_json::json!({ - "token": FCM_TOKEN, - "app_id": "dev" - })) - .unwrap() + fn default_router_data() -> HashMap { + 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, + router_data: HashMap, data: Option, ) -> Notification { Notification { @@ -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(¬ification).await; diff --git a/autopush-common/src/db/models.rs b/autopush-common/src/db/models.rs index 10bec0972..90656ffcf 100644 --- a/autopush-common/src/db/models.rs +++ b/autopush-common/src/db/models.rs @@ -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; @@ -74,7 +73,7 @@ pub struct DynamoDbUser { // Router type of the user pub router_type: String, // Router-specific data - pub router_data: Option>, + pub router_data: Option>, // 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,