diff --git a/go_client/tests/secret_test.go b/go_client/tests/secret_test.go index ac3bff7..f5ab9c5 100644 --- a/go_client/tests/secret_test.go +++ b/go_client/tests/secret_test.go @@ -44,7 +44,7 @@ func TestWriteSecret(t *testing.T) { _, err := client.Secrets.KvV2Write(ctx, "foo", schema.KvV2WriteRequest{ Data: map[string]any{ "password1": "abc123", - "password2": "correct horse battery staple", + "version": 1, }}, vault.WithMountPath(mountpath), ) diff --git a/src/engines.rs b/src/engines.rs index 5397b1e..f1d9a92 100644 --- a/src/engines.rs +++ b/src/engines.rs @@ -1,7 +1,11 @@ pub mod kv; +use std::string; + +use crate::engines::kv::logic::body_to_json; +use crate::engines::kv::structs::KvSecret; use axum::{ - extract::Request, + extract::{Path, Request}, http::StatusCode, middleware::{self, Next}, response::Response, @@ -14,8 +18,29 @@ use sqlx::{Any, Pool}; pub fn secrets_router(pool: Pool) -> Router> { // Router::new().layer(map_request(handler)) - Router::new().with_state(pool) - // .nest("/:path", kv2::asdasdsadsd()) + Router::new() + .route("/:mount_path/data/:kv_path", post(baz)) + .with_state(pool) +} + +/// Routing handler for path "/v1/kv-v2/data/foo" +/// expects payload as JSON, prints payload into struct + +async fn baz(Path(mount_path): Path, Path(kv_path): Path, body: String) -> String { + let mut body_json = body_to_json(body); + + let secret: KvSecret = KvSecret { + content: body_json["data"]["password1"].take().to_string(), + version: body_json["data"]["version"].take().as_i64().unwrap(), + }; + log::debug!( + "Secret: {}, Content: {}, Version: {}, path: {}", + kv_path, + secret.content, + secret.version, + mount_path, + ); + String::from("RoutingTest baz successful") } // async fn handler(Host(hostname): Host, request: Request) -> &'static str { diff --git a/src/main.rs b/src/main.rs index 0003cda..aca393a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,12 @@ -use axum::{extract::Request, http::StatusCode, routing::get, Router}; +use axum::{ + extract::Request, http::StatusCode, routing::get, Router +}; use log::*; -use serde::Deserialize; use sqlx::{Any, Pool}; -use std::{env, net::SocketAddr, str::FromStr}; use tokio::net::TcpListener; +use std::{env, net::SocketAddr, str::FromStr}; -use crate::{engines::kv::logic::body_to_json, storage::create_pool}; +use crate::storage::create_pool; mod auth; mod common;