pub mod kv; use axum::{ body::Body, extract::{Request, State}, response::Response, Router, }; use log::*; use sqlx::{Any, Pool}; pub fn secrets_router(pool: Pool) -> Router> { Router::new().fallback(map_mount_points).with_state(pool) } async fn map_mount_points(State(_pool): State>, req: Request) -> Response { // let mount_path = mount_path.trim_start_matches('/'); // debug!("Mount path: {}", mount_path); debug!("Mount path: {:?}", req); let mut mount_path: Vec<&str> = req.uri().path().split("/").collect(); // let a = sqlx::query!("SELECT * FROM secret_engines WHERE path = $1", mount_path.join("/")) // .fetch_one(&pool) // .await // .expect("Failed to fetch secret engine"); let tada = vec!["a/b/c/d".to_string(), "/a/b/c".to_string(), "/kv-v2".into()]; // Find longest matching existing mount path for the request for _ in 1..mount_path.len() { if tada.contains(&mount_path.join("/")) { trace!( "Mount path {} found for route request: {}", mount_path.join("/"), req.uri().path() ); break; } else { mount_path.pop(); } } return Response::new(Body::from(format!("Mount path:"))); }