idk
This commit is contained in:
parent
bc82e576f3
commit
5441747154
9 changed files with 143 additions and 90 deletions
57
Cargo.lock
generated
57
Cargo.lock
generated
|
|
@ -165,13 +165,6 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backend-kv"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.71"
|
||||
|
|
@ -203,6 +196,12 @@ version = "1.3.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.16.0"
|
||||
|
|
@ -223,9 +222,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.94"
|
||||
version = "1.0.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7"
|
||||
checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
|
|
@ -551,9 +550,9 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
|||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.11"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
|
||||
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"scopeguard",
|
||||
|
|
@ -650,12 +649,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.1"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
|
||||
checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
"parking_lot_core 0.9.9",
|
||||
"parking_lot_core 0.9.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -674,15 +673,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.9.9"
|
||||
version = "0.9.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
|
||||
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"redox_syscall 0.4.1",
|
||||
"redox_syscall 0.5.1",
|
||||
"smallvec",
|
||||
"windows-targets 0.48.5",
|
||||
"windows-targets 0.52.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -771,16 +770,16 @@ version = "0.2.16"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.4.1"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
|
||||
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.5.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -838,18 +837,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.198"
|
||||
version = "1.0.199"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
|
||||
checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.198"
|
||||
version = "1.0.199"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
|
||||
checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -906,9 +905,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.1"
|
||||
version = "1.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
|
||||
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
|
@ -997,7 +996,7 @@ dependencies = [
|
|||
"libc",
|
||||
"mio",
|
||||
"num_cpus",
|
||||
"parking_lot 0.12.1",
|
||||
"parking_lot 0.12.2",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"socket2",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ env_logger = "0.11.3"
|
|||
tokio = "1.37.0"
|
||||
axum = "0.7.5"
|
||||
tower = "0.4.13"
|
||||
serde = "1.0.199"
|
||||
serde_json = "1.0.116"
|
||||
chrono = "0.4.38"
|
||||
|
||||
[workspace.lints.clippy]
|
||||
uninlined_format_args = "warn"
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ edition = "2021"
|
|||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
chrono = { version = "0.4.38", features = ["serde"] }
|
||||
serde = { version = "1.0.198", features = ["derive"] }
|
||||
serde_json = "1.0.116"
|
||||
chrono = { workspace = true, features = ["serde"] }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
log = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ env_logger = { workspace = true }
|
|||
tokio = { workspace = true, features=["full"] }
|
||||
tower = { workspace = true, features = []}
|
||||
axum = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
utoipa = { version = "4", features = ["axum_extras"] }
|
||||
serde = "1.0.197"
|
||||
serde_json = "1.0.1"
|
||||
|
||||
base = { path = "../base" }
|
||||
67
crates/server/src/backend_kv.rs
Normal file
67
crates/server/src/backend_kv.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
use axum::{routing::*, Router};
|
||||
|
||||
pub fn kv_router() -> Router {
|
||||
Router::new()
|
||||
.route("/:mount_path/config", get(get_config))
|
||||
.route("/:mount_path/config", post(post_config))
|
||||
.route("/:mount_path/data/:path", get(get_data))
|
||||
.route("/:mount_path/data/:path/", get(get_data))
|
||||
.route("/:mount_path/data/:path", get(post_data))
|
||||
.route("/:mount_path/data/:path", delete(delete_data))
|
||||
.route("/:mount_path/delete/:path", post(delete_path))
|
||||
.route("/:mount_path/destroy/:path", post(destroy_path))
|
||||
.route("/:mount_path/metadata/:path", get(get_meta))
|
||||
.route("/:mount_path/metadata/:path/", get(get_meta))
|
||||
.route("/:mount_path/metadata/:path", post(post_meta))
|
||||
.route("/:mount_path/metadata/:path", delete(delete_meta))
|
||||
.route("/:mount_path/subkeys/:path", get(get_subkeys))
|
||||
.route("/:mount_path/undelete/:path", post(post_undelete))
|
||||
}
|
||||
|
||||
async fn get_config() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn post_config() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn get_data() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn post_data() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn delete_data() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn delete_path() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn destroy_path() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn get_meta() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn post_meta() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn delete_meta() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn get_subkeys() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
||||
async fn post_undelete() -> &'static str {
|
||||
todo!("not implemented")
|
||||
}
|
||||
|
|
@ -4,13 +4,14 @@ use axum::{
|
|||
use log::*;
|
||||
use std::{env, net::SocketAddr, str::FromStr};
|
||||
use tokio::net::TcpListener;
|
||||
use serde::Deserialize;
|
||||
use base::body_to_json;
|
||||
|
||||
mod auth;
|
||||
mod identity;
|
||||
mod secrets;
|
||||
mod sys;
|
||||
use serde::Deserialize;
|
||||
use base::body_to_json;
|
||||
mod backend_kv;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
|
@ -18,7 +19,6 @@ async fn main() {
|
|||
env::set_var("RUST_LOG", "trace"); // Used to set level of logging -> choose from (highest to lowest): error, warn, info, debug, trace, off
|
||||
env_logger::init();
|
||||
|
||||
|
||||
// Listen on all IPv4 and IPv6 interfaces on port 8200
|
||||
let listen_addr = env::var("LISTEN_ADDR").unwrap_or("[::]:8200".to_string()); // Do not change
|
||||
let listen_addr = SocketAddr::from_str(&listen_addr).expect("Failed to parse LISTEN_ADDR");
|
||||
|
|
@ -30,7 +30,7 @@ async fn main() {
|
|||
.nest("/v1/identity", identity::identity_router())
|
||||
.nest("/v1/sys", sys::sys_router())
|
||||
.nest("/v1", secrets::secrets_router()) // mountable secret backends
|
||||
.route("/v1/kv-v2/data/foo", post(baz))
|
||||
// .route("/v1/kv-v2/data/foo", post(baz))
|
||||
.fallback(fallback_route_unknown);
|
||||
|
||||
warn!("Listening on: {}", listen_addr.to_string());
|
||||
|
|
|
|||
|
|
@ -1,50 +1,45 @@
|
|||
use std::convert::Infallible;
|
||||
use axum::{extract::Request, http::StatusCode, middleware::{self, Next}, response::Response, routing::*, Router};
|
||||
use log::*;
|
||||
|
||||
use axum::{
|
||||
body::Body,
|
||||
http::{Request, StatusCode},
|
||||
middleware::map_request,
|
||||
response::Response,
|
||||
routing::*,
|
||||
Router,
|
||||
};
|
||||
use tower::{service_fn, util::BoxService, Service};
|
||||
use crate::backend_kv;
|
||||
|
||||
pub fn secrets_router() -> Router {
|
||||
// let middleware = tower::util::MapRequestLayer::new(handler);
|
||||
// Router::new().layer(map_request(handler))
|
||||
|
||||
Router::new().layer(map_request(handler))
|
||||
Router::new()
|
||||
.nest("/:path", backend_kv::asdasdsadsd())
|
||||
}
|
||||
|
||||
|
||||
// async fn handler(Host(hostname): Host, request: Request<Body>) -> &'static str {
|
||||
// TODO: Find a solution for this mess
|
||||
async fn handler(request: Request<Body>) -> Result<Request<Body>, StatusCode> {
|
||||
// let path: Vec<&str> = request.uri().path().split('/').clone().collect();
|
||||
// log::info!("path, {:?}", path[1]);
|
||||
// async fn handler(request: Request<Body>) -> Result<Request<Body>, StatusCode> {
|
||||
// // let path: Vec<&str> = request.uri().path().split('/').clone().collect();
|
||||
// // log::info!("path, {:?}", path[1]);
|
||||
|
||||
let root = service_fn(|req: Request<String>| async move {
|
||||
let res = Response::new("Hello, World!".to_string());
|
||||
Ok::<_, Infallible>(res)
|
||||
});
|
||||
let root = BoxService::new(root);
|
||||
// let root = service_fn(|req: Request<String>| async move {
|
||||
// let res = Response::new("Hello, World!".to_string());
|
||||
// Ok::<_, Infallible>(res)
|
||||
// });
|
||||
// let root = BoxService::new(root);
|
||||
|
||||
let mut routes = vec!["/abc", "/def"];
|
||||
routes.sort_unstable_by(|a, b| a.len().cmp(&b.len()));
|
||||
// let mut routes = vec!["/abc", "/def"];
|
||||
// routes.sort_unstable_by(|a, b| a.len().cmp(&b.len()));
|
||||
|
||||
let mut app = Router::new();
|
||||
app.as_service().call(request).await.unwrap();
|
||||
// let mut app = Router::new();
|
||||
// app.as_service().call(request).await.unwrap();
|
||||
|
||||
// match path[1] {
|
||||
// "test" => {
|
||||
// log::info!("test route");
|
||||
// // TODO: Nest another Router here
|
||||
// return Ok(Request::new(Body::empty()));
|
||||
// // match path[1] {
|
||||
// // "test" => {
|
||||
// // log::info!("test route");
|
||||
// // // TODO: Nest another Router here
|
||||
// // return Ok(Request::new(Body::empty()));
|
||||
// // }
|
||||
// // _ => {
|
||||
// // log::info!("default");
|
||||
// // return Err(StatusCode::NOT_FOUND);
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// Err(StatusCode::IM_A_TEAPOT)
|
||||
// }
|
||||
// _ => {
|
||||
// log::info!("default");
|
||||
// return Err(StatusCode::NOT_FOUND);
|
||||
// }
|
||||
// }
|
||||
|
||||
Err(StatusCode::IM_A_TEAPOT)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,4 +8,5 @@ workspace = true
|
|||
|
||||
[dependencies]
|
||||
base = { path = "../base" }
|
||||
|
||||
sled = "0.34.7"
|
||||
|
|
|
|||
Loading…
Reference in a new issue