diff --git a/Cargo.lock b/Cargo.lock index 52cc082..f6d6619 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -30,6 +39,17 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.5.0" @@ -225,6 +245,19 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "errno" version = "0.3.14" @@ -289,6 +322,15 @@ dependencies = [ "slab", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "http" version = "1.4.0" @@ -334,6 +376,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "hyper" version = "1.8.1" @@ -466,6 +517,8 @@ name = "mdf-bouncer" version = "0.1.0" dependencies = [ "axum", + "log", + "pretty_env_logger", "tokio", ] @@ -554,6 +607,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pretty_env_logger" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" +dependencies = [ + "env_logger", + "log", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -563,6 +626,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quick-xml" version = "0.37.5" @@ -591,6 +660,35 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + [[package]] name = "rss" version = "2.0.12" @@ -747,6 +845,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "tokio" version = "1.50.0" @@ -886,6 +993,37 @@ dependencies = [ "unicode-ident", ] +[[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-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys", +] + +[[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.62.2" diff --git a/mdf-bouncer/Cargo.toml b/mdf-bouncer/Cargo.toml index e89599f..8edf124 100644 --- a/mdf-bouncer/Cargo.toml +++ b/mdf-bouncer/Cargo.toml @@ -6,3 +6,5 @@ edition = "2024" [dependencies] axum = "*" tokio = { version = "*", features = ["full"] } +log = "0.4" +pretty_env_logger = "0.4" diff --git a/mdf-bouncer/src/main.rs b/mdf-bouncer/src/main.rs index 558e950..63d4ddb 100644 --- a/mdf-bouncer/src/main.rs +++ b/mdf-bouncer/src/main.rs @@ -1,9 +1,15 @@ -use std::{env::{args, var}, io}; +use std::{env::{args, var}, io, sync::Arc}; -use axum::{Router, body::{Body, Bytes}, extract::{DefaultBodyLimit, Path}, routing::{delete, post, put}}; +use axum::{Router, body::{Body, Bytes}, extract::{DefaultBodyLimit, Path, State}, routing::{delete, post, put}}; +use std::path::PathBuf; const MAXIMUM_PACKET_SIZE: usize = (2 << 20) * 10; +#[derive(Clone)] +struct AppState { + root: PathBuf, +} + #[tokio::main] async fn main() -> io::Result<()> { // get secret from secret file @@ -16,11 +22,15 @@ async fn main() -> io::Result<()> { port_str.parse::().expect("PORT is malformed") } else { 3236 }; + let state = Arc::new(AppState { root: PathBuf::from(target_path) }); + let app = Router::new() - .route("/", put(put_file)) - .route("/", delete(delete_file)) + .route("/{*key}", put(put_file)) + .route("/{*key}", delete(delete_file)) + .with_state(state) .layer(DefaultBodyLimit::max(MAXIMUM_PACKET_SIZE)); + let listener = tokio::net::TcpListener::bind(("localhost", port)) .await .expect("failed to bind to tcp socket"); @@ -29,11 +39,12 @@ async fn main() -> io::Result<()> { Ok(()) } -async fn delete_file(Path(path): Path) { - println!("the path: {path}"); +async fn delete_file(State(state): State>, Path(path): Path) { + println!("about to delete: {path}"); } -async fn put_file(body: Bytes) { +async fn put_file(State(state): State>, Path(path): Path, body: Bytes) { + println!("about to put: {path}"); let bytes = Vec::from(body); println!("body: {:?}", bytes); }