Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3538675
D12938.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D12938.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 11:38 PM (11 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2709459
Default Alt Text
D12938.diff (3 KB)
Attached To
Mode
D12938: [Tunnelbroker] add Platform column to `device_token` DDB table
Attached
Detach File
Event Timeline
Log In to Comment