Page MenuHomePhabricator

D12938.id42990.diff
No OneTemporary

D12938.id42990.diff

diff --git a/services/tunnelbroker/src/constants.rs b/services/tunnelbroker/src/constants.rs
--- a/services/tunnelbroker/src/constants.rs
+++ b/services/tunnelbroker/src/constants.rs
@@ -52,6 +52,7 @@
pub const DEVICE_ID: &str = "deviceID";
pub const DEVICE_TOKEN: &str = "deviceToken";
pub const TOKEN_INVALID: &str = "tokenInvalid";
+ pub const PLATFORM: &str = "platform";
pub const DEVICE_TOKEN_INDEX_NAME: &str = "deviceToken-index";
}
diff --git a/services/tunnelbroker/src/database/mod.rs b/services/tunnelbroker/src/database/mod.rs
--- a/services/tunnelbroker/src/database/mod.rs
+++ b/services/tunnelbroker/src/database/mod.rs
@@ -6,7 +6,9 @@
use comm_lib::aws::ddb::operation::query::QueryError;
use comm_lib::aws::ddb::types::AttributeValue;
use comm_lib::aws::{AwsConfig, DynamoDBClient};
-use comm_lib::database::{AttributeExtractor, AttributeMap, Error};
+use comm_lib::database::{
+ AttributeExtractor, AttributeMap, DBItemAttributeError, DBItemError, Error,
+};
use std::collections::HashMap;
use std::sync::Arc;
use tracing::{debug, error, warn};
@@ -18,6 +20,8 @@
use crate::database::message_id::MessageID;
pub use message::*;
+use std::str::FromStr;
+use tunnelbroker_messages::Platform;
#[derive(Clone)]
pub struct DatabaseClient {
@@ -39,6 +43,7 @@
pub struct DeviceTokenEntry {
pub device_token: String,
pub token_invalid: bool,
+ pub platform: Option<Platform>,
}
impl DatabaseClient {
@@ -182,9 +187,24 @@
let token_invalid: Option<bool> =
item.take_attr(device_tokens::TOKEN_INVALID)?;
+ let platform = if let Some(platform_str) =
+ item.take_attr::<Option<String>>(device_tokens::PLATFORM)?
+ {
+ Some(Platform::from_str(&platform_str).map_err(|_| {
+ DBItemError::new(
+ device_tokens::TOKEN_INVALID.to_string(),
+ platform_str.clone().into(),
+ DBItemAttributeError::InvalidValue,
+ )
+ })?)
+ } else {
+ None
+ };
+
Ok(Some(DeviceTokenEntry {
device_token,
token_invalid: token_invalid.unwrap_or(false),
+ platform,
}))
}
@@ -192,6 +212,7 @@
&self,
device_id: &str,
device_token: &str,
+ platform: Option<Platform>,
) -> Result<(), Error> {
debug!("Setting device token for device: {}", &device_id);
@@ -236,7 +257,7 @@
}
}
- self
+ let mut put_item_input = self
.client
.put_item()
.table_name(device_tokens::TABLE_NAME)
@@ -247,13 +268,19 @@
.item(
device_tokens::DEVICE_TOKEN,
AttributeValue::S(device_token.to_string()),
- )
- .send()
- .await
- .map_err(|e| {
- error!("DynamoDB client failed to set device token {:?}", e);
- Error::AwsSdk(e.into())
- })?;
+ );
+
+ if let Some(platform_atr) = platform {
+ put_item_input = put_item_input.item(
+ device_tokens::PLATFORM,
+ AttributeValue::S(platform_atr.to_string()),
+ );
+ }
+
+ put_item_input.send().await.map_err(|e| {
+ error!("DynamoDB client failed to set device token {:?}", e);
+ Error::AwsSdk(e.into())
+ })?;
Ok(())
}
diff --git a/services/tunnelbroker/src/websockets/session.rs b/services/tunnelbroker/src/websockets/session.rs
--- a/services/tunnelbroker/src/websockets/session.rs
+++ b/services/tunnelbroker/src/websockets/session.rs
@@ -286,7 +286,11 @@
MessageToTunnelbroker::SetDeviceToken(token) => {
self
.db_client
- .set_device_token(&self.device_info.device_id, &token.device_token)
+ .set_device_token(
+ &self.device_info.device_id,
+ &token.device_token,
+ None,
+ )
.await?;
}
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 1:37 AM (4 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2559317
Default Alt Text
D12938.id42990.diff (3 KB)

Event Timeline