Changeset View
Changeset View
Standalone View
Standalone View
services/identity/src/database.rs
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | ) -> Result<UpdateItemOutput, Error> { | ||||
}; | }; | ||||
if let Some(username) = username { | if let Some(username) = username { | ||||
update_expression_parts | update_expression_parts | ||||
.push(format!("{} = :u", USERS_TABLE_USERNAME_ATTRIBUTE)); | .push(format!("{} = :u", USERS_TABLE_USERNAME_ATTRIBUTE)); | ||||
expression_attribute_values | expression_attribute_values | ||||
.insert(":u".to_string(), AttributeValue::S(username)); | .insert(":u".to_string(), AttributeValue::S(username)); | ||||
}; | }; | ||||
if let Some(public_key) = signing_public_key { | if let Some(public_key) = signing_public_key { | ||||
let device_info = match session_initialization_info { | |||||
Some(info) => info | |||||
.iter() | |||||
.map(|(k, v)| (k.to_string(), AttributeValue::S(v.to_string()))) | |||||
.collect(), | |||||
None => HashMap::new(), | |||||
}; | |||||
// How we construct the update expression will depend on whether the user | |||||
// already exists or not | |||||
if let GetItemOutput { item: Some(_), .. } = | |||||
self.get_item_from_users_table(&user_id).await? | |||||
{ | |||||
update_expression_parts.push(format!( | update_expression_parts.push(format!( | ||||
"{}.#{} = :k", | "{}.#{} = :k", | ||||
USERS_TABLE_DEVICES_ATTRIBUTE, USERS_TABLE_DEVICES_MAP_ATTRIBUTE_NAME, | USERS_TABLE_DEVICES_ATTRIBUTE, USERS_TABLE_DEVICES_MAP_ATTRIBUTE_NAME, | ||||
)); | )); | ||||
expression_attribute_names.insert( | expression_attribute_names.insert( | ||||
format!("#{}", USERS_TABLE_DEVICES_MAP_ATTRIBUTE_NAME), | format!("#{}", USERS_TABLE_DEVICES_MAP_ATTRIBUTE_NAME), | ||||
public_key, | public_key, | ||||
); | ); | ||||
let device_info = match session_initialization_info { | |||||
Some(info) => info | |||||
.iter() | |||||
.map(|(k, v)| (k.to_string(), AttributeValue::S(v.to_string()))) | |||||
.collect(), | |||||
None => HashMap::new(), | |||||
}; | |||||
expression_attribute_values | expression_attribute_values | ||||
.insert(":k".to_string(), AttributeValue::M(device_info)); | .insert(":k".to_string(), AttributeValue::M(device_info)); | ||||
} else { | |||||
update_expression_parts | |||||
.push(format!("{} = :k", USERS_TABLE_DEVICES_ATTRIBUTE)); | |||||
let mut devices = HashMap::new(); | |||||
devices.insert(public_key, AttributeValue::M(device_info)); | |||||
expression_attribute_values | |||||
.insert(":k".to_string(), AttributeValue::M(devices)); | |||||
}; | |||||
}; | }; | ||||
self | self | ||||
.client | .client | ||||
.update_item() | .update_item() | ||||
.table_name(USERS_TABLE) | .table_name(USERS_TABLE) | ||||
.key(USERS_TABLE_PARTITION_KEY, AttributeValue::S(user_id)) | .key(USERS_TABLE_PARTITION_KEY, AttributeValue::S(user_id)) | ||||
.update_expression(format!("SET {}", update_expression_parts.join(","))) | .update_expression(format!("SET {}", update_expression_parts.join(","))) | ||||
▲ Show 20 Lines • Show All 612 Lines • Show Last 20 Lines |