moved test request to engines.rs + extracted mountpath from request
This commit is contained in:
parent
aae1225d2d
commit
0730d711b5
3 changed files with 32 additions and 26 deletions
|
|
@ -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),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
@ -13,10 +17,29 @@ use log::*;
|
||||||
pub fn secrets_router() -> Router {
|
pub fn secrets_router() -> Router {
|
||||||
// Router::new().layer(map_request(handler))
|
// Router::new().layer(map_request(handler))
|
||||||
|
|
||||||
Router::new()
|
Router::new().route("/:mount_path/data/foo", post(baz))
|
||||||
// .nest("/:path", kv2::asdasdsadsd())
|
// .nest("/:path", kv2::asdasdsadsd())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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>, 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!(
|
||||||
|
"Content: {}, Version: {}, 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 {
|
||||||
// TODO: Find a solution for this mess
|
// TODO: Find a solution for this mess
|
||||||
// async fn handler(request: Request<Body>) -> Result<Request<Body>, StatusCode> {
|
// async fn handler(request: Request<Body>) -> Result<Request<Body>, StatusCode> {
|
||||||
|
|
|
||||||
29
src/main.rs
29
src/main.rs
|
|
@ -1,11 +1,13 @@
|
||||||
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 std::{env, net::SocketAddr, str::FromStr};
|
use std::{env, net::SocketAddr, str::FromStr};
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
|
|
||||||
use crate::engines::kv::logic::body_to_json;
|
|
||||||
|
|
||||||
mod auth;
|
mod auth;
|
||||||
mod common;
|
mod common;
|
||||||
mod engines;
|
mod engines;
|
||||||
|
|
@ -30,7 +32,6 @@ async fn main() {
|
||||||
.nest("/v1/identity", identity::identity_router())
|
.nest("/v1/identity", identity::identity_router())
|
||||||
.nest("/v1/sys", sys::sys_router())
|
.nest("/v1/sys", sys::sys_router())
|
||||||
.nest("/v1", engines::secrets_router()) // mountable secret backends
|
.nest("/v1", engines::secrets_router()) // mountable secret backends
|
||||||
// .route("/v1/kv-v2/data/foo", post(baz))
|
|
||||||
.fallback(fallback_route_unknown);
|
.fallback(fallback_route_unknown);
|
||||||
|
|
||||||
warn!("Listening on {}", listen_addr.to_string());
|
warn!("Listening on {}", listen_addr.to_string());
|
||||||
|
|
@ -39,24 +40,6 @@ async fn main() {
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
struct CreateSecret {
|
|
||||||
password1: String,
|
|
||||||
password2: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Routing handler for path "/v1/kw_mount_path/data/foo"
|
|
||||||
/// expects payload as JSON, prints payload into struct
|
|
||||||
async fn baz(body: String) -> String {
|
|
||||||
let mut body_json = body_to_json(body);
|
|
||||||
let secret: CreateSecret = CreateSecret {
|
|
||||||
password1: body_json["data"]["password1"].take().to_string(),
|
|
||||||
password2: body_json["data"]["password2"].take().to_string(),
|
|
||||||
};
|
|
||||||
log::debug!("Pass1: {}, Pass2: {}", secret.password1, secret.password2);
|
|
||||||
String::from("RoutingTest baz successful")
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fallback_route_unknown(req: Request) -> (StatusCode, &'static str) {
|
async fn fallback_route_unknown(req: Request) -> (StatusCode, &'static str) {
|
||||||
log::error!(
|
log::error!(
|
||||||
"Route not found: {} {}, payload {:?}",
|
"Route not found: {} {}, payload {:?}",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue