Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Laurenz 2024-04-28 17:02:02 +02:00
commit 79130d39e8
3 changed files with 34 additions and 8 deletions

View file

@ -44,7 +44,7 @@ func TestWriteSecret(t *testing.T) {
_, err := client.Secrets.KvV2Write(ctx, "foo", schema.KvV2WriteRequest{ _, err := client.Secrets.KvV2Write(ctx, "foo", schema.KvV2WriteRequest{
Data: map[string]any{ Data: map[string]any{
"password1": "abc123", "password1": "abc123",
"password2": "correct horse battery staple", "version": 1,
}}, }},
vault.WithMountPath(mountpath), vault.WithMountPath(mountpath),
) )

View file

@ -1,7 +1,11 @@
pub mod kv; pub mod kv;
use std::string;
use crate::engines::kv::logic::body_to_json;
use crate::engines::kv::structs::KvSecret;
use axum::{ use axum::{
extract::Request, extract::{Path, Request},
http::StatusCode, http::StatusCode,
middleware::{self, Next}, middleware::{self, Next},
response::Response, response::Response,
@ -14,8 +18,29 @@ use sqlx::{Any, Pool};
pub fn secrets_router(pool: Pool<Any>) -> Router<Pool<Any>> { pub fn secrets_router(pool: Pool<Any>) -> Router<Pool<Any>> {
// Router::new().layer(map_request(handler)) // Router::new().layer(map_request(handler))
Router::new().with_state(pool) Router::new()
// .nest("/:path", kv2::asdasdsadsd()) .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<String>, Path(kv_path): Path<String>, 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<Body>) -> &'static str { // async fn handler(Host(hostname): Host, request: Request<Body>) -> &'static str {

View file

@ -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 log::*;
use serde::Deserialize;
use sqlx::{Any, Pool}; use sqlx::{Any, Pool};
use std::{env, net::SocketAddr, str::FromStr};
use tokio::net::TcpListener; 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 auth;
mod common; mod common;