diff --git a/services/identity/src/backup.rs b/services/identity/src/backup.rs new file mode 100644 --- /dev/null +++ b/services/identity/src/backup.rs @@ -0,0 +1,22 @@ +use crate::{config::CONFIG, constants::error_types}; + +pub async fn delete_backup_user_data( + user_id: &str, +) -> Result<(), crate::error::Error> { + let path = format!("/user_data/{}", user_id); + let url = CONFIG + .backup_service_url + .join(&path) + .expect("failed to construct backup service URL"); + let client = reqwest::Client::builder().build()?; + let response = client.delete(url).send().await?; + if !response.status().is_success() { + let response_body = response.text().await?; + tracing::error!( + errorType = error_types::HTTP_LOG, + "Backup service failed to delete user data: {}", + response_body + ) + } + Ok(()) +} diff --git a/services/identity/src/error.rs b/services/identity/src/error.rs --- a/services/identity/src/error.rs +++ b/services/identity/src/error.rs @@ -23,6 +23,8 @@ #[display(...)] Serde(serde_json::Error), #[display(...)] + Reqwest(reqwest::Error), + #[display(...)] CannotOverwrite, #[display(...)] OneTimeKeyUploadLimitExceeded, diff --git a/services/identity/src/grpc_services/authenticated.rs b/services/identity/src/grpc_services/authenticated.rs --- a/services/identity/src/grpc_services/authenticated.rs +++ b/services/identity/src/grpc_services/authenticated.rs @@ -107,6 +107,14 @@ }); } +fn spawn_delete_backup_data_task(user_id: String) { + tokio::spawn(async move { + debug!("Attempting to delete Backup data for user: {}", &user_id); + let result = crate::backup::delete_backup_user_data(&user_id).await; + consume_error(result); + }); +} + #[tonic::async_trait] impl IdentityClientService for AuthenticatedService { #[tracing::instrument(skip_all)] @@ -570,10 +578,11 @@ let device_ids = self .db_client - .delete_user(user_id) + .delete_user(user_id.clone()) .await .map_err(handle_db_error)?; spawn_delete_tunnelbroker_data_task(device_ids); + spawn_delete_backup_data_task(user_id); let response = Empty {}; Ok(Response::new(response)) @@ -657,10 +666,11 @@ let device_ids = self .db_client - .delete_user(user_id) + .delete_user(user_id.clone()) .await .map_err(handle_db_error)?; spawn_delete_tunnelbroker_data_task(device_ids); + spawn_delete_backup_data_task(user_id); let response = Empty {}; Ok(Response::new(response)) diff --git a/services/identity/src/main.rs b/services/identity/src/main.rs --- a/services/identity/src/main.rs +++ b/services/identity/src/main.rs @@ -6,6 +6,7 @@ use tonic::transport::Server; use tonic_web::GrpcWebLayer; +mod backup; mod client_service; mod config; pub mod constants;