diff --git a/services/identity/src/service.rs b/services/identity/src/service.rs --- a/services/identity/src/service.rs +++ b/services/identity/src/service.rs @@ -25,6 +25,7 @@ pub use proto::identity_service_server::IdentityServiceServer; use proto::{ + get_user_id_request::AuthType as ProtoAuthType, identity_service_server::IdentityService, login_request::Data::PakeLoginRequest, login_request::Data::WalletLoginRequest, @@ -356,7 +357,40 @@ &self, request: Request, ) -> Result, Status> { - unimplemented!(); + info!("Received GetUserID request: {:?}", request); + let message = request.into_inner(); + let auth_type = match ProtoAuthType::from_i32(message.auth_type) { + Some(ProtoAuthType::Password) => AuthType::Password, + Some(ProtoAuthType::Wallet) => AuthType::Wallet, + None => { + error!( + "Unable to parse AuthType from message: {}", + message.auth_type + ); + return Err(Status::invalid_argument("invalid message")); + } + }; + let user_id = match self + .client + .get_user_id_from_user_info(message.user_info, auth_type) + .await + { + Ok(Some(user_id)) => user_id, + Ok(None) => return Err(Status::not_found("no user ID found")), + Err(Error::AwsSdk(DynamoDBError::InternalServerError(_))) + | Err(Error::AwsSdk( + DynamoDBError::ProvisionedThroughputExceededException(_), + )) + | Err(Error::AwsSdk(DynamoDBError::RequestLimitExceeded(_))) => { + return Err(Status::unavailable("please retry")) + } + Err(e) => { + error!("Encountered an unexpected error: {}", e); + return Err(Status::failed_precondition("unexpected error")); + } + }; + let response = Response::new(GetUserIdResponse { user_id }); + Ok(response) } }