Changeset View
Changeset View
Standalone View
Standalone View
services/identity/src/database.rs
Show First 20 Lines • Show All 968 Lines • ▼ Show 20 Lines | self | ||||
.table_name(USERS_TABLE) | .table_name(USERS_TABLE) | ||||
.set_key(Some(primary_key)) | .set_key(Some(primary_key)) | ||||
.consistent_read(true) | .consistent_read(true) | ||||
.send() | .send() | ||||
.await | .await | ||||
.map_err(|e| Error::AwsSdk(e.into())) | .map_err(|e| Error::AwsSdk(e.into())) | ||||
} | } | ||||
/// Retrieves username for password users or wallet address for wallet users | |||||
/// Returns `None` if user not found | |||||
pub async fn get_user_identifier( | pub async fn get_user_identifier( | ||||
&self, | &self, | ||||
user_id: &str, | user_id: &str, | ||||
) -> Result<Identifier, Error> { | ) -> Result<Option<Identifier>, Error> { | ||||
let user_info = self | self | ||||
.get_item_from_users_table(user_id) | .get_item_from_users_table(user_id) | ||||
.await? | .await? | ||||
.item | .item | ||||
.ok_or(Error::MissingItem)?; | .map(Identifier::try_from) | ||||
.transpose() | |||||
Identifier::try_from(user_info).map_err(|e| { | .map_err(|e| { | ||||
error!(user_id, "Database item is missing an identifier"); | error!(user_id, "Database item is missing an identifier"); | ||||
e | e | ||||
}) | }) | ||||
} | } | ||||
async fn get_all_usernames(&self) -> Result<Vec<String>, Error> { | async fn get_all_usernames(&self) -> Result<Vec<String>, Error> { | ||||
let scan_output = self | let scan_output = self | ||||
.client | .client | ||||
.scan() | .scan() | ||||
.table_name(USERS_TABLE) | .table_name(USERS_TABLE) | ||||
.projection_expression(USERS_TABLE_USERNAME_ATTRIBUTE) | .projection_expression(USERS_TABLE_USERNAME_ATTRIBUTE) | ||||
▲ Show 20 Lines • Show All 447 Lines • Show Last 20 Lines |