added Pool to router

This commit is contained in:
someone 2024-05-02 10:01:28 +02:00
parent 1d85839237
commit 876a784e90

View file

@ -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<Any>) -> Router<Pool<Any>> {
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