This commit is contained in:
Laurenz 2024-04-28 13:54:24 +02:00
parent b8fbc86084
commit 6e215a99ee
18 changed files with 50 additions and 273 deletions

171
Cargo.lock generated
View file

@ -100,10 +100,6 @@ dependencies = [
"syn 2.0.60",
]
[[package]]
name = "auth-token"
version = "0.1.0"
[[package]]
name = "autocfg"
version = "1.2.0"
@ -180,23 +176,6 @@ dependencies = [
"rustc-demangle",
]
[[package]]
name = "base"
version = "0.1.0"
dependencies = [
"chrono",
"json-patch",
"log",
"serde",
"serde_json",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.5.0"
@ -209,12 +188,6 @@ version = "3.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
version = "1.6.0"
@ -260,30 +233,6 @@ version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "crc32fast"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa"
dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
[[package]]
name = "env_filter"
version = "0.1.0"
@ -328,16 +277,6 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "fs2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "futures-channel"
version = "0.3.30"
@ -371,15 +310,6 @@ dependencies = [
"pin-utils",
]
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "gimli"
version = "0.28.1"
@ -519,15 +449,6 @@ dependencies = [
"serde",
]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
[[package]]
name = "itoa"
version = "1.0.11"
@ -649,17 +570,6 @@ version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "parking_lot"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core 0.8.6",
]
[[package]]
name = "parking_lot"
version = "0.12.2"
@ -667,21 +577,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb"
dependencies = [
"lock_api",
"parking_lot_core 0.9.10",
]
[[package]]
name = "parking_lot_core"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall 0.2.16",
"smallvec",
"winapi",
"parking_lot_core",
]
[[package]]
@ -692,7 +588,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.5.1",
"redox_syscall",
"smallvec",
"windows-targets 0.52.5",
]
@ -777,22 +673,13 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_syscall"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
dependencies = [
"bitflags 2.5.0",
"bitflags",
]
[[package]]
@ -906,8 +793,9 @@ name = "server"
version = "0.1.0"
dependencies = [
"axum",
"base",
"chrono",
"env_logger",
"json-patch",
"log",
"serde",
"serde_json",
@ -925,22 +813,6 @@ dependencies = [
"libc",
]
[[package]]
name = "sled"
version = "0.34.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935"
dependencies = [
"crc32fast",
"crossbeam-epoch",
"crossbeam-utils",
"fs2",
"fxhash",
"libc",
"log",
"parking_lot 0.11.2",
]
[[package]]
name = "smallvec"
version = "1.13.2"
@ -957,15 +829,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "storage-sled"
version = "0.1.0"
dependencies = [
"base",
"chrono",
"sled",
]
[[package]]
name = "syn"
version = "1.0.109"
@ -1030,7 +893,7 @@ dependencies = [
"libc",
"mio",
"num_cpus",
"parking_lot 0.12.2",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
@ -1209,28 +1072,6 @@ version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.52.0"

View file

@ -1,18 +1,26 @@
[package]
name = "server"
version = "0.1.0"
edition = "2021"
[workspace]
resolver = "2"
members = ["crates/*"]
default-members = ["crates/server"]
# [target.x86_64-unknown-linux-gnu]
# rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]
[workspace.dependencies]
[lints]
workspace = true
[dependencies]
log = "0.4.21"
env_logger = "0.11.3"
tokio = "1.37.0"
chrono = { version = "0.4.38", features = ["serde"] }
tokio = { version = "1.37.0", features = ["full"] }
tower = { version = "0.4.13", features = [] }
axum = "0.7.5"
tower = "0.4.13"
serde = "1.0.199"
serde_json = "1.0.116"
chrono = "0.4.38"
json-patch = "1.2.0"
utoipa = { version = "4.2.0", features = ["axum_extras"] }
[workspace.lints.clippy]
uninlined_format_args = "warn"

View file

@ -1,9 +0,0 @@
[package]
name = "auth-token"
version = "0.1.0"
edition = "2021"
[lints]
workspace = true
[dependencies]

View file

@ -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);
}
}

View file

@ -1,10 +0,0 @@
[package]
name = "backend-kv"
version = "0.1.0"
edition = "2021"
[lints]
workspace = true
[dependencies]
base = { path = "../base" }

View file

@ -1,14 +0,0 @@
[package]
name = "base"
version = "0.1.0"
edition = "2021"
[lints]
workspace = true
[dependencies]
chrono = { workspace = true, features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
log = { workspace = true }
json-patch = "*"

View file

@ -1,23 +0,0 @@
[package]
name = "server"
version = "0.1.0"
edition = "2021"
# [target.x86_64-unknown-linux-gnu]
# rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]
[lints]
workspace = true
[dependencies]
log = { workspace = true }
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"] }
base = { path = "../base" }

View file

@ -1,12 +0,0 @@
[package]
name = "storage-sled"
version = "0.1.0"
edition = "2021"
[lints]
workspace = true
[dependencies]
base = { path = "../base" }
sled = "0.34.7"

View file

@ -1,16 +1,20 @@
use axum::{extract::Request, http::StatusCode, middleware::{self, Next}, response::Response, routing::*, Router};
use axum::{
extract::Request,
http::StatusCode,
middleware::{self, Next},
response::Response,
routing::*,
Router,
};
use log::*;
use crate::backend_kv;
pub fn secrets_router() -> Router {
// Router::new().layer(map_request(handler))
Router::new()
.nest("/:path", backend_kv::asdasdsadsd())
// .nest("/:path", kv2::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> {

View file

@ -1,17 +1,17 @@
use axum::{
extract::Request, http::StatusCode, routing::{get,post, trace}, Router
};
use axum::{extract::Request, http::StatusCode, routing::get, Router};
use log::*;
use serde::Deserialize;
use std::{env, net::SocketAddr, str::FromStr};
use tokio::net::TcpListener;
use serde::Deserialize;
use base::body_to_json;
use crate::common::body_to_json;
mod auth;
mod common;
mod engines;
mod identity;
mod secrets;
mod storage;
mod sys;
mod backend_kv;
#[tokio::main]
async fn main() {
@ -29,17 +29,17 @@ async fn main() {
.nest("/v1/auth", auth::auth_router())
.nest("/v1/identity", identity::identity_router())
.nest("/v1/sys", sys::sys_router())
.nest("/v1", secrets::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);
warn!("Listening on: {}", listen_addr.to_string());
warn!("Listening on {}", listen_addr.to_string());
// Start listening
let listener = TcpListener::bind(listen_addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
}
#[derive(Deserialize,Debug)]
#[derive(Deserialize, Debug)]
struct CreateSecret {
password1: String,
password2: String,
@ -47,9 +47,12 @@ struct CreateSecret {
/// Routing handler for path "/v1/kw_mount_path/data/foo"
/// expects payload as JSON, prints payload into struct
async fn baz(body: String) -> String{
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()};
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")
}

1
src/storage.rs Normal file
View file

@ -0,0 +1 @@

View file

@ -1,5 +1,7 @@
use axum::Router;
/// System routes
///
pub fn sys_router() -> Router {
Router::new()
}