Skip to content

Commit

Permalink
Integration delete handler fixes (#493)
Browse files Browse the repository at this point in the history
* Add telemetry support for DELETE HTTP operations

- Introduce a new `telemetry_delete` macro to wrap DELETE requests with telemetry functionality.
- Modify the `/integration-delete` route to use the `telemetry_delete` macro for enhanced tracking.
- Update `handle_v1_integration_delete` function to parse request body as JSON and validate integration paths more robustly.
- Switch query parameter integration path type to `PathBuf` for better path handling.
- Improve logging and error messages for clarity in path deletion and error responses.

* Remove obsolete telemetry_delete macro and update integration delete handling in v1 routers

- Remove the `telemetry_delete` macro from `utils.rs`, as it is no longer needed.
- Update `handle_v1_integration_delete` function to use query parameters instead of parsing JSON from the request body.
- Modify the `/integration-delete` route in `v1.rs` to directly use the `delete` handler without the telemetry macro.
  • Loading branch information
JegernOUTT authored Dec 16, 2024
1 parent 9f4c9f1 commit 364216b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/http/routers/v1/v1_integrations.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::PathBuf;
use std::sync::Arc;
use axum::Extension;
use axum::http::{Response, StatusCode};
Expand All @@ -11,7 +12,7 @@ use axum::extract::Query;

use crate::custom_error::ScratchError;
use crate::global_context::GlobalContext;

use crate::integrations::setting_up_integrations::split_path_into_project_and_integration;

pub async fn handle_v1_integrations(
Extension(gcx): Extension<Arc<ARwLock<GlobalContext>>>,
Expand Down Expand Up @@ -155,28 +156,30 @@ pub async fn handle_v1_integration_icon(
// Define a structure to match query parameters
#[derive(Deserialize)]
pub struct HTTPIntegrationDeleteQueryParams {
integration_path: String, // Optional field for flexibility
integration_path: PathBuf
}

pub async fn handle_v1_integration_delete(
Query(params): Query<HTTPIntegrationDeleteQueryParams>,
) -> axum::response::Result<Response<Body>, ScratchError> {

) -> axum::response::Result<Response<Body>, ScratchError> {
let integration_path = params.integration_path;
log::info!("Deleting integration path: {}", integration_path);
log::info!("Deleting integration path: {:?}", integration_path);

split_path_into_project_and_integration(&integration_path).map_err(
|_| ScratchError::new(StatusCode::UNPROCESSABLE_ENTITY, "integration_path is invalid".to_string())
)?;

// If file path exists, delete it
if !std::path::Path::new(&integration_path).exists() {
if !integration_path.exists() {
return Err(ScratchError::new(StatusCode::NOT_FOUND, "integration_path not found".to_string()));
}

std::fs::remove_file(&integration_path).map_err(|e| {
ScratchError::new(StatusCode::INTERNAL_SERVER_ERROR, format!("Failed to delete file: {}", e))
ScratchError::new(StatusCode::INTERNAL_SERVER_ERROR, format!("failed to delete integration config: {}", e))
})?;

Ok(Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "application/json")
.body(Body::from(format!("")))
.body(Body::from("{}"))
.unwrap())
}

0 comments on commit 364216b

Please sign in to comment.