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 @@ -35,4 +35,18 @@ pub const MESSAGE_ID: &str = "messageID"; pub const SORT_KEY: &str = "messageID"; } + + // This table holds a device token associated with a device. + // + // - (primary key) = (deviceID: Partition Key) + // - deviceID: The public key of a device's olm identity key + // - deviceToken: Token to push services uploaded by device. + pub mod device_tokens { + pub const TABLE_NAME: &str = "tunnelbroker-device-tokens"; + pub const PARTITION_KEY: &str = "deviceID"; + pub const DEVICE_ID: &str = "deviceID"; + pub const DEVICE_TOKEN: &str = "deviceToken"; + + 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 @@ -11,9 +11,7 @@ use std::sync::Arc; use tracing::{debug, error}; -use crate::constants::dynamodb::undelivered_messages::{ - PARTITION_KEY, PAYLOAD, SORT_KEY, TABLE_NAME, -}; +use crate::constants::dynamodb::undelivered_messages; pub mod message; pub mod message_id; @@ -63,10 +61,10 @@ let request = self .client .put_item() - .table_name(TABLE_NAME) - .item(PARTITION_KEY, device_av) - .item(SORT_KEY, message_id_av) - .item(PAYLOAD, payload_av); + .table_name(undelivered_messages::TABLE_NAME) + .item(undelivered_messages::PARTITION_KEY, device_av) + .item(undelivered_messages::SORT_KEY, message_id_av) + .item(undelivered_messages::PAYLOAD, payload_av); debug!("Persisting message to device: {}", &device_id); @@ -83,8 +81,11 @@ let response = self .client .query() - .table_name(TABLE_NAME) - .key_condition_expression(format!("{} = :u", PARTITION_KEY)) + .table_name(undelivered_messages::TABLE_NAME) + .key_condition_expression(format!( + "{} = :u", + undelivered_messages::PARTITION_KEY + )) .expression_attribute_values( ":u", AttributeValue::S(device_id.to_string()), @@ -109,11 +110,11 @@ let key = HashMap::from([ ( - PARTITION_KEY.to_string(), + undelivered_messages::PARTITION_KEY.to_string(), AttributeValue::S(device_id.to_string()), ), ( - SORT_KEY.to_string(), + undelivered_messages::SORT_KEY.to_string(), AttributeValue::S(message_id.to_string()), ), ]); @@ -121,7 +122,7 @@ self .client .delete_item() - .table_name(TABLE_NAME) + .table_name(undelivered_messages::TABLE_NAME) .set_key(Some(key)) .send() .await