From 876a784e90eb7624d9fd80b1da3b1a85a32f2b58 Mon Sep 17 00:00:00 2001 From: someone Date: Thu, 2 May 2024 10:01:28 +0200 Subject: [PATCH] added Pool to router --- src/engines/kv.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/engines/kv.rs b/src/engines/kv.rs index 0489def..21db586 100644 --- a/src/engines/kv.rs +++ b/src/engines/kv.rs @@ -3,9 +3,12 @@ pub mod structs; #[cfg(tests)] mod tests; -use axum::{routing::*, Router}; +use crate::engines::kv::logic::body_to_json; +use crate::engines::kv::structs::KvSecret; +use axum::{routing::*, Router, extract::Path}; +use sqlx::{Any, Pool}; -pub fn kv_router() -> Router { +pub fn kv_router(pool: Pool) -> Router> { Router::new() .route("/:mount_path/config", get(get_config)) .route("/:mount_path/config", post(post_config)) @@ -21,6 +24,7 @@ pub fn kv_router() -> Router { .route("/:mount_path/metadata/*path", delete(delete_meta)) .route("/:mount_path/subkeys/*path", get(get_subkeys)) .route("/:mount_path/undelete/*path", post(post_undelete)) + .with_state(pool) } async fn get_config() -> &'static str { @@ -35,10 +39,26 @@ async fn get_data() -> &'static str { todo!("not implemented") } -async fn post_data() -> &'static str { - todo!("not implemented") +async fn post_data(Path((mount_path, kv_path)): Path<(String, String)>, body: String) -> &'static str { + let mut body_json = body_to_json(body); + + let secret: KvSecret = KvSecret { + data: body_json["data"]["password1"].take().to_string(), + version: body_json["data"]["version"].take().as_i64(), + }; + log::debug!( + "Secret: {}, Content: {}, Version: {}, path: {}", + kv_path, + secret.data, + secret.version.unwrap(), + mount_path, + ); + "RoutingTest foo successful" + + // todo!("not implemented") } + /// TODO soft delete the secret version at path. can be undone with undelete_secret // https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#delete-latest-version-of-secret // https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#delete-secret-versions