From e641036cda340ca5561399bd71f8a089ce6f0c9a Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 1 Jul 2025 17:17:44 +0800 Subject: [PATCH] add router --- rustfs/src/admin/handlers/event.rs | 6 ++++-- rustfs/src/admin/mod.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/rustfs/src/admin/handlers/event.rs b/rustfs/src/admin/handlers/event.rs index 5aacca76..d2d8884f 100644 --- a/rustfs/src/admin/handlers/event.rs +++ b/rustfs/src/admin/handlers/event.rs @@ -9,7 +9,7 @@ use s3s::{Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, header::C use serde::{Deserialize, Serialize}; use serde_urlencoded::from_bytes; use std::collections::HashMap; -use tracing::{error, info, warn}; +use tracing::{debug, error, info, warn}; #[derive(Debug, Deserialize)] struct TargetQuery { @@ -95,6 +95,8 @@ pub struct ListNotificationTargets {} #[async_trait::async_trait] impl Operation for ListNotificationTargets { async fn call(&self, req: S3Request, _params: Params<'_, '_>) -> S3Result> { + debug!("ListNotificationTargets call start request params: {:?}", req.uri.query()); + // 1. Permission verification let Some(input_cred) = &req.credentials else { return Err(s3_error!(InvalidRequest, "credentials not found")); @@ -113,7 +115,7 @@ impl Operation for ListNotificationTargets { // 4. Serialize and return the result let data = serde_json::to_vec(&active_targets) .map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, format!("failed to serialize targets: {}", e)))?; - + debug!("ListNotificationTargets call end, response data length: {}", data.len(),); let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) diff --git a/rustfs/src/admin/mod.rs b/rustfs/src/admin/mod.rs index 38c3030a..591d14de 100644 --- a/rustfs/src/admin/mod.rs +++ b/rustfs/src/admin/mod.rs @@ -5,6 +5,7 @@ pub mod utils; // use ecstore::global::{is_dist_erasure, is_erasure}; use handlers::{ + event::{ListNotificationTargets, RemoveNotificationTarget, SetNotificationTarget}, group, policys, pools, rebalance, service_account::{AddServiceAccount, DeleteServiceAccount, InfoServiceAccount, ListServiceAccount, UpdateServiceAccount}, sts, tier, user, @@ -337,5 +338,23 @@ fn register_user_route(r: &mut S3Router) -> std::io::Result<()> AdminOperation(&tier::ClearTier {}), )?; + r.insert( + Method::GET, + format!("{}{}", ADMIN_PREFIX, "/v3/target-list").as_str(), + AdminOperation(&ListNotificationTargets {}), + )?; + + r.insert( + Method::POST, + format!("{}{}", ADMIN_PREFIX, "/v3/target-set").as_str(), + AdminOperation(&SetNotificationTarget {}), + )?; + + r.insert( + Method::DELETE, + format!("{}{}", ADMIN_PREFIX, "/v3/target-remove").as_str(), + AdminOperation(&RemoveNotificationTarget {}), + )?; + Ok(()) }