Skip to content

Commit

Permalink
feat: delete fcm v1
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed May 16, 2024
1 parent 4552a51 commit daeac31
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/handlers/delete_fcm_v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use {
crate::{
error::Error::{self},
handlers::validate_tenant_request,
increment_counter,
state::AppState,
},
axum::{
extract::{Path, State},
http::HeaderMap,
},
hyper::StatusCode,
std::sync::Arc,
tracing::{debug, error, instrument},
};

#[instrument(skip_all, name = "delete_fcm_v1_handler")]
pub async fn handler(
State(state): State<Arc<AppState>>,
Path(id): Path<String>,
headers: HeaderMap,
) -> Result<StatusCode, Error> {
// JWT token verification
#[cfg(feature = "cloud")]
let jwt_verification_result =
validate_tenant_request(&state.jwt_validation_client, &headers, &id).await;

// -- check if tenant is real
let _existing_tenant = state.tenant_store.get_tenant(&id).await?;

#[cfg(not(feature = "cloud"))]
let jwt_verification_result = validate_tenant_request(&state.jwt_validation_client, &headers);

if let Err(e) = jwt_verification_result {
error!(
tenant_id = %id,
err = ?e,
"JWT verification failed"
);
return Err(e);
}

let new_tenant = state.tenant_store.update_tenant_delete_fcm_v1(&id).await?;

if new_tenant.suspended {
// If suspended, it can be restored now because valid credentials have been
// provided
state.tenant_store.unsuspend_tenant(&new_tenant.id).await?;
}

increment_counter!(state.metrics, tenant_fcm_v1_updates);

Ok(StatusCode::NO_CONTENT)
}
2 changes: 2 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub mod single_tenant_wrappers;
#[cfg(feature = "multitenant")]
pub mod create_tenant;
#[cfg(feature = "multitenant")]
pub mod delete_fcm_v1;
#[cfg(feature = "multitenant")]
pub mod delete_tenant;
#[cfg(feature = "multitenant")]
pub mod get_tenant;
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ pub async fn bootstap(mut shutdown: broadcast::Receiver<()>, config: Config) ->
get(handlers::get_tenant::handler).delete(handlers::delete_tenant::handler),
)
.route("/:id/fcm", post(handlers::update_fcm::handler))
// .route("/:id/fcm", delete(handlers::delete_fcm::handler))
.route("/:id/fcm_v1", post(handlers::update_fcm_v1::handler))
.route("/:id/fcm_v1", delete(handlers::delete_fcm_v1::handler))
.route("/:id/apns", post(handlers::update_apns::handler))
// .route("/:id/apns", delete(handlers::delete_apns::handler))
.layer(
global_middleware.clone().layer(
CorsLayer::new()
Expand Down

0 comments on commit daeac31

Please sign in to comment.