diff --git a/INCUBATOR.md b/INCUBATOR.md index 0d9d2f9..9f14321 100644 --- a/INCUBATOR.md +++ b/INCUBATOR.md @@ -1,6 +1,6 @@ # 代理工具孵化记录 -> 状态:孵化中 | 更新:2026-03-21 +> 状态:孵化中 | 更新:2026-03-24 --- @@ -10,11 +10,27 @@ |------|------|------|----------| | mysql-proxy | 3307 | 可用 | `mysql-proxy` | | ssh-proxy | 3308 | 可用 | `ssh-proxy` | +| mongo-proxy | 3309 | 可用 | `mongo-proxy` | +| redis-proxy | 3310 | 可用 | `redis-proxy` | --- ## 新增功能 +### 2026-03-24 + +1. **redis-proxy** (新工具) + - Redis HTTP 代理,会话复用 + - 支持 run/get/set/del/keys/info + - CLI 模式 + HTTP API 双模式 + - 连接: flux_dev + +2. **mongo-proxy** (新工具) + - MongoDB HTTP 代理,会话复用 + - 支持 find/insert/update/delete/aggregate/count + - CLI 模式 + HTTP API 双模式 + - 连接: suke_dev, suke_pro + ### 2026-03-21 1. **ssh-proxy 断线重连** (P0) diff --git a/INDEX.md b/INDEX.md index 00b85a6..e88d36e 100644 --- a/INDEX.md +++ b/INDEX.md @@ -1,6 +1,6 @@ # Rust Work 索引 -> 更新:2026-03-18 +> 更新:2026-03-24 ## 项目列表 @@ -8,6 +8,8 @@ |------|------|------| | [mysql-proxy](mysql-proxy) | 3307 | MySQL 会话复用代理 | | [ssh-proxy](ssh-proxy) | 3308 | SSH 会话复用代理 | +| [mongo-proxy](mongo-proxy) | 3309 | MongoDB 会话复用代理 | +| [redis-proxy](redis-proxy) | 3310 | Redis 会话复用代理 | | [mysql-cli](mysql-cli) | - | MySQL CLI 工具 (开发中) | ## 孵化记录 @@ -22,4 +24,10 @@ cd mysql-proxy && ./target/release/mysql-proxy.exe # ssh-proxy cd ssh-proxy && ./target/release/ssh-proxy.exe + +# mongo-proxy +cd mongo-proxy && ./target/release/mongo-proxy.exe + +# redis-proxy +cd redis-proxy && ./target/release/redis-proxy.exe ``` diff --git a/mongo-proxy/Cargo.lock b/mongo-proxy/Cargo.lock new file mode 100644 index 0000000..4d37ec0 --- /dev/null +++ b/mongo-proxy/Cargo.lock @@ -0,0 +1,2575 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "getrandom 0.3.4", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "axum" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bson" +version = "2.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969a9ba84b0ff843813e7249eed1678d9b6607ce5a3b8f0a47af3fcf7978e6e" +dependencies = [ + "ahash", + "base64", + "bitvec", + "getrandom 0.2.17", + "getrandom 0.3.4", + "hex", + "indexmap", + "js-sys", + "once_cell", + "rand", + "serde", + "serde_bytes", + "serde_json", + "time", + "uuid", +] + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "clap" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "const-random" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom 0.2.17", + "once_cell", + "tiny-keccak", +] + +[[package]] +name = "convert_case" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633458d4ef8c78b72454de2d54fd6ab2e60f9e02be22f3c6104cdc8a4e0fceb9" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + +[[package]] +name = "crossbeam-channel" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" +dependencies = [ + "crossbeam-utils", +] + +[[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.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "darling" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0" +dependencies = [ + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "data-encoding" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea" + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "derive-syn-parse" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive-where" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d08b3a0bcc0d079199cd476b2cae8435016ec11d1c0986c6901c5ac223041534" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_more" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn", + "unicode-xid", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "enum-as-inner" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-io", + "futures-macro", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 5.3.0", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "wasip2", + "wasip3", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hickory-proto" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8a6fe56c0038198998a6f217ca4e7ef3a5e51f46163bd6dd60b5c71ca6c6502" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna", + "ipnet", + "once_cell", + "rand", + "ring", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc62a9a99b0bfb44d2ab95a7208ac952d31060efc16241c87eaf36406fecf87a" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto", + "ipconfig", + "moka", + "once_cell", + "parking_lot", + "rand", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "bytes", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", + "serde", + "serde_core", +] + +[[package]] +name = "ipconfig" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d72a21f6a71a6c4c3160e095e8925861f5119dd26ef71acee1b9146f74f76c8" +dependencies = [ + "socket2", + "widestring", + "windows-sys 0.61.2", + "winreg", +] + +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.183" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "macro_magic" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc33f9f0351468d26fbc53d9ce00a096c8522ecb42f19b50f34f2c422f76d21d" +dependencies = [ + "macro_magic_core", + "macro_magic_macros", + "quote", + "syn", +] + +[[package]] +name = "macro_magic_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1687dc887e42f352865a393acae7cf79d98fab6351cde1f58e9e057da89bf150" +dependencies = [ + "const-random", + "derive-syn-parse", + "macro_magic_core_macros", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "macro_magic_core_macros" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "macro_magic_macros" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" +dependencies = [ + "macro_magic_core", + "quote", + "syn", +] + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "moka" +version = "0.12.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957228ad12042ee839f93c8f257b62b4c0ab5eaae1d4fa60de53b27c9d7c5046" +dependencies = [ + "crossbeam-channel", + "crossbeam-epoch", + "crossbeam-utils", + "equivalent", + "parking_lot", + "portable-atomic", + "smallvec", + "tagptr", + "uuid", +] + +[[package]] +name = "mongo-proxy" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "clap", + "futures-util", + "mongodb", + "serde", + "serde_json", + "time", + "tokio", + "toml", + "ureq", +] + +[[package]] +name = "mongocrypt" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da0cd419a51a5fb44819e290fbdb0665a54f21dead8923446a799c7f4d26ad9" +dependencies = [ + "bson", + "mongocrypt-sys", + "once_cell", + "serde", +] + +[[package]] +name = "mongocrypt-sys" +version = "0.1.5+1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224484c5d09285a7b8cb0a0c117e847ebd14cb6e4470ecf68cdb89c503b0edb9" + +[[package]] +name = "mongodb" +version = "3.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c5941683db2ab2697f71e58dc0319024e808d3b28e7cf20f4bfb445fe54a30b" +dependencies = [ + "base64", + "bitflags", + "bson", + "derive-where", + "derive_more", + "futures-core", + "futures-io", + "futures-util", + "hex", + "hickory-proto", + "hickory-resolver", + "hmac", + "macro_magic", + "md-5", + "mongocrypt", + "mongodb-internal-macros", + "pbkdf2", + "percent-encoding", + "rand", + "rustc_version_runtime", + "rustls", + "rustversion", + "serde", + "serde_bytes", + "serde_with", + "sha1", + "sha2", + "socket2", + "stringprep", + "strsim", + "take_mut", + "thiserror", + "tokio", + "tokio-rustls", + "tokio-util", + "typed-builder", + "uuid", + "webpki-roots 1.0.6", +] + +[[package]] +name = "mongodb-internal-macros" +version = "3.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47021a12bbf0dffde9c890fa2d36ff6ae342c532016226b04a42301b2b912660" +dependencies = [ + "macro_magic", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "num-conv" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +dependencies = [ + "critical-section", + "portable-atomic", +] + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "resolv-conf" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e061d1b48cb8d38042de4ae0a7a6401009d6143dc80d2e2d6f31f0bdd6470c7" + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustc_version_runtime" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dd18cd2bae1820af0b6ad5e54f4a51d0f3fcc53b05f845675074efcc7af071d" +dependencies = [ + "rustc_version", + "semver", +] + +[[package]] +name = "rustls" +version = "0.23.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df33b2b81ac578cabaf06b89b0631153a3f416b0a886e8a7a1707fb51abbd1ef" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_bytes" +version = "0.11.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "indexmap", + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "3.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd5414fad8e6907dbdd5bc441a50ae8d6e26151a03b1de04d89a5576de61d01f" +dependencies = [ + "serde_core", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "3.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3db8978e608f1fe7357e211969fd9abdcae80bac1ba7a3369bb7eb6b404eb65" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "simd-adler32" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tagptr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" + +[[package]] +name = "take_mut" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" + +[[package]] +name = "time-macros" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-io", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "typed-builder" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "398a3a3c918c96de527dc11e6e846cd549d4508030b8a33e1da12789c856b81a" +dependencies = [ + "typed-builder-macro", +] + +[[package]] +name = "typed-builder-macro" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e48cea23f68d1f78eb7bc092881b6bb88d3d6b5b7e6234f6f9c911da1ffb221" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" +dependencies = [ + "base64", + "flate2", + "log", + "once_cell", + "rustls", + "rustls-pki-types", + "url", + "webpki-roots 0.26.11", +] + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "uuid" +version = "1.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a68d3c8f01c0cfa54a75291d83601161799e4a89a39e0929f4b0354d88757a37" +dependencies = [ + "getrandom 0.4.2", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.6", +] + +[[package]] +name = "webpki-roots" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "widestring" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72069c3113ab32ab29e5584db3c6ec55d416895e60715417b5b883a357c3e471" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" +dependencies = [ + "memchr", +] + +[[package]] +name = "winreg" +version = "0.55.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb5a765337c50e9ec252c2069be9bf91c7df47afb103b642ba3a53bf8101be97" +dependencies = [ + "cfg-if", + "windows-sys 0.59.0", +] + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbb2a062be311f2ba113ce66f697a4dc589f85e78a4aea276200804cea0ed87" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/mongo-proxy/Cargo.toml b/mongo-proxy/Cargo.toml new file mode 100644 index 0000000..debeb27 --- /dev/null +++ b/mongo-proxy/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "mongo-proxy" +version = "0.1.0" +edition = "2021" +description = "MongoDB HTTP proxy with connection pooling" + +[dependencies] +mongodb = "3" +tokio = { version = "1", features = ["full"] } +axum = "0.7" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +toml = "0.8" +futures-util = "0.3" +anyhow = "1" +clap = { version = "4", features = ["derive"] } +ureq = "2" +time = { version = "0.3", features = ["formatting", "macros"] } + +[profile.release] +opt-level = "z" +lto = true +strip = true diff --git a/mongo-proxy/mongo-proxy.toml b/mongo-proxy/mongo-proxy.toml new file mode 100644 index 0000000..67f30d0 --- /dev/null +++ b/mongo-proxy/mongo-proxy.toml @@ -0,0 +1,23 @@ +[server] +port = 3309 +host = "127.0.0.1" + +[pool] +idle_timeout_secs = 300 +check_interval_secs = 60 + +[[connections]] +name = "suke_dev" +host = "39.99.243.191" +port = 27017 +database = "suke" +username = "u_suke" +password = "123456" + +[[connections]] +name = "suke_pro" +host = "39.100.50.215" +port = 27017 +database = "suke_pro" +username = "u_suke" +password = "231122" diff --git a/mongo-proxy/src/cli.rs b/mongo-proxy/src/cli.rs new file mode 100644 index 0000000..3ee51dd --- /dev/null +++ b/mongo-proxy/src/cli.rs @@ -0,0 +1,278 @@ +use anyhow::{Result, bail}; +use serde::Deserialize; +use std::time::Instant; + +const DEFAULT_SERVER: &str = "http://127.0.0.1:3309"; + +#[derive(Debug, Deserialize)] +struct ErrorResponse { + error: String, +} + +#[derive(Debug, Deserialize)] +struct ConnectionsResponse { + connections: Vec, +} + +#[derive(Debug, Deserialize)] +struct ConnectionInfo { + name: String, + database: String, + host: String, + status: String, +} + +pub struct Cli { + server: String, +} + +impl Cli { + pub fn new(server: Option) -> Self { + Self { server: server.unwrap_or_else(|| DEFAULT_SERVER.to_string()) } + } + + pub fn check_server(&self) -> Result { + match ureq::get(&format!("{}/health", self.server)).call() { + Ok(_) => Ok(true), + Err(_) => Ok(false), + } + } + + pub fn find(&self, conn: &str, collection: &str, filter: &str, format: &str, + projection: Option<&str>, limit: Option, skip: Option) -> Result<()> { + let start = Instant::now(); + + let mut body = serde_json::json!({ + "conn": conn, + "collection": collection, + "filter": serde_json::from_str::(filter).unwrap_or(serde_json::json!({})) + }); + if let Some(p) = projection { + body["projection"] = serde_json::from_str(p).unwrap_or(serde_json::Value::Null); + } + if let Some(l) = limit { + body["limit"] = serde_json::json!(l); + } + if let Some(s) = skip { + body["skip"] = serde_json::json!(s); + } + + let resp = post_json(&format!("{}/find", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + + if let Ok(err) = serde_json::from_str::(&resp) { + eprintln!("Error: {}", err.error); + return Ok(()); + } + + #[derive(Deserialize)] + struct FindResp { + documents: Vec, + count: usize, + #[serde(rename = "durationMs")] + duration_ms: u64, + } + let result: FindResp = serde_json::from_str(&resp)?; + + match format { + "json" => println!("{}", serde_json::to_string_pretty(&result.documents).unwrap_or_default()), + _ => { + for doc in &result.documents { + println!("{}", serde_json::to_string_pretty(doc).unwrap_or_default()); + } + } + } + + println!("\n{} documents ({}ms db, {}ms total)", result.count, result.duration_ms, total_ms); + Ok(()) + } + + pub fn insert(&self, conn: &str, collection: &str, documents: &str) -> Result<()> { + let start = Instant::now(); + + let docs: Vec = serde_json::from_str(documents) + .map_err(|e| anyhow::anyhow!("Invalid JSON documents: {}", e))?; + + let body = serde_json::json!({ + "conn": conn, + "collection": collection, + "documents": docs + }); + + let resp = post_json(&format!("{}/insert", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + + if let Ok(err) = serde_json::from_str::(&resp) { + eprintln!("Error: {}", err.error); + return Ok(()); + } + + #[derive(Deserialize)] + struct InsertResp { + #[serde(rename = "insertedCount")] + inserted_count: u64, + } + let result: InsertResp = serde_json::from_str(&resp)?; + println!("Inserted {} document(s) ({}ms total)", result.inserted_count, total_ms); + Ok(()) + } + + pub fn update(&self, conn: &str, collection: &str, filter: &str, update: &str, upsert: bool, multi: bool) -> Result<()> { + let start = Instant::now(); + + let mut body = serde_json::json!({ + "conn": conn, + "collection": collection, + "filter": serde_json::from_str::(filter)?, + "update": serde_json::from_str::(update)? + }); + if upsert { body["upsert"] = serde_json::json!(true); } + if multi { body["multi"] = serde_json::json!(true); } + + let resp = post_json(&format!("{}/update", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + + if let Ok(err) = serde_json::from_str::(&resp) { + eprintln!("Error: {}", err.error); + return Ok(()); + } + + #[derive(Deserialize)] + struct UpdateResp { + #[serde(rename = "matchedCount")] + matched_count: u64, + #[serde(rename = "modifiedCount")] + modified_count: u64, + } + let result: UpdateResp = serde_json::from_str(&resp)?; + println!("Matched: {}, Modified: {} ({}ms total)", result.matched_count, result.modified_count, total_ms); + Ok(()) + } + + pub fn delete(&self, conn: &str, collection: &str, filter: &str, multi: bool) -> Result<()> { + let start = Instant::now(); + + let mut body = serde_json::json!({ + "conn": conn, + "collection": collection, + "filter": serde_json::from_str::(filter)? + }); + if multi { body["multi"] = serde_json::json!(true); } + + let resp = post_json(&format!("{}/delete", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + + if let Ok(err) = serde_json::from_str::(&resp) { + eprintln!("Error: {}", err.error); + return Ok(()); + } + + #[derive(Deserialize)] + struct DeleteResp { + #[serde(rename = "deletedCount")] + deleted_count: u64, + } + let result: DeleteResp = serde_json::from_str(&resp)?; + println!("Deleted {} document(s) ({}ms total)", result.deleted_count, total_ms); + Ok(()) + } + + pub fn aggregate(&self, conn: &str, collection: &str, pipeline: &str) -> Result<()> { + let start = Instant::now(); + + let body = serde_json::json!({ + "conn": conn, + "collection": collection, + "pipeline": serde_json::from_str::(pipeline)? + }); + + let resp = post_json(&format!("{}/aggregate", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + + if let Ok(err) = serde_json::from_str::(&resp) { + eprintln!("Error: {}", err.error); + return Ok(()); + } + + #[derive(Deserialize)] + struct AggResp { + documents: Vec, + #[serde(rename = "durationMs")] + duration_ms: u64, + } + let result: AggResp = serde_json::from_str(&resp)?; + + for doc in &result.documents { + println!("{}", serde_json::to_string_pretty(doc).unwrap_or_default()); + } + + println!("\n{} result(s) ({}ms db, {}ms total)", result.documents.len(), result.duration_ms, total_ms); + Ok(()) + } + + pub fn count(&self, conn: &str, collection: &str, filter: Option<&str>) -> Result<()> { + let start = Instant::now(); + + let mut body = serde_json::json!({ + "conn": conn, + "collection": collection + }); + if let Some(f) = filter { + body["filter"] = serde_json::from_str::(f).unwrap_or(serde_json::json!({})); + } + + let resp = post_json(&format!("{}/count", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + + if let Ok(err) = serde_json::from_str::(&resp) { + eprintln!("Error: {}", err.error); + return Ok(()); + } + + #[derive(Deserialize)] + struct CountResp { + count: u64, + #[serde(rename = "durationMs")] + duration_ms: u64, + } + let result: CountResp = serde_json::from_str(&resp)?; + println!("{} documents ({}ms db, {}ms total)", result.count, result.duration_ms, total_ms); + Ok(()) + } + + pub fn list_connections(&self) -> Result<()> { + let response = ureq::get(&format!("{}/connections", self.server)).call()?; + let body = response.into_string()?; + + if let Ok(err) = serde_json::from_str::(&body) { + bail!("{}", err.error); + } + + let result: ConnectionsResponse = serde_json::from_str(&body)?; + + println!("Connections:"); + println!("{:<15} {:<20} {:<40} {:<10}", "Name", "Database", "Host", "Status"); + println!("{}", "-".repeat(85)); + + for conn in result.connections { + println!("{:<15} {:<20} {:<40} {:<10}", + conn.name, conn.database, conn.host, conn.status); + } + + Ok(()) + } +} + +fn post_json(url: &str, body: &serde_json::Value) -> Result { + let data = serde_json::to_string(body)?; + + let response = ureq::post(url) + .set("Content-Type", "application/json") + .send_string(&data); + + match response { + Ok(r) => Ok(r.into_string()?), + Err(ureq::Error::Status(_, resp)) => Ok(resp.into_string()?), + Err(e) => bail!("HTTP error: {}", e), + } +} diff --git a/mongo-proxy/src/config.rs b/mongo-proxy/src/config.rs new file mode 100644 index 0000000..d8e0f5f --- /dev/null +++ b/mongo-proxy/src/config.rs @@ -0,0 +1,139 @@ +use anyhow::{Result, bail}; +use serde::Deserialize; +use std::fs; + +#[derive(Debug, Deserialize, Clone)] +pub struct ServerConfig { + pub port: u16, + #[serde(default = "default_host")] + pub host: String, +} + +fn default_host() -> String { + "127.0.0.1".to_string() +} + +#[derive(Debug, Deserialize, Clone)] +pub struct PoolConfig { + #[serde(default = "default_idle_timeout")] + pub idle_timeout_secs: u64, + #[serde(default = "default_check_interval")] + pub check_interval_secs: u64, +} + +fn default_idle_timeout() -> u64 { 300 } +fn default_check_interval() -> u64 { 60 } + +impl Default for PoolConfig { + fn default() -> Self { + Self { + idle_timeout_secs: default_idle_timeout(), + check_interval_secs: default_check_interval(), + } + } +} + +#[derive(Debug, Deserialize, Clone)] +pub struct ConnectionConfig { + pub name: String, + pub host: String, + #[serde(default = "default_port")] + pub port: u16, + pub database: String, + #[serde(default)] + pub username: Option, + #[serde(default)] + pub password: Option, + #[serde(default)] + pub auth_source: Option, +} + +fn default_port() -> u16 { 27017 } + +#[derive(Debug, Deserialize)] +pub struct Config { + #[serde(default = "default_server")] + pub server: ServerConfig, + #[serde(default)] + pub pool: PoolConfig, + pub connections: Vec, +} + +fn default_server() -> ServerConfig { + ServerConfig { + port: 3309, + host: "127.0.0.1".to_string(), + } +} + +impl Config { + pub fn from_file(path: &str) -> Result { + let content = fs::read_to_string(path)?; + let config: Config = toml::from_str(&content)?; + config.validate()?; + Ok(config) + } + + #[allow(dead_code)] + pub fn load() -> Result { + let paths = [ + "mongo-proxy.toml", + "./config/mongo-proxy.toml", + &format!("{}/.mongo-proxy.toml", std::env::var("HOME").unwrap_or_default()), + ]; + + for path in &paths { + if std::path::Path::new(path).exists() { + return Self::from_file(path); + } + } + + bail!("Config file not found. Create mongo-proxy.toml in current directory or use --config flag") + } + + fn validate(&self) -> Result<()> { + let mut names = std::collections::HashSet::new(); + for conn in &self.connections { + if conn.name.is_empty() { + bail!("Connection name cannot be empty"); + } + if names.contains(&conn.name) { + bail!("Duplicate connection name: {}", conn.name); + } + names.insert(conn.name.clone()); + } + Ok(()) + } +} + +impl ConnectionConfig { + pub fn build_uri(&self) -> String { + let cred = match (&self.username, &self.password) { + (Some(user), Some(pass)) => format!("{}:{}@", user, urlencoding(pass)), + _ => String::new(), + }; + let auth = match &self.auth_source { + Some(src) => format!("?authSource={}", src), + None => String::new(), + }; + format!( + "mongodb://{}{}:{}/{}{}", + cred, self.host, self.port, self.database, auth + ) + } +} + +fn urlencoding(s: &str) -> String { + let mut result = String::new(); + for c in s.chars() { + match c { + '@' => result.push_str("%40"), + ':' => result.push_str("%3A"), + '/' => result.push_str("%2F"), + '?' => result.push_str("%3F"), + '#' => result.push_str("%23"), + _ => result.push(c), + } + } + result +} diff --git a/mongo-proxy/src/db.rs b/mongo-proxy/src/db.rs new file mode 100644 index 0000000..302feaf --- /dev/null +++ b/mongo-proxy/src/db.rs @@ -0,0 +1,144 @@ +use anyhow::{Result, bail}; +use mongodb::{Client, options::ClientOptions}; +use std::collections::HashMap; +use std::sync::Mutex; +use std::time::{Duration, Instant}; + +use crate::config::{ConnectionConfig, PoolConfig}; + +struct ClientState { + client: Client, + last_used: Instant, +} + +pub struct ConnectionManager { + clients: Mutex>, + configs: Mutex>, + pool_config: PoolConfig, +} + +impl ConnectionManager { + pub fn new(configs: &[ConnectionConfig], pool_config: PoolConfig) -> Result { + let mut config_map = HashMap::new(); + + for cfg in configs { + config_map.insert(cfg.name.clone(), cfg.clone()); + println!(" Registered: {} ({}/{})", cfg.name, cfg.host, cfg.database); + } + + println!("\n{} connection(s) configured (lazy init)", config_map.len()); + println!("Pool config: idle_timeout={}s", pool_config.idle_timeout_secs); + + Ok(Self { + clients: Mutex::new(HashMap::new()), + configs: Mutex::new(config_map), + pool_config, + }) + } + + pub async fn get_client(&self, name: &str) -> Result { + // 1. 已有客户端 + { + let mut clients = self.clients.lock().unwrap(); + if let Some(state) = clients.get_mut(name) { + state.last_used = Instant::now(); + return Ok(state.client.clone()); + } + } + + // 2. 创建新客户端 + let cfg = self.configs.lock().unwrap().get(name) + .ok_or_else(|| anyhow::anyhow!("Connection '{}' not found", name))? + .clone(); + + println!("[LazyInit] Creating MongoDB client for: {}", name); + let client = self.create_client(&cfg).await?; + let state = ClientState { + client: client.clone(), + last_used: Instant::now(), + }; + + self.clients.lock().unwrap().insert(name.to_string(), state); + Ok(client) + } + + async fn create_client(&self, cfg: &ConnectionConfig) -> Result { + let uri = cfg.build_uri(); + let mut opts = ClientOptions::parse(&uri).await?; + + // 连接超时 + opts.connect_timeout = Some(Duration::from_secs(5)); + opts.server_selection_timeout = Some(Duration::from_secs(5)); + + let client = Client::with_options(opts)?; + + // 测试连接 + client.database(&cfg.database).run_command(mongodb::bson::doc! {"ping": 1}).await?; + + println!("[LazyInit] ✓ Connected: {}", cfg.name); + Ok(client) + } + + pub fn list_connections(&self) -> Vec { + let clients = self.clients.lock().unwrap(); + let configs = self.configs.lock().unwrap(); + + configs.iter().map(|(name, cfg)| { + let status = if clients.contains_key(name) { "connected" } else { "pending" }; + ConnectionInfo { + name: name.clone(), + database: cfg.database.clone(), + host: cfg.host.clone(), + status: status.to_string(), + } + }).collect() + } + + pub fn cleanup_idle(&self) { + let mut clients = self.clients.lock().unwrap(); + let now = Instant::now(); + let idle_timeout = Duration::from_secs(self.pool_config.idle_timeout_secs); + + clients.retain(|name, state| { + let elapsed = now.duration_since(state.last_used); + if elapsed > idle_timeout { + println!("[Cleanup] Removing idle client: {} (idle {}s)", name, elapsed.as_secs()); + return false; + } + true + }); + } + + pub async fn add_connection(&self, cfg: ConnectionConfig) -> Result<()> { + let name = cfg.name.clone(); + + // 先检查是否已存在(configs 锁短暂持有) + { + let configs = self.configs.lock().unwrap(); + if configs.contains_key(&name) { + bail!("Connection '{}' already exists", name); + } + } + + println!("[Dynamic] Adding: {} ({}/{})", name, cfg.host, cfg.database); + let client = self.create_client(&cfg).await?; + + // 先写 configs 再写 clients,与 get_client 的读取顺序一致 + self.configs.lock().unwrap().insert(name.clone(), cfg); + self.clients.lock().unwrap().insert(name.clone(), ClientState { + client: client.clone(), + last_used: Instant::now(), + }); + + println!("[Dynamic] ✓ Added: {}", name); + Ok(()) + } +} + +#[derive(Debug, Clone, serde::Serialize)] +pub struct ConnectionInfo { + pub name: String, + pub database: String, + pub host: String, + pub status: String, +} diff --git a/mongo-proxy/src/handler.rs b/mongo-proxy/src/handler.rs new file mode 100644 index 0000000..311d16f --- /dev/null +++ b/mongo-proxy/src/handler.rs @@ -0,0 +1,457 @@ +use axum::{ + extract::State, + http::StatusCode, + Json, +}; +use futures_util::TryStreamExt; +use mongodb::bson::Document; +use serde::{Deserialize, Serialize}; +use std::sync::Arc; +use std::time::Instant; + +use crate::db::ConnectionManager; +use crate::logger::{LogEntry, RequestLogger}; + +pub type AppState = Arc<(Arc, Arc)>; + +// ============== 请求结构 ============== + +#[derive(Debug, Deserialize)] +pub struct FindRequest { + pub conn: String, + pub collection: String, + #[serde(default)] + pub filter: Option, + #[serde(default)] + pub projection: Option, + #[serde(default)] + pub sort: Option, + #[serde(default)] + pub limit: Option, + #[serde(default)] + pub skip: Option, +} + +#[derive(Debug, Deserialize)] +pub struct InsertRequest { + pub conn: String, + pub collection: String, + pub documents: Vec, +} + +#[derive(Debug, Deserialize)] +pub struct UpdateRequest { + pub conn: String, + pub collection: String, + pub filter: Document, + pub update: Document, + #[serde(default)] + pub upsert: Option, + #[serde(default)] + pub multi: Option, +} + +#[derive(Debug, Deserialize)] +pub struct DeleteRequest { + pub conn: String, + pub collection: String, + pub filter: Document, + #[serde(default)] + pub multi: Option, +} + +#[derive(Debug, Deserialize)] +pub struct AggregateRequest { + pub conn: String, + pub collection: String, + pub pipeline: Vec, +} + +#[derive(Debug, Deserialize)] +pub struct CountRequest { + pub conn: String, + pub collection: String, + #[serde(default)] + pub filter: Option, +} + +#[derive(Debug, Deserialize)] +pub struct AddConnectionRequest { + pub name: String, + pub host: String, + #[serde(default = "default_port")] + pub port: u16, + pub database: String, + pub username: Option, + pub password: Option, + pub auth_source: Option, +} + +fn default_port() -> u16 { 27017 } + +// ============== 响应结构 ============== + +#[derive(Debug, Serialize)] +pub struct FindResponse { + pub documents: Vec, + pub count: usize, + #[serde(rename = "durationMs")] + pub duration_ms: u64, +} + +#[derive(Debug, Serialize)] +pub struct InsertResponse { + #[serde(rename = "insertedIds")] + pub inserted_ids: Vec, + #[serde(rename = "insertedCount")] + pub inserted_count: usize, + #[serde(rename = "durationMs")] + pub duration_ms: u64, +} + +#[derive(Debug, Serialize)] +pub struct UpdateResponse { + #[serde(rename = "matchedCount")] + pub matched_count: u64, + #[serde(rename = "modifiedCount")] + pub modified_count: u64, + #[serde(rename = "upsertedId")] + pub upserted_id: Option, + #[serde(rename = "durationMs")] + pub duration_ms: u64, +} + +#[derive(Debug, Serialize)] +pub struct DeleteResponse { + #[serde(rename = "deletedCount")] + pub deleted_count: u64, + #[serde(rename = "durationMs")] + pub duration_ms: u64, +} + +#[derive(Debug, Serialize)] +pub struct AggregateResponse { + pub documents: Vec, + #[serde(rename = "durationMs")] + pub duration_ms: u64, +} + +#[derive(Debug, Serialize)] +pub struct CountResponse { + pub count: u64, + #[serde(rename = "durationMs")] + pub duration_ms: u64, +} + +#[derive(Debug, Serialize)] +pub struct ConnectionsResponse { + pub connections: Vec, +} + +#[derive(Debug, Serialize)] +pub struct HealthResponse { + pub status: String, + pub connections: usize, +} + +#[derive(Debug, Serialize)] +pub struct ErrorResponse { + pub error: String, + #[serde(rename = "usage")] + pub usage: Option, +} + +impl ErrorResponse { + pub fn new(msg: &str) -> Self { + Self { error: msg.to_string(), usage: None } + } + + pub fn with_usage(mut self, usage: &str) -> Self { + self.usage = Some(usage.to_string()); + self + } +} + +// ============== 处理器 ============== + +pub async fn find( + State(state): State, + Json(req): Json, +) -> Result, (StatusCode, Json)> { + let (manager, logger) = &*state; + let start = Instant::now(); + + let client = manager.get_client(&req.conn).await + .map_err(|e| error_response_with_usage(&e.to_string(), + &format!("Usage: POST /find {{\"conn\": \"name\", \"collection\": \"coll\", \"filter\": {{}}}}\nAvailable: {}", list_conn_names(manager))))?; + + let db = client.database(&get_database(manager, &req.conn)); + let coll = db.collection::(&req.collection); + + let mut find = coll.find(req.filter.unwrap_or_default()); + if let Some(p) = req.projection { find = find.projection(p); } + if let Some(s) = req.sort { find = find.sort(s); } + if let Some(l) = req.limit { find = find.limit(l); } + if let Some(s) = req.skip { find = find.skip(s); } + + let mut cursor = find.await + .map_err(|e| error_response(&e.to_string()))?; + + let mut documents = Vec::new(); + while let Some(result) = cursor.try_next().await.map_err(|e: mongodb::error::Error| error_response(&e.to_string()))? { + documents.push(bson_to_json(&result)); + } + + let count = documents.len(); + let duration = start.elapsed(); + + logger.log(&LogEntry::new("/find", "http") + .with_conn(&req.conn) + .with_command(&format!("{}.{}", req.conn, req.collection)) + .with_duration(duration.as_millis() as u64) + .with_rows(count)); + + Ok(Json(FindResponse { documents, count, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn insert( + State(state): State, + Json(req): Json, +) -> Result, (StatusCode, Json)> { + let (manager, logger) = &*state; + let start = Instant::now(); + + let client = manager.get_client(&req.conn).await + .map_err(|e| error_response_with_usage(&e.to_string(), + &format!("Usage: POST /insert {{\"conn\": \"name\", \"collection\": \"coll\", \"documents\": [{{}}]}}")))?; + + let db = client.database(&get_database(manager, &req.conn)); + let coll = db.collection::(&req.collection); + + let result = coll.insert_many(req.documents).await + .map_err(|e| error_response(&e.to_string()))?; + + let inserted_ids: Vec = result.inserted_ids.iter() + .map(|(k, v)| format!("{}:{}", k, v)) + .collect(); + let inserted_count = result.inserted_ids.len(); + let duration = start.elapsed(); + + logger.log(&LogEntry::new("/insert", "http") + .with_conn(&req.conn) + .with_command(&format!("{}.{}", req.conn, req.collection)) + .with_duration(duration.as_millis() as u64) + .with_rows(inserted_count)); + + Ok(Json(InsertResponse { inserted_ids, inserted_count, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn update( + State(state): State, + Json(req): Json, +) -> Result, (StatusCode, Json)> { + let (manager, logger) = &*state; + let start = Instant::now(); + + let client = manager.get_client(&req.conn).await + .map_err(|e| error_response_with_usage(&e.to_string(), + "Usage: POST /update {\"conn\": \"name\", \"collection\": \"coll\", \"filter\": {}, \"update\": {\"$set\": {}}}"))?; + + let db = client.database(&get_database(manager, &req.conn)); + let coll = db.collection::(&req.collection); + + let result = if req.multi.unwrap_or(false) { + let mut cmd = coll.update_many(req.filter, req.update); + if req.upsert.unwrap_or(false) { cmd = cmd.upsert(true); } + cmd.await + } else { + let mut cmd = coll.update_one(req.filter, req.update); + if req.upsert.unwrap_or(false) { cmd = cmd.upsert(true); } + cmd.await + }.map_err(|e| error_response(&e.to_string()))?; + + let upserted_id = result.upserted_id.map(|id| format!("{:?}", id)); + let duration = start.elapsed(); + + logger.log(&LogEntry::new("/update", "http") + .with_conn(&req.conn) + .with_command(&format!("{}.{}", req.conn, req.collection)) + .with_duration(duration.as_millis() as u64)); + + Ok(Json(UpdateResponse { + matched_count: result.matched_count, + modified_count: result.modified_count, + upserted_id, + duration_ms: duration.as_millis() as u64, + })) +} + +pub async fn delete( + State(state): State, + Json(req): Json, +) -> Result, (StatusCode, Json)> { + let (manager, logger) = &*state; + let start = Instant::now(); + + let client = manager.get_client(&req.conn).await + .map_err(|e| error_response_with_usage(&e.to_string(), + "Usage: POST /delete {\"conn\": \"name\", \"collection\": \"coll\", \"filter\": {}}"))?; + + let db = client.database(&get_database(manager, &req.conn)); + let coll = db.collection::(&req.collection); + + let result = if req.multi.unwrap_or(false) { + coll.delete_many(req.filter).await + } else { + coll.delete_one(req.filter).await + }.map_err(|e| error_response(&e.to_string()))?; + + let deleted_count = result.deleted_count; + let duration = start.elapsed(); + + logger.log(&LogEntry::new("/delete", "http") + .with_conn(&req.conn) + .with_command(&format!("{}.{}", req.conn, req.collection)) + .with_duration(duration.as_millis() as u64)); + + Ok(Json(DeleteResponse { deleted_count, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn aggregate( + State(state): State, + Json(req): Json, +) -> Result, (StatusCode, Json)> { + let (manager, logger) = &*state; + let start = Instant::now(); + + let client = manager.get_client(&req.conn).await + .map_err(|e| error_response_with_usage(&e.to_string(), + "Usage: POST /aggregate {\"conn\": \"name\", \"collection\": \"coll\", \"pipeline\": [{\"$match\": {}}, ...]}"))?; + + let db = client.database(&get_database(manager, &req.conn)); + let coll = db.collection::(&req.collection); + + let mut cursor = coll.aggregate(req.pipeline).await + .map_err(|e| error_response(&e.to_string()))?; + + let mut documents = Vec::new(); + while let Some(result) = cursor.try_next().await.map_err(|e: mongodb::error::Error| error_response(&e.to_string()))? { + documents.push(bson_to_json(&result)); + } + + let count = documents.len(); + let duration = start.elapsed(); + + logger.log(&LogEntry::new("/aggregate", "http") + .with_conn(&req.conn) + .with_command(&format!("{}.{}", req.conn, req.collection)) + .with_duration(duration.as_millis() as u64) + .with_rows(count)); + + Ok(Json(AggregateResponse { documents, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn count( + State(state): State, + Json(req): Json, +) -> Result, (StatusCode, Json)> { + let (manager, logger) = &*state; + let start = Instant::now(); + + let client = manager.get_client(&req.conn).await + .map_err(|e| error_response_with_usage(&e.to_string(), + "Usage: POST /count {\"conn\": \"name\", \"collection\": \"coll\", \"filter\": {}}"))?; + + let db = client.database(&get_database(manager, &req.conn)); + let coll = db.collection::(&req.collection); + + let count = coll.count_documents(req.filter.unwrap_or_default()).await + .map_err(|e| error_response(&e.to_string()))?; + + let duration = start.elapsed(); + + logger.log(&LogEntry::new("/count", "http") + .with_conn(&req.conn) + .with_command(&format!("{}.{}", req.conn, req.collection)) + .with_duration(duration.as_millis() as u64)); + + Ok(Json(CountResponse { count, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn connections( + State(state): State, +) -> Json { + let (manager, _) = &*state; + Json(ConnectionsResponse { + connections: manager.list_connections(), + }) +} + +pub async fn health( + State(state): State, +) -> Json { + let (manager, _) = &*state; + Json(HealthResponse { + status: "ok".to_string(), + connections: manager.list_connections().len(), + }) +} + +pub async fn add_connection( + State(state): State, + Json(req): Json, +) -> Result, (StatusCode, Json)> { + let (manager, logger) = &*state; + use crate::config::ConnectionConfig; + + let cfg = ConnectionConfig { + name: req.name.clone(), + host: req.host, + port: req.port, + database: req.database, + username: req.username, + password: req.password, + auth_source: req.auth_source, + }; + + manager.add_connection(cfg).await + .map_err(|e| error_response(&e.to_string()))?; + + logger.log(&LogEntry::new("/connections/add", "http") + .with_conn(&req.name) + .with_duration(0)); + + Ok(Json(serde_json::json!({ + "success": true, + "message": format!("Connection '{}' added (temporary)", req.name) + }))) +} + +// ============== 辅助函数 ============== + +fn error_response(msg: &str) -> (StatusCode, Json) { + (StatusCode::BAD_REQUEST, Json(ErrorResponse::new(msg))) +} + +fn error_response_with_usage(msg: &str, usage: &str) -> (StatusCode, Json) { + (StatusCode::BAD_REQUEST, Json(ErrorResponse::new(msg).with_usage(usage))) +} + +fn list_conn_names(manager: &ConnectionManager) -> String { + manager.list_connections() + .iter() + .map(|c| c.name.clone()) + .collect::>() + .join(", ") +} + +fn get_database(manager: &ConnectionManager, name: &str) -> String { + manager.list_connections().iter() + .find(|c| c.name == name) + .map(|c| c.database.clone()) + .unwrap_or_default() +} + +fn bson_to_json(doc: &Document) -> serde_json::Value { + serde_json::to_value(doc).unwrap_or(serde_json::Value::Null) +} diff --git a/mongo-proxy/src/logger.rs b/mongo-proxy/src/logger.rs new file mode 100644 index 0000000..852983c --- /dev/null +++ b/mongo-proxy/src/logger.rs @@ -0,0 +1,150 @@ +use serde::{Deserialize, Serialize}; +use std::fs::{File, OpenOptions}; +use std::io::Write; +use std::path::PathBuf; +use std::sync::Mutex; + +pub struct RequestLogger { + log_file: Mutex>, + enabled: bool, +} + +impl RequestLogger { + pub fn new(log_path: Option<&str>) -> Self { + let (log_file, enabled) = if let Some(path) = log_path { + let path = expand_path(path); + if let Some(parent) = path.parent() { + let _ = std::fs::create_dir_all(parent); + } + match OpenOptions::new() + .create(true) + .append(true) + .open(&path) + { + Ok(file) => (Some(file), true), + Err(e) => { + eprintln!("[Logger] Failed to open log file {}: {}", path.display(), e); + (None, false) + } + } + } else { + (None, false) + }; + + Self { log_file: Mutex::new(log_file), enabled } + } + + pub fn is_enabled(&self) -> bool { self.enabled } + + pub fn log(&self, entry: &LogEntry) { + if !self.enabled { return; } + + let json = match serde_json::to_string(entry) { + Ok(j) => j, + Err(e) => { + eprintln!("[Logger] Failed to serialize log: {}", e); + return; + } + }; + + if let Ok(mut file) = self.log_file.lock() { + if let Some(ref mut f) = *file { + let _ = writeln!(f, "{}", json); + } + } + } +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct LogEntry { + pub timestamp: String, + pub level: String, + #[serde(rename = "type")] + pub log_type: String, + pub client: String, + pub endpoint: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub conn: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub command: Option, + #[serde(rename = "durationMs")] + pub duration_ms: u64, + #[serde(skip_serializing_if = "Option::is_none")] + pub rows: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub error: Option, +} + +impl LogEntry { + pub fn new(endpoint: &str, client: &str) -> Self { + Self { + timestamp: current_timestamp(), + level: "INFO".to_string(), + log_type: "request".to_string(), + client: client.to_string(), + endpoint: endpoint.to_string(), + conn: None, + command: None, + duration_ms: 0, + rows: None, + error: None, + } + } + + pub fn with_conn(mut self, conn: &str) -> Self { + self.conn = Some(conn.to_string()); + self + } + + pub fn with_command(mut self, cmd: &str) -> Self { + self.command = Some(truncate_string(cmd, 500)); + self + } + + pub fn with_duration(mut self, ms: u64) -> Self { + self.duration_ms = ms; + if ms > 5000 && self.level == "INFO" { + self.level = "ERROR".to_string(); + } else if ms > 2000 && self.level == "INFO" { + self.level = "WARN".to_string(); + } + self + } + + pub fn with_rows(mut self, rows: usize) -> Self { + self.rows = Some(rows); + self + } + + #[allow(dead_code)] + pub fn with_error(mut self, error: &str) -> Self { + self.level = "ERROR".to_string(); + self.error = Some(error.to_string()); + self + } +} + +fn current_timestamp() -> String { + time::OffsetDateTime::now_utc() + .format(&time::macros::format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]")) + .unwrap_or_default() +} + +fn truncate_string(s: &str, max_len: usize) -> String { + if s.chars().count() <= max_len { + s.to_string() + } else { + format!("{}... (truncated)", s.chars().take(max_len).collect::()) + } +} + +fn expand_path(path: &str) -> PathBuf { + if path.starts_with('~') { + let home = std::env::var("HOME") + .or_else(|_| std::env::var("USERPROFILE")) + .unwrap_or_default(); + PathBuf::from(path.replacen('~', &home, 1)) + } else { + PathBuf::from(path) + } +} diff --git a/mongo-proxy/src/main.rs b/mongo-proxy/src/main.rs new file mode 100644 index 0000000..fa6e422 --- /dev/null +++ b/mongo-proxy/src/main.rs @@ -0,0 +1,310 @@ +mod cli; +mod config; +mod db; +mod handler; +mod logger; + +use axum::{ + routing::{get, post}, + Router, +}; +use clap::{Parser, Subcommand}; +use std::sync::Arc; + +#[derive(Parser, Debug)] +#[command(name = "mongo-proxy")] +#[command(about = "MongoDB HTTP proxy with connection pooling")] +struct Args { + #[command(subcommand)] + command: Option, + + /// Config file path + #[arg(long, default_value = "mongo-proxy.toml", global = true)] + config: String, + + /// Server URL (for CLI mode) + #[arg(short = 'S', long, default_value = "http://127.0.0.1:3309", global = true)] + server: String, +} + +#[derive(Debug, Subcommand)] +enum Commands { + /// Start HTTP server (default) + Server { + #[arg(short = 'P', long)] + port: Option, + + #[arg(short = 'H', long)] + host: Option, + }, + + /// Find documents + Find { + /// Connection name + #[arg(short, long)] + conn: String, + + /// Collection name + #[arg(short = 'C', long)] + collection: String, + + /// Filter JSON + #[arg(short, long, default_value = "{}")] + filter: String, + + /// Projection JSON + #[arg(short, long)] + projection: Option, + + /// Limit + #[arg(short, long)] + limit: Option, + + /// Skip + #[arg(short, long)] + skip: Option, + + /// Output format: json, pretty + #[arg(short = 'F', long, default_value = "pretty")] + format: String, + }, + + /// Insert documents + Insert { + #[arg(short, long)] + conn: String, + + #[arg(short = 'C', long)] + collection: String, + + /// Documents JSON array + #[arg(short, long)] + documents: String, + }, + + /// Update documents + Update { + #[arg(short, long)] + conn: String, + + #[arg(short = 'C', long)] + collection: String, + + /// Filter JSON + #[arg(short, long)] + filter: String, + + /// Update JSON + #[arg(short, long)] + update: String, + + /// Upsert + #[arg(long)] + upsert: bool, + + /// Update multiple + #[arg(long)] + multi: bool, + }, + + /// Delete documents + Delete { + #[arg(short, long)] + conn: String, + + #[arg(short = 'C', long)] + collection: String, + + /// Filter JSON + #[arg(short, long)] + filter: String, + + /// Delete multiple + #[arg(long)] + multi: bool, + }, + + /// Aggregate pipeline + Aggregate { + #[arg(short, long)] + conn: String, + + #[arg(short = 'C', long)] + collection: String, + + /// Pipeline JSON array + #[arg(long)] + pipeline: String, + }, + + /// Count documents + Count { + #[arg(short, long)] + conn: String, + + #[arg(short = 'C', long)] + collection: String, + + /// Filter JSON + #[arg(short, long)] + filter: Option, + }, + + /// List available connections + Connections, +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let args = Args::parse(); + + match args.command { + Some(Commands::Server { port, host }) => { + run_server(&args.config, port, host).await + } + Some(Commands::Find { conn, collection, filter, projection, limit, skip, format }) => { + run_find(&args.server, &conn, &collection, &filter, &format, projection.as_deref(), limit, skip) + } + Some(Commands::Insert { conn, collection, documents }) => { + run_insert(&args.server, &conn, &collection, &documents) + } + Some(Commands::Update { conn, collection, filter, update, upsert, multi }) => { + run_update(&args.server, &conn, &collection, &filter, &update, upsert, multi) + } + Some(Commands::Delete { conn, collection, filter, multi }) => { + run_delete(&args.server, &conn, &collection, &filter, multi) + } + Some(Commands::Aggregate { conn, collection, pipeline }) => { + run_aggregate(&args.server, &conn, &collection, &pipeline) + } + Some(Commands::Count { conn, collection, filter }) => { + run_count(&args.server, &conn, &collection, filter.as_deref()) + } + Some(Commands::Connections) => { + list_connections(&args.server) + } + None => { + run_server(&args.config, None, None).await + } + } +} + +async fn run_server(config_path: &str, port: Option, host: Option) -> anyhow::Result<()> { + println!("MongoDB HTTP Proxy v0.1.0\n"); + + let mut config = config::Config::from_file(config_path)?; + + if let Some(port) = port { + config.server.port = port; + } + if let Some(host) = host { + config.server.host = host; + } + + let log_path = std::env::var("MONGO_PROXY_LOG").ok(); + let logger = Arc::new(logger::RequestLogger::new(log_path.as_deref())); + if logger.is_enabled() { + println!("Request logging: enabled"); + } + + println!("Initializing connection pools...\n"); + let manager = Arc::new(db::ConnectionManager::new(&config.connections, config.pool.clone())?); + + let manager_clone = manager.clone(); + let check_interval = config.pool.check_interval_secs; + tokio::spawn(async move { + let mut interval = tokio::time::interval(std::time::Duration::from_secs(check_interval)); + loop { + interval.tick().await; + manager_clone.cleanup_idle(); + } + }); + + let app = Router::new() + .route("/find", post(handler::find)) + .route("/insert", post(handler::insert)) + .route("/update", post(handler::update)) + .route("/delete", post(handler::delete)) + .route("/aggregate", post(handler::aggregate)) + .route("/count", post(handler::count)) + .route("/connections", get(handler::connections)) + .route("/connections/add", post(handler::add_connection)) + .route("/health", get(handler::health)) + .with_state(Arc::new((manager, logger))); + + let addr = format!("{}:{}", config.server.host, config.server.port); + let listener = tokio::net::TcpListener::bind(&addr).await?; + + println!("\nServer started at http://{}", addr); + println!("\nAPI Endpoints:"); + println!(" POST /find - Query documents"); + println!(" POST /insert - Insert documents"); + println!(" POST /update - Update documents"); + println!(" POST /delete - Delete documents"); + println!(" POST /aggregate - Aggregation pipeline"); + println!(" POST /count - Count documents"); + println!(" GET /connections - List all connections"); + println!(" POST /connections/add - Add connection (temporary)"); + println!(" GET /health - Health check"); + println!("\nCLI Usage:"); + println!(" mongo-proxy find -c flux_dev -C users -f '{{\"status\": 1}}'"); + println!(" mongo-proxy insert -c flux_dev -C users -d '[{{\"name\": \"test\"}}]'"); + println!(" mongo-proxy aggregate -c flux_dev -C users --pipeline '[{{\"$match\": {{}}}}]'"); + println!(" mongo-proxy connections"); + + axum::serve(listener, app).await?; + Ok(()) +} + +fn run_cli(server: &str) -> anyhow::Result { + let c = cli::Cli::new(Some(server.to_string())); + if !c.check_server()? { + eprintln!(); + eprintln!("=== mongo-proxy 未运行,请使用降级方案 ==="); + eprintln!(); + eprintln!("启动代理: mongo-proxy"); + eprintln!(); + eprintln!("或直接使用 mongosh:"); + eprintln!(" mongosh \"mongodb://user:pass@host:27017/db\""); + eprintln!(); + eprintln!("配置文件中的连接信息见: mongo-proxy.toml"); + anyhow::bail!("Proxy server not running at {}", server); + } + Ok(c) +} + +fn run_find(server: &str, conn: &str, collection: &str, filter: &str, format: &str, + projection: Option<&str>, limit: Option, skip: Option) -> anyhow::Result<()> { + let cli = run_cli(server)?; + cli.find(conn, collection, filter, format, projection, limit, skip) +} + +fn run_insert(server: &str, conn: &str, collection: &str, documents: &str) -> anyhow::Result<()> { + let cli = run_cli(server)?; + cli.insert(conn, collection, documents) +} + +fn run_update(server: &str, conn: &str, collection: &str, filter: &str, update: &str, upsert: bool, multi: bool) -> anyhow::Result<()> { + let cli = run_cli(server)?; + cli.update(conn, collection, filter, update, upsert, multi) +} + +fn run_delete(server: &str, conn: &str, collection: &str, filter: &str, multi: bool) -> anyhow::Result<()> { + let cli = run_cli(server)?; + cli.delete(conn, collection, filter, multi) +} + +fn run_aggregate(server: &str, conn: &str, collection: &str, pipeline: &str) -> anyhow::Result<()> { + let cli = run_cli(server)?; + cli.aggregate(conn, collection, pipeline) +} + +fn run_count(server: &str, conn: &str, collection: &str, filter: Option<&str>) -> anyhow::Result<()> { + let cli = run_cli(server)?; + cli.count(conn, collection, filter) +} + +fn list_connections(server: &str) -> anyhow::Result<()> { + let cli = run_cli(server)?; + cli.list_connections() +} diff --git a/redis-proxy/Cargo.lock b/redis-proxy/Cargo.lock new file mode 100644 index 0000000..4929502 --- /dev/null +++ b/redis-proxy/Cargo.lock @@ -0,0 +1,1491 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "arc-swap" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a07d1f37ff60921c83bdfc7407723bdefe89b44b98a9b772f225c8f9d67141a6" +dependencies = [ + "rustversion", +] + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "axum" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "clap" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "bytes", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "libc" +version = "0.2.183" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redis" +version = "0.27.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d8f99a4090c89cc489a94833c901ead69bfbf3877b4867d5482e321ee875bc" +dependencies = [ + "arc-swap", + "combine", + "itertools", + "itoa", + "num-bigint", + "percent-encoding", + "ryu", + "sha1_smol", + "socket2 0.5.10", + "url", +] + +[[package]] +name = "redis-proxy" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "clap", + "redis", + "serde", + "serde_json", + "time", + "tokio", + "toml", + "ureq", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.23.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df33b2b81ac578cabaf06b89b0631153a3f416b0a886e8a7a1707fb51abbd1ef" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1_smol" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "simd-adler32" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" + +[[package]] +name = "time-macros" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tokio" +version = "1.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.6.3", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" +dependencies = [ + "base64", + "flate2", + "log", + "once_cell", + "rustls", + "rustls-pki-types", + "url", + "webpki-roots 0.26.11", +] + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.6", +] + +[[package]] +name = "webpki-roots" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" +dependencies = [ + "memchr", +] + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/redis-proxy/Cargo.toml b/redis-proxy/Cargo.toml new file mode 100644 index 0000000..a9e0cc0 --- /dev/null +++ b/redis-proxy/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "redis-proxy" +version = "0.1.0" +edition = "2021" +description = "Redis HTTP proxy with connection pooling" + +[dependencies] +redis = "0.27" +tokio = { version = "1", features = ["full"] } +axum = "0.7" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +toml = "0.8" +anyhow = "1" +clap = { version = "4", features = ["derive"] } +ureq = "2" +time = { version = "0.3", features = ["formatting", "macros"] } + +[profile.release] +opt-level = "z" +lto = true +strip = true diff --git a/redis-proxy/redis-proxy.toml b/redis-proxy/redis-proxy.toml new file mode 100644 index 0000000..7122ecb --- /dev/null +++ b/redis-proxy/redis-proxy.toml @@ -0,0 +1,14 @@ +[server] +port = 3310 +host = "127.0.0.1" + +[pool] +idle_timeout_secs = 300 +check_interval_secs = 60 + +[[connections]] +name = "flux_dev" +host = "39.99.243.191" +port = 6379 +password = "suke123!" +db = 0 diff --git a/redis-proxy/src/cli.rs b/redis-proxy/src/cli.rs new file mode 100644 index 0000000..df5ac01 --- /dev/null +++ b/redis-proxy/src/cli.rs @@ -0,0 +1,107 @@ +use anyhow::{Result, bail}; +use serde::Deserialize; +use std::time::Instant; + +const DEFAULT_SERVER: &str = "http://127.0.0.1:3310"; + +#[derive(Debug, Deserialize)] +struct ErrorResponse { error: String } + +#[derive(Debug, Deserialize)] +struct ConnectionsResponse { connections: Vec } + +#[derive(Debug, Deserialize)] +struct ConnectionInfo { name: String, host: String, port: u16, db: i64, status: String } + +pub struct Cli { server: String } + +impl Cli { + pub fn new(server: Option) -> Self { Self { server: server.unwrap_or_else(|| DEFAULT_SERVER.to_string()) } } + pub fn check_server(&self) -> Result { match ureq::get(&format!("{}/health", self.server)).call() { Ok(_) => Ok(true), Err(_) => Ok(false) } } + + pub fn run(&self, conn: &str, command: &str, args: &[String]) -> Result<()> { + let start = Instant::now(); + let body = serde_json::json!({"conn": conn, "command": command, "args": args}); + let resp = post_json(&format!("{}/run", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + if let Ok(err) = serde_json::from_str::(&resp) { eprintln!("Error: {}", err.error); return Ok(()); } + #[derive(Deserialize)] struct RunResp { result: serde_json::Value, #[serde(rename = "durationMs")] duration_ms: u64 } + let result: RunResp = serde_json::from_str(&resp)?; + println!("{}", serde_json::to_string_pretty(&result.result).unwrap_or_default()); + println!("\n({}ms db, {}ms total)", result.duration_ms, total_ms); + Ok(()) + } + + pub fn get(&self, conn: &str, key: &str) -> Result<()> { + let start = Instant::now(); + let body = serde_json::json!({"conn": conn, "key": key}); + let resp = post_json(&format!("{}/get", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + if let Ok(err) = serde_json::from_str::(&resp) { eprintln!("Error: {}", err.error); return Ok(()); } + #[derive(Deserialize)] struct GetResp { value: Option, #[serde(rename = "durationMs")] duration_ms: u64 } + let result: GetResp = serde_json::from_str(&resp)?; + match result.value { Some(v) => println!("\"{}\"", v), None => println!("(nil)") } + println!("({}ms db, {}ms total)", result.duration_ms, total_ms); + Ok(()) + } + + pub fn set(&self, conn: &str, key: &str, value: &str, ttl: Option) -> Result<()> { + let start = Instant::now(); + let mut body = serde_json::json!({"conn": conn, "key": key, "value": value}); + if let Some(t) = ttl { body["ttl"] = serde_json::json!(t); } + let resp = post_json(&format!("{}/set", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + if let Ok(err) = serde_json::from_str::(&resp) { eprintln!("Error: {}", err.error); return Ok(()); } + #[derive(Deserialize)] struct SetResp { ok: bool, #[serde(rename = "durationMs")] duration_ms: u64 } + let result: SetResp = serde_json::from_str(&resp)?; + println!("OK ({}ms db, {}ms total)", result.duration_ms, total_ms); + Ok(()) + } + + pub fn del(&self, conn: &str, keys: &[String]) -> Result<()> { + let start = Instant::now(); + let body = serde_json::json!({"conn": conn, "keys": keys}); + let resp = post_json(&format!("{}/del", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + if let Ok(err) = serde_json::from_str::(&resp) { eprintln!("Error: {}", err.error); return Ok(()); } + #[derive(Deserialize)] struct DelResp { deleted: u64, #[serde(rename = "durationMs")] duration_ms: u64 } + let result: DelResp = serde_json::from_str(&resp)?; + println!("(integer) {}\n({}ms db, {}ms total)", result.deleted, result.duration_ms, total_ms); + Ok(()) + } + + pub fn keys(&self, conn: &str, pattern: &str) -> Result<()> { + let start = Instant::now(); + let body = serde_json::json!({"conn": conn, "pattern": pattern}); + let resp = post_json(&format!("{}/keys", self.server), &body)?; + let total_ms = start.elapsed().as_millis(); + if let Ok(err) = serde_json::from_str::(&resp) { eprintln!("Error: {}", err.error); return Ok(()); } + #[derive(Deserialize)] struct KeysResp { keys: Vec, #[serde(rename = "durationMs")] duration_ms: u64 } + let result: KeysResp = serde_json::from_str(&resp)?; + for key in &result.keys { println!("{}", key); } + println!("\n({} keys, {}ms db, {}ms total)", result.keys.len(), result.duration_ms, total_ms); + Ok(()) + } + + pub fn list_connections(&self) -> Result<()> { + let response = ureq::get(&format!("{}/connections", self.server)).call()?; + let body = response.into_string()?; + if let Ok(err) = serde_json::from_str::(&body) { bail!("{}", err.error); } + let result: ConnectionsResponse = serde_json::from_str(&body)?; + println!("Connections:"); + println!("{:<15} {:<25} {:<10} {:<5} {:<10}", "Name", "Host", "Port", "DB", "Status"); + println!("{}", "-".repeat(65)); + for conn in result.connections { println!("{:<15} {:<25} {:<10} {:<5} {:<10}", conn.name, conn.host, conn.port, conn.db, conn.status); } + Ok(()) + } +} + +fn post_json(url: &str, body: &serde_json::Value) -> Result { + let data = serde_json::to_string(body)?; + let response = ureq::post(url).set("Content-Type", "application/json").send_string(&data); + match response { + Ok(r) => Ok(r.into_string()?), + Err(ureq::Error::Status(_, resp)) => Ok(resp.into_string()?), + Err(e) => bail!("HTTP error: {}", e), + } +} diff --git a/redis-proxy/src/config.rs b/redis-proxy/src/config.rs new file mode 100644 index 0000000..7b6bcb5 --- /dev/null +++ b/redis-proxy/src/config.rs @@ -0,0 +1,84 @@ +use anyhow::{Result, bail}; +use serde::Deserialize; +use std::fs; + +#[derive(Debug, Deserialize, Clone)] +pub struct ServerConfig { + pub port: u16, + #[serde(default = "default_host")] + pub host: String, +} + +fn default_host() -> String { "127.0.0.1".to_string() } + +#[derive(Debug, Deserialize, Clone)] +pub struct PoolConfig { + #[serde(default = "default_idle_timeout")] + pub idle_timeout_secs: u64, + #[serde(default = "default_check_interval")] + pub check_interval_secs: u64, +} + +fn default_idle_timeout() -> u64 { 300 } +fn default_check_interval() -> u64 { 60 } + +impl Default for PoolConfig { + fn default() -> Self { + Self { idle_timeout_secs: default_idle_timeout(), check_interval_secs: default_check_interval() } + } +} + +#[derive(Debug, Deserialize, Clone)] +pub struct ConnectionConfig { + pub name: String, + pub host: String, + #[serde(default = "default_port")] + pub port: u16, + #[serde(default)] + pub password: Option, + #[serde(default)] + pub db: i64, +} + +pub fn default_port() -> u16 { 6379 } + +#[derive(Debug, Deserialize)] +pub struct Config { + #[serde(default = "default_server")] + pub server: ServerConfig, + #[serde(default)] + pub pool: PoolConfig, + pub connections: Vec, +} + +fn default_server() -> ServerConfig { + ServerConfig { port: 3310, host: "127.0.0.1".to_string() } +} + +impl Config { + pub fn from_file(path: &str) -> Result { + let content = fs::read_to_string(path)?; + let config: Config = toml::from_str(&content)?; + config.validate()?; + Ok(config) + } + + fn validate(&self) -> Result<()> { + let mut names = std::collections::HashSet::new(); + for conn in &self.connections { + if conn.name.is_empty() { bail!("Connection name cannot be empty"); } + if names.contains(&conn.name) { bail!("Duplicate connection name: {}", conn.name); } + names.insert(conn.name.clone()); + } + Ok(()) + } +} + +impl ConnectionConfig { + pub fn build_url(&self) -> String { + match &self.password { + Some(pass) => format!("redis://:{}@{}:{}/{}", pass, self.host, self.port, self.db), + None => format!("redis://{}:{}/{}", self.host, self.port, self.db), + } + } +} diff --git a/redis-proxy/src/db.rs b/redis-proxy/src/db.rs new file mode 100644 index 0000000..f4f59a2 --- /dev/null +++ b/redis-proxy/src/db.rs @@ -0,0 +1,102 @@ +use anyhow::{Result, bail}; +use redis::Client as RedisClient; +use std::collections::HashMap; +use std::sync::Mutex; +use std::time::{Duration, Instant}; + +use crate::config::{ConnectionConfig, PoolConfig}; + +struct ClientState { + client: RedisClient, + last_used: Instant, +} + +pub struct ConnectionManager { + clients: Mutex>, + configs: Mutex>, + pool_config: PoolConfig, +} + +impl ConnectionManager { + pub fn new(configs: &[ConnectionConfig], pool_config: PoolConfig) -> Result { + let mut config_map = HashMap::new(); + for cfg in configs { + config_map.insert(cfg.name.clone(), cfg.clone()); + println!(" Registered: {} ({}:{}/{})", cfg.name, cfg.host, cfg.port, cfg.db); + } + println!("\n{} connection(s) configured (lazy init)", config_map.len()); + println!("Pool config: idle_timeout={}s", pool_config.idle_timeout_secs); + Ok(Self { clients: Mutex::new(HashMap::new()), configs: Mutex::new(config_map), pool_config }) + } + + pub fn get_conn(&self, name: &str) -> Result<(RedisClient, ConnectionConfig)> { + let client = { + let mut clients = self.clients.lock().unwrap(); + if let Some(state) = clients.get_mut(name) { + state.last_used = Instant::now(); + Some(state.client.clone()) + } else { None } + }; + if let Some(client) = client { + let cfg = self.configs.lock().unwrap().get(name).unwrap().clone(); + return Ok((client, cfg)); + } + let cfg = self.configs.lock().unwrap().get(name) + .ok_or_else(|| anyhow::anyhow!("Connection '{}' not found", name))?.clone(); + println!("[LazyInit] Creating Redis client for: {}", name); + let client = self.create_client(&cfg)?; + self.clients.lock().unwrap().insert(name.to_string(), ClientState { client: client.clone(), last_used: Instant::now() }); + Ok((client, cfg)) + } + + fn create_client(&self, cfg: &ConnectionConfig) -> Result { + let url = cfg.build_url(); + let client = RedisClient::open(url.as_str())?; + let mut conn = client.get_connection()?; + redis::cmd("PING").query::(&mut conn)?; + println!("[LazyInit] ✓ Connected: {}", cfg.name); + Ok(client) + } + + pub fn list_connections(&self) -> Vec { + let clients = self.clients.lock().unwrap(); + let configs = self.configs.lock().unwrap(); + configs.iter().map(|(name, cfg)| { + let status = if clients.contains_key(name) { "connected" } else { "pending" }; + ConnectionInfo { name: name.clone(), host: cfg.host.clone(), port: cfg.port, db: cfg.db, status: status.to_string() } + }).collect() + } + + pub fn cleanup_idle(&self) { + let mut clients = self.clients.lock().unwrap(); + let now = Instant::now(); + let idle_timeout = Duration::from_secs(self.pool_config.idle_timeout_secs); + clients.retain(|name, state| { + let elapsed = now.duration_since(state.last_used); + if elapsed > idle_timeout { + println!("[Cleanup] Removing idle client: {} (idle {}s)", name, elapsed.as_secs()); + false + } else { true } + }); + } + + pub fn add_connection(&self, cfg: ConnectionConfig) -> Result<()> { + let name = cfg.name.clone(); + { let configs = self.configs.lock().unwrap(); if configs.contains_key(&name) { bail!("Connection '{}' already exists", name); } } + println!("[Dynamic] Adding: {} ({}:{}/{})", name, cfg.host, cfg.port, cfg.db); + let client = self.create_client(&cfg)?; + self.configs.lock().unwrap().insert(name.clone(), cfg); + self.clients.lock().unwrap().insert(name.clone(), ClientState { client, last_used: Instant::now() }); + println!("[Dynamic] ✓ Added: {}", name); + Ok(()) + } +} + +#[derive(Debug, Clone, serde::Serialize)] +pub struct ConnectionInfo { + pub name: String, + pub host: String, + pub port: u16, + pub db: i64, + pub status: String, +} diff --git a/redis-proxy/src/handler.rs b/redis-proxy/src/handler.rs new file mode 100644 index 0000000..749caf0 --- /dev/null +++ b/redis-proxy/src/handler.rs @@ -0,0 +1,231 @@ +use axum::{extract::State, http::StatusCode, Json}; +use redis::Commands; +use serde::{Deserialize, Serialize}; +use std::sync::Arc; +use std::time::Instant; + +use crate::db::ConnectionManager; +use crate::logger::{LogEntry, RequestLogger}; + +pub type AppState = Arc<(Arc, Arc)>; + +// ============== 请求 ============== + +#[derive(Debug, Deserialize)] +pub struct RunRequest { pub conn: String, pub command: String, #[serde(default)] pub args: Vec } + +#[derive(Debug, Deserialize)] +pub struct GetRequest { pub conn: String, pub key: String } + +#[derive(Debug, Deserialize)] +pub struct SetRequest { pub conn: String, pub key: String, pub value: String, #[serde(default)] pub ttl: Option } + +#[derive(Debug, Deserialize)] +pub struct DelRequest { pub conn: String, pub keys: Vec } + +#[derive(Debug, Deserialize)] +pub struct KeysRequest { pub conn: String, pub pattern: String } + +#[derive(Debug, Deserialize)] +pub struct InfoRequest { pub conn: String } + +#[derive(Debug, Deserialize)] +pub struct AddConnectionRequest { pub name: String, pub host: String, #[serde(default = "crate::config::default_port")] pub port: u16, pub password: Option, #[serde(default)] pub db: i64 } + +// ============== 响应 ============== + +#[derive(Debug, Serialize)] +pub struct RunResponse { pub result: serde_json::Value, #[serde(rename = "durationMs")] pub duration_ms: u64 } + +#[derive(Debug, Serialize)] +pub struct GetResponse { pub value: Option, #[serde(rename = "durationMs")] pub duration_ms: u64 } + +#[derive(Debug, Serialize)] +pub struct SetResponse { pub ok: bool, #[serde(rename = "durationMs")] pub duration_ms: u64 } + +#[derive(Debug, Serialize)] +pub struct DelResponse { pub deleted: u64, #[serde(rename = "durationMs")] pub duration_ms: u64 } + +#[derive(Debug, Serialize)] +pub struct KeysResponse { pub keys: Vec, #[serde(rename = "durationMs")] pub duration_ms: u64 } + +#[derive(Debug, Serialize)] +pub struct InfoResponse { pub info: String, #[serde(rename = "durationMs")] pub duration_ms: u64 } + +#[derive(Debug, Serialize)] +pub struct ConnectionsResponse { pub connections: Vec } + +#[derive(Debug, Serialize)] +pub struct HealthResponse { pub status: String, pub connections: usize } + +#[derive(Debug, Serialize)] +pub struct ErrorResponse { pub error: String, #[serde(rename = "usage")] pub usage: Option } + +impl ErrorResponse { + pub fn new(msg: &str) -> Self { Self { error: msg.to_string(), usage: None } } + pub fn with_usage(mut self, usage: &str) -> Self { self.usage = Some(usage.to_string()); self } +} + +type ApiError = (StatusCode, Json); + +fn err(msg: &str) -> ApiError { (StatusCode::BAD_REQUEST, Json(ErrorResponse::new(msg))) } +fn err_usage(msg: &str, usage: &str) -> ApiError { (StatusCode::BAD_REQUEST, Json(ErrorResponse::new(msg).with_usage(usage))) } + +pub async fn run_cmd(State(state): State, Json(req): Json) -> Result, ApiError> { + let (manager, logger) = state.as_ref(); + let start = Instant::now(); + let mgr = manager.clone(); + let conn_name = req.conn.clone(); + let cmd_str = format!("{} {}", req.command, req.args.join(" ")); + + let result: serde_json::Value = tokio::task::spawn_blocking(move || -> Result { + let (client, _) = mgr.get_conn(&conn_name).map_err(|e| err_usage(&e.to_string(), "Usage: POST /run {\"conn\": \"name\", \"command\": \"GET\", \"args\": [\"key\"]}"))?; + let mut conn = client.get_connection().map_err(|e| err(&e.to_string()))?; + let mut cmd = redis::cmd(&req.command); + for arg in &req.args { cmd.arg(arg); } + let val: redis::Value = cmd.query(&mut conn).map_err(|e| err(&e.to_string()))?; + Ok(redis_value_to_json(&val)) + }).await.map_err(|_| err("Task join error"))??; + + let duration = start.elapsed(); + logger.log(&LogEntry::new("/run", "http").with_conn(&req.conn).with_command(&cmd_str).with_duration(duration.as_millis() as u64)); + Ok(Json(RunResponse { result, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn get(State(state): State, Json(req): Json) -> Result, ApiError> { + let (manager, logger) = state.as_ref(); + let start = Instant::now(); + let mgr = manager.clone(); + let conn_name = req.conn.clone(); + let key_name = req.key.clone(); + + let value: Option = tokio::task::spawn_blocking(move || -> Result, ApiError> { + let (client, _) = mgr.get_conn(&conn_name).map_err(|e| err(&e.to_string()))?; + let mut conn = client.get_connection().map_err(|e| err(&e.to_string()))?; + let val: Option = conn.get(&key_name).map_err(|e| err(&e.to_string()))?; + Ok(val) + }).await.map_err(|_| err("Task join error"))??; + + let duration = start.elapsed(); + logger.log(&LogEntry::new("/get", "http").with_conn(&req.conn).with_command(&format!("GET {}", req.key)).with_duration(duration.as_millis() as u64)); + Ok(Json(GetResponse { value, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn set(State(state): State, Json(req): Json) -> Result, ApiError> { + let (manager, logger) = state.as_ref(); + let start = Instant::now(); + let mgr = manager.clone(); + let conn_name = req.conn.clone(); + let key_name = req.key.clone(); + let value_str = req.value.clone(); + let ttl = req.ttl; + + tokio::task::spawn_blocking(move || -> Result<(), ApiError> { + let (client, _) = mgr.get_conn(&conn_name).map_err(|e| err(&e.to_string()))?; + let mut conn = client.get_connection().map_err(|e| err(&e.to_string()))?; + if let Some(secs) = ttl { + conn.set_ex::<_, _, ()>(&key_name, &value_str, secs as u64).map_err(|e| err(&e.to_string()))?; + } else { + conn.set::<_, _, ()>(&key_name, &value_str).map_err(|e| err(&e.to_string()))?; + } + Ok(()) + }).await.map_err(|_| err("Task join error"))??; + + let duration = start.elapsed(); + logger.log(&LogEntry::new("/set", "http").with_conn(&req.conn).with_command(&format!("SET {} {}", req.key, req.value)).with_duration(duration.as_millis() as u64)); + Ok(Json(SetResponse { ok: true, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn del(State(state): State, Json(req): Json) -> Result, ApiError> { + let (manager, logger) = state.as_ref(); + let start = Instant::now(); + let mgr = manager.clone(); + let conn_name = req.conn.clone(); + let del_keys = req.keys.clone(); + + let deleted: u64 = tokio::task::spawn_blocking(move || -> Result { + let (client, _) = mgr.get_conn(&conn_name).map_err(|e| err(&e.to_string()))?; + let mut conn = client.get_connection().map_err(|e| err(&e.to_string()))?; + let count: u64 = conn.del(&del_keys).map_err(|e| err(&e.to_string()))?; + Ok(count) + }).await.map_err(|_| err("Task join error"))??; + + let duration = start.elapsed(); + logger.log(&LogEntry::new("/del", "http").with_conn(&req.conn).with_command(&format!("DEL {}", req.keys.join(" "))).with_duration(duration.as_millis() as u64)); + Ok(Json(DelResponse { deleted, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn keys(State(state): State, Json(req): Json) -> Result, ApiError> { + let (manager, logger) = state.as_ref(); + let start = Instant::now(); + let mgr = manager.clone(); + let conn_name = req.conn.clone(); + let pattern = req.pattern.clone(); + + let result: Vec = tokio::task::spawn_blocking(move || -> Result, ApiError> { + let (client, _) = mgr.get_conn(&conn_name).map_err(|e| err(&e.to_string()))?; + let mut conn = client.get_connection().map_err(|e| err(&e.to_string()))?; + let keys: Vec = conn.keys(&pattern).map_err(|e| err(&e.to_string()))?; + Ok(keys) + }).await.map_err(|_| err("Task join error"))??; + + let duration = start.elapsed(); + logger.log(&LogEntry::new("/keys", "http").with_conn(&req.conn).with_command(&format!("KEYS {}", req.pattern)).with_duration(duration.as_millis() as u64)); + Ok(Json(KeysResponse { keys: result, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn info(State(state): State, Json(req): Json) -> Result, ApiError> { + let (manager, logger) = state.as_ref(); + let start = Instant::now(); + let mgr = manager.clone(); + let conn_name = req.conn.clone(); + + let info: String = tokio::task::spawn_blocking(move || -> Result { + let (client, _) = mgr.get_conn(&conn_name).map_err(|e| err(&e.to_string()))?; + let mut conn = client.get_connection().map_err(|e| err(&e.to_string()))?; + let info: String = redis::cmd("INFO").query(&mut conn).map_err(|e| err(&e.to_string()))?; + Ok(info) + }).await.map_err(|_| err("Task join error"))??; + + let duration = start.elapsed(); + logger.log(&LogEntry::new("/info", "http").with_conn(&req.conn).with_command("INFO").with_duration(duration.as_millis() as u64)); + Ok(Json(InfoResponse { info, duration_ms: duration.as_millis() as u64 })) +} + +pub async fn connections(State(state): State) -> Json { + Json(ConnectionsResponse { connections: state.0.list_connections() }) +} + +pub async fn health(State(state): State) -> Json { + Json(HealthResponse { status: "ok".to_string(), connections: state.0.list_connections().len() }) +} + +pub async fn add_connection(State(state): State, Json(req): Json) -> Result, ApiError> { + let (manager, logger) = state.as_ref(); + let cfg = crate::config::ConnectionConfig { name: req.name.clone(), host: req.host, port: req.port, password: req.password, db: req.db }; + manager.add_connection(cfg).map_err(|e| err(&e.to_string()))?; + logger.log(&LogEntry::new("/connections/add", "http").with_conn(&req.name).with_duration(0)); + Ok(Json(serde_json::json!({"success": true, "message": format!("Connection '{}' added (temporary)", req.name)}))) +} + +fn redis_value_to_json(val: &redis::Value) -> serde_json::Value { + match val { + redis::Value::Nil => serde_json::Value::Null, + redis::Value::Int(i) => serde_json::json!(*i), + redis::Value::BulkString(bytes) => { + if let Ok(s) = std::str::from_utf8(bytes) { + if (s.starts_with('{') && s.ends_with('}')) || (s.starts_with('[') && s.ends_with(']')) { + serde_json::from_str(s).unwrap_or(serde_json::json!(s)) + } else { + serde_json::json!(s) + } + } else { + serde_json::json!(format!("{:?}", bytes)) + } + } + redis::Value::Array(values) => serde_json::json!(values.iter().map(redis_value_to_json).collect::>()), + redis::Value::SimpleString(s) => serde_json::json!(s), + redis::Value::Okay => serde_json::json!("OK"), + _ => serde_json::json!(format!("{:?}", val)), + } +} diff --git a/redis-proxy/src/logger.rs b/redis-proxy/src/logger.rs new file mode 100644 index 0000000..8d4cc5a --- /dev/null +++ b/redis-proxy/src/logger.rs @@ -0,0 +1,92 @@ +use serde::{Deserialize, Serialize}; +use std::fs::{File, OpenOptions}; +use std::io::Write; +use std::path::PathBuf; +use std::sync::Mutex; + +pub struct RequestLogger { + log_file: Mutex>, + enabled: bool, +} + +impl RequestLogger { + pub fn new(log_path: Option<&str>) -> Self { + let (log_file, enabled) = if let Some(path) = log_path { + let path = expand_path(path); + if let Some(parent) = path.parent() { let _ = std::fs::create_dir_all(parent); } + match OpenOptions::new().create(true).append(true).open(&path) { + Ok(file) => (Some(file), true), + Err(e) => { eprintln!("[Logger] Failed to open log file {}: {}", path.display(), e); (None, false) } + } + } else { (None, false) }; + Self { log_file: Mutex::new(log_file), enabled } + } + + pub fn is_enabled(&self) -> bool { self.enabled } + + pub fn log(&self, entry: &LogEntry) { + if !self.enabled { return; } + let json = match serde_json::to_string(entry) { + Ok(j) => j, + Err(e) => { eprintln!("[Logger] Failed to serialize log: {}", e); return; } + }; + if let Ok(mut file) = self.log_file.lock() { + if let Some(ref mut f) = *file { let _ = writeln!(f, "{}", json); } + } + } +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct LogEntry { + pub timestamp: String, + pub level: String, + #[serde(rename = "type")] + pub log_type: String, + pub client: String, + pub endpoint: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub conn: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub command: Option, + #[serde(rename = "durationMs")] + pub duration_ms: u64, + #[serde(skip_serializing_if = "Option::is_none")] + pub error: Option, +} + +impl LogEntry { + pub fn new(endpoint: &str, client: &str) -> Self { + Self { + timestamp: current_timestamp(), level: "INFO".to_string(), log_type: "request".to_string(), + client: client.to_string(), endpoint: endpoint.to_string(), + conn: None, command: None, duration_ms: 0, error: None, + } + } + pub fn with_conn(mut self, conn: &str) -> Self { self.conn = Some(conn.to_string()); self } + pub fn with_command(mut self, cmd: &str) -> Self { self.command = Some(truncate_string(cmd, 500)); self } + pub fn with_duration(mut self, ms: u64) -> Self { + self.duration_ms = ms; + if ms > 5000 && self.level == "INFO" { self.level = "ERROR".to_string(); } + else if ms > 2000 && self.level == "INFO" { self.level = "WARN".to_string(); } + self + } + pub fn with_error(mut self, error: &str) -> Self { self.level = "ERROR".to_string(); self.error = Some(error.to_string()); self } +} + +fn current_timestamp() -> String { + time::OffsetDateTime::now_utc() + .format(&time::macros::format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]")) + .unwrap_or_default() +} + +fn truncate_string(s: &str, max_len: usize) -> String { + if s.chars().count() <= max_len { s.to_string() } + else { format!("{}... (truncated)", s.chars().take(max_len).collect::()) } +} + +fn expand_path(path: &str) -> PathBuf { + if path.starts_with('~') { + let home = std::env::var("HOME").or_else(|_| std::env::var("USERPROFILE")).unwrap_or_default(); + PathBuf::from(path.replacen('~', &home, 1)) + } else { PathBuf::from(path) } +} diff --git a/redis-proxy/src/main.rs b/redis-proxy/src/main.rs new file mode 100644 index 0000000..927be4c --- /dev/null +++ b/redis-proxy/src/main.rs @@ -0,0 +1,113 @@ +mod cli; +mod config; +mod db; +mod handler; +mod logger; + +use axum::{routing::{get, post}, Router}; +use clap::{Parser, Subcommand}; +use std::sync::Arc; + +#[derive(Parser, Debug)] +#[command(name = "redis-proxy")] +#[command(about = "Redis HTTP proxy with connection pooling")] +struct Args { + #[command(subcommand)] + command: Option, + #[arg(long, default_value = "redis-proxy.toml", global = true)] + config: String, + #[arg(short = 'S', long, default_value = "http://127.0.0.1:3310", global = true)] + server: String, +} + +#[derive(Debug, Subcommand)] +enum Commands { + Server { #[arg(short = 'P', long)] port: Option, #[arg(short = 'H', long)] host: Option }, + Run { #[arg(short, long)] conn: String, #[arg(short = 'C', long)] command: String, #[arg(short = 'a', long)] args: Vec }, + Get { #[arg(short, long)] conn: String, #[arg(short = 'k', long)] key: String }, + Set { #[arg(short, long)] conn: String, #[arg(short = 'k', long)] key: String, #[arg(short, long)] value: String, #[arg(short, long)] ttl: Option }, + Del { #[arg(short, long)] conn: String, #[arg(short = 'k', long)] key: Vec }, + Keys { #[arg(short, long)] conn: String, #[arg(short, long)] pattern: String }, + Connections, +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let args = Args::parse(); + match args.command { + Some(Commands::Server { port, host }) => run_server(&args.config, port, host).await, + Some(Commands::Run { conn, command, args: ref keys }) => { let c = get_cli(&args.server)?; Ok(c.run(&conn, &command, keys)?) }, + Some(Commands::Get { conn, key }) => { let c = get_cli(&args.server)?; Ok(c.get(&conn, &key)?) }, + Some(Commands::Set { conn, key, value, ttl }) => { let c = get_cli(&args.server)?; Ok(c.set(&conn, &key, &value, ttl)?) }, + Some(Commands::Del { conn, key: ref keys }) => { let c = get_cli(&args.server)?; Ok(c.del(&conn, keys)?) }, + Some(Commands::Keys { conn, pattern }) => { let c = get_cli(&args.server)?; Ok(c.keys(&conn, &pattern)?) }, + Some(Commands::Connections) => { let c = get_cli(&args.server)?; Ok(c.list_connections()?) }, + None => run_server(&args.config, None, None).await, + } +} + +fn get_cli(server: &str) -> anyhow::Result { + let c = cli::Cli::new(Some(server.to_string())); + if !c.check_server()? { + eprintln!("\n=== redis-proxy 未运行 ===\n启动代理: redis-proxy\n降级: redis-cli -h -p -a"); + anyhow::bail!("Proxy server not running at {}", server); + } + Ok(c) +} + +async fn run_server(config_path: &str, port: Option, host: Option) -> anyhow::Result<()> { + println!("Redis HTTP Proxy v0.1.0\n"); + let mut config = config::Config::from_file(config_path)?; + if let Some(port) = port { config.server.port = port; } + if let Some(host) = host { config.server.host = host; } + + let log_path = std::env::var("REDIS_PROXY_LOG").ok(); + let logger = Arc::new(logger::RequestLogger::new(log_path.as_deref())); + if logger.is_enabled() { println!("Request logging: enabled"); } + + println!("Initializing connection pools...\n"); + let manager = Arc::new(db::ConnectionManager::new(&config.connections, config.pool.clone())?); + + let manager_clone = manager.clone(); + let check_interval = config.pool.check_interval_secs; + tokio::spawn(async move { + let mut interval = tokio::time::interval(std::time::Duration::from_secs(check_interval)); + loop { interval.tick().await; manager_clone.cleanup_idle(); } + }); + + let app = Router::new() + .route("/run", post(handler::run_cmd)) + .route("/get", post(handler::get)) + .route("/set", post(handler::set)) + .route("/del", post(handler::del)) + .route("/keys", post(handler::keys)) + .route("/info", post(handler::info)) + .route("/connections", get(handler::connections)) + .route("/connections/add", post(handler::add_connection)) + .route("/health", get(handler::health)) + .with_state(Arc::new((manager, logger))); + + let addr = format!("{}:{}", config.server.host, config.server.port); + let listener = tokio::net::TcpListener::bind(&addr).await?; + + println!("\nServer started at http://{}", addr); + println!("\nAPI Endpoints:"); + println!(" POST /run - Execute Redis command"); + println!(" POST /get - GET key"); + println!(" POST /set - SET key value [EX ttl]"); + println!(" POST /del - DEL key1 key2"); + println!(" POST /keys - KEYS pattern"); + println!(" POST /info - INFO"); + println!(" GET /connections - List connections"); + println!(" GET /health - Health check"); + println!("\nCLI Usage:"); + println!(" redis-proxy run -c flux_dev -C GET -a key"); + println!(" redis-proxy get -c flux_dev -k key"); + println!(" redis-proxy set -c flux_dev -k key -v value"); + println!(" redis-proxy del -c flux_dev -k key"); + println!(" redis-proxy keys -c flux_dev -p \"user:*\""); + println!(" redis-proxy connections"); + + axum::serve(listener, app).await?; + Ok(()) +}