commit 586420a476cd813f6b2b04984e761838a22da0df Author: DevITWay Date: Sun Jan 25 17:03:18 2026 +0000 feat: initialize NORA artifact registry Cloud-native multi-protocol artifact registry in Rust. - Docker Registry v2 - Maven (+ proxy) - npm (+ proxy) - Cargo, PyPI - Web UI, Swagger, Prometheus - Local & S3 storage - 32MB Docker image Created by DevITWay https://getnora.io diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0856bc8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +target/ +.git/ +.gitignore +*.md +!README.md +Dockerfile* +docker-compose* +.env* +*.htpasswd +data/ +.internal* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09a497b --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/target +data/ +*.htpasswd +.env +.env.* +*.log +internal config diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..5046997 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,100 @@ +# Contributing to NORA + +Thanks for your interest in contributing to NORA! + +## Getting Started + +1. **Fork** the repository +2. **Clone** your fork: + ```bash + git clone https://github.com/your-username/nora.git + cd nora + ``` +3. **Create a branch**: + ```bash + git checkout -b feature/your-feature-name + ``` + +## Development Setup + +### Prerequisites + +- Rust 1.75+ (`rustup update`) +- Docker (for testing) +- Git + +### Build + +```bash +cargo build +``` + +### Run + +```bash +cargo run --bin nora +``` + +### Test + +```bash +cargo test +cargo clippy +cargo fmt --check +``` + +## Making Changes + +1. **Write code** following Rust conventions +2. **Add tests** for new features +3. **Update docs** if needed +4. **Run checks**: + ```bash + cargo fmt + cargo clippy -- -D warnings + cargo test + ``` + +## Commit Messages + +Follow [Conventional Commits](https://www.conventionalcommits.org/): + +- `feat:` - New feature +- `fix:` - Bug fix +- `docs:` - Documentation +- `test:` - Tests +- `refactor:` - Code refactoring +- `chore:` - Maintenance + +Example: +```bash +git commit -m "feat: add S3 storage migration" +``` + +## Pull Request Process + +1. **Push** to your fork: + ```bash + git push origin feature/your-feature-name + ``` + +2. **Open a Pull Request** on GitHub + +3. **Wait for review** - maintainers will review your PR + +## Code Style + +- Follow Rust conventions +- Use `cargo fmt` for formatting +- Pass `cargo clippy` with no warnings +- Write meaningful commit messages + +## Questions? + +- Open an [Issue](https://github.com/getnora-io/nora/issues) +- Ask in [Discussions](https://github.com/getnora-io/nora/discussions) +- Reach out on [Telegram](https://t.me/DevITWay) + +--- + +Built with love by the NORA community diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c7e8ac5 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,2622 @@ +# 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 = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +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 = "arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" +dependencies = [ + "derive_arbitrary", +] + +[[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.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8" +dependencies = [ + "axum-core", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "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 = "bcrypt" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abaf6da45c74385272ddf00e1ac074c7d8a6c1a1dda376902bd6a427522a8b2c" +dependencies = [ + "base64", + "blowfish", + "getrandom 0.3.4", + "subtle", + "zeroize", +] + +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" + +[[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 = "blowfish" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7" +dependencies = [ + "byteorder", + "cipher", +] + +[[package]] +name = "bumpalo" +version = "3.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" + +[[package]] +name = "cc" +version = "1.2.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6354c81bbfd62d9cfa9cb3c773c2b7b2a3a482d569de977fd0e961f6e7c00583" +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 = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "chrono" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "clap" +version = "4.5.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "unicode-width", + "windows-sys 0.59.0", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[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 = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "derive_arbitrary" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[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 = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + +[[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 = "filetime" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98844151eee8917efc50bd9e8318cb963ae8b297431495d3f758616ea5c57db" +dependencies = [ + "cfg-if", + "libc", + "libredox", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db" + +[[package]] +name = "flate2" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b375d6465b98090a5f25b1c7703f3859783755aa9a80433b36e0379a3ec2f369" +dependencies = [ + "crc32fast", + "miniz_oxide", + "zlib-rs", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[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.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "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", + "wasip2", + "wasm-bindgen", +] + +[[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", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[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", + "serde", + "serde_core", +] + +[[package]] +name = "indicatif" +version = "0.17.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235" +dependencies = [ + "console", + "number_prefix", + "portable-atomic", + "unicode-width", + "web-time", +] + +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + +[[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.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "js-sys" +version = "0.3.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.180" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" + +[[package]] +name = "libredox" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" +dependencies = [ + "bitflags", + "libc", + "redox_syscall 0.7.0", +] + +[[package]] +name = "linux-raw-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" + +[[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 = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[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 = "nora-cli" +version = "0.1.0" +dependencies = [ + "clap", + "flate2", + "indicatif", + "reqwest", + "serde", + "serde_json", + "tar", + "tokio", +] + +[[package]] +name = "nora-registry" +version = "0.1.0" +dependencies = [ + "async-trait", + "axum", + "base64", + "bcrypt", + "chrono", + "clap", + "flate2", + "httpdate", + "indicatif", + "lazy_static", + "prometheus", + "reqwest", + "serde", + "serde_json", + "sha2", + "tar", + "tokio", + "toml", + "tracing", + "tracing-subscriber", + "utoipa", + "utoipa-swagger-ui", + "uuid", +] + +[[package]] +name = "nora-storage" +version = "0.1.0" +dependencies = [ + "axum", + "base64", + "chrono", + "httpdate", + "quick-xml", + "serde", + "serde_json", + "sha2", + "tokio", + "toml", + "tracing", + "tracing-subscriber", + "uuid", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[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 0.5.18", + "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.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[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 = "prometheus" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d33c28a30771f7f96db69893f78b857f7450d7e0237e9c8fc6427a81bae7ed1" +dependencies = [ + "cfg-if", + "fnv", + "lazy_static", + "memchr", + "parking_lot", + "protobuf", + "thiserror 1.0.69", +] + +[[package]] +name = "protobuf" +version = "2.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" + +[[package]] +name = "quick-xml" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 2.0.18", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" +dependencies = [ + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.18", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +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 = "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 = "redox_syscall" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[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 = "rust-embed" +version = "8.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04113cb9355a377d83f06ef1f0a45b8ab8cd7d8b1288160717d66df5c7988d27" +dependencies = [ + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "8.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0902e4c7c8e997159ab384e6d0fc91c221375f6894346ae107f47dd0f3ccaa" +dependencies = [ + "proc-macro2", + "quote", + "rust-embed-utils", + "syn", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "8.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bcdef0be6fe7f6fa333b1073c949729274b05f123a0ad7efcb8efd878e5c3b1" +dependencies = [ + "sha2", + "walkdir", +] + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustix" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" +dependencies = [ + "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 = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +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.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[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 = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[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.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" + +[[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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +dependencies = [ + "libc", + "windows-sys 0.60.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.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +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" +dependencies = [ + "futures-core", +] + +[[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 = "tar" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d863878d212c87a19c1a610eb53bb01fe12951c0501cf5a0d65f724914a667a" +dependencies = [ + "filetime", + "libc", + "xattr", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[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 = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + +[[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.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +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.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +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 = "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-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[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-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "704b1aeb7be0d0a84fc9828cae51dab5970fee5088f83d1dd7ee6f6246fc6ff1" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "serde", + "serde_json", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", + "tracing-serde", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicase" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[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 = "utoipa" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fcc29c80c21c31608227e0912b2d7fddba57ad76b606890627ba8ee7964e993" +dependencies = [ + "indexmap", + "serde", + "serde_json", + "utoipa-gen", +] + +[[package]] +name = "utoipa-gen" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d79d08d92ab8af4c5e8a6da20c47ae3f61a0f1dabc1997cdf2d082b757ca08b" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn", +] + +[[package]] +name = "utoipa-swagger-ui" +version = "9.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d047458f1b5b65237c2f6dc6db136945667f40a7668627b3490b9513a3d43a55" +dependencies = [ + "axum", + "base64", + "mime_guess", + "regex", + "reqwest", + "rust-embed", + "serde", + "serde_json", + "url", + "utoipa", + "zip", +] + +[[package]] +name = "uuid" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee48d38b119b0cd71fe4141b30f5ba9c7c5d9f4e7a3a8b4a674e4b6ef789976f" +dependencies = [ + "getrandom 0.3.4", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[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 = "wasm-bindgen" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f" +dependencies = [ + "cfg-if", + "futures-util", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12bed680863276c63889429bfd6cab3b99943659923822de1c8a39c49e4d722c" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[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 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[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_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[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_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[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_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[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_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[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_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "winnow" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "xattr" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156" +dependencies = [ + "libc", + "rustix", +] + +[[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.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" +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 = "zip" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12598812502ed0105f607f941c386f43d441e00148fce9dec3ca5ffb0bde9308" +dependencies = [ + "arbitrary", + "crc32fast", + "flate2", + "indexmap", + "memchr", + "zopfli", +] + +[[package]] +name = "zlib-rs" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40990edd51aae2c2b6907af74ffb635029d5788228222c4bb811e9351c0caad3" + +[[package]] +name = "zmij" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65" + +[[package]] +name = "zopfli" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249" +dependencies = [ + "bumpalo", + "crc32fast", + "log", + "simd-adler32", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..0dfa6ff --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,26 @@ +[workspace] +resolver = "2" +members = [ + "nora-registry", + "nora-storage", + "nora-cli", +] + +[workspace.package] +version = "0.1.0" +edition = "2021" +license = "MIT" +authors = ["DevITWay "] +repository = "https://github.com/getnora-io/nora" +homepage = "https://getnora.io" + +[workspace.dependencies] +tokio = { version = "1", features = ["full"] } +axum = "0.8" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } +reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] } +sha2 = "0.10" +async-trait = "0.1" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2a4b9c8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +# Build stage +FROM rust:1.83-alpine AS builder + +RUN apk add --no-cache musl-dev curl + +WORKDIR /app + +# Copy manifests +COPY Cargo.toml Cargo.lock ./ +COPY nora-registry/Cargo.toml nora-registry/ +COPY nora-storage/Cargo.toml nora-storage/ +COPY nora-cli/Cargo.toml nora-cli/ + +# Create dummy sources for dependency caching +RUN mkdir -p nora-registry/src nora-storage/src nora-cli/src && \ + echo "fn main() {}" > nora-registry/src/main.rs && \ + echo "fn main() {}" > nora-storage/src/main.rs && \ + echo "fn main() {}" > nora-cli/src/main.rs + +# Build dependencies only +RUN cargo build --release --package nora-registry && \ + rm -rf nora-registry/src nora-storage/src nora-cli/src + +# Copy real sources +COPY nora-registry/src nora-registry/src +COPY nora-storage/src nora-storage/src +COPY nora-cli/src nora-cli/src + +# Build release binary +RUN touch nora-registry/src/main.rs && \ + cargo build --release --package nora-registry + +# Runtime stage +FROM alpine:3.20 + +RUN apk add --no-cache ca-certificates + +WORKDIR /app + +# Copy binary +COPY --from=builder /app/target/release/nora /usr/local/bin/nora + +# Create data directory +RUN mkdir -p /data + +# Default environment +ENV RUST_LOG=info +ENV NORA_HOST=0.0.0.0 +ENV NORA_PORT=4000 +ENV NORA_STORAGE_MODE=local +ENV NORA_STORAGE_PATH=/data/storage +ENV NORA_AUTH_TOKEN_STORAGE=/data/tokens + +EXPOSE 4000 + +VOLUME ["/data"] + +ENTRYPOINT ["nora"] +CMD ["serve"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9811b07 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 DevITWay + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ff7c50b --- /dev/null +++ b/README.md @@ -0,0 +1,169 @@ +# NORA + +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) +[![Telegram](https://img.shields.io/badge/Telegram-DevITWay-blue?logo=telegram)](https://t.me/DevITWay) + +> **Your Cloud-Native Artifact Registry** + +Fast. Organized. Feel at Home. + +**10x faster** than Nexus | **< 100 MB RAM** | **32 MB Docker image** + +## Features + +- **Multi-Protocol Support** + - Docker Registry v2 + - Maven repository (+ proxy to Maven Central) + - npm registry (+ proxy to npmjs.org) + - Cargo registry + - PyPI index + +- **Storage Backends** + - Local filesystem (zero-config default) + - S3-compatible (MinIO, AWS S3) + +- **Production Ready** + - Web UI with search and browse + - Swagger UI API documentation + - Prometheus metrics (`/metrics`) + - Health checks (`/health`, `/ready`) + - JSON structured logging + - Graceful shutdown + +- **Security** + - Basic Auth (htpasswd + bcrypt) + - Revocable API tokens + - ENV-based configuration (12-Factor) + +## Quick Start + +### Docker (Recommended) + +```bash +docker run -d -p 4000:4000 -v nora-data:/data getnora/nora +``` + +### From Source + +```bash +cargo install nora-registry +nora +``` + +Open http://localhost:4000/ui/ + +## Usage + +### Docker Images + +```bash +# Tag and push +docker tag myapp:latest localhost:4000/myapp:latest +docker push localhost:4000/myapp:latest + +# Pull +docker pull localhost:4000/myapp:latest +``` + +### Maven + +```xml + + + nora + http://localhost:4000/maven2/ + +``` + +### npm + +```bash +npm config set registry http://localhost:4000/npm/ +npm publish +``` + +## CLI Commands + +```bash +nora # Start server +nora serve # Start server (explicit) +nora backup -o backup.tar.gz +nora restore -i backup.tar.gz +nora migrate --from local --to s3 +``` + +## Configuration + +### Environment Variables + +| Variable | Default | Description | +|----------|---------|-------------| +| `NORA_HOST` | 127.0.0.1 | Bind address | +| `NORA_PORT` | 4000 | Port | +| `NORA_STORAGE_MODE` | local | `local` or `s3` | +| `NORA_STORAGE_PATH` | data/storage | Local storage path | +| `NORA_STORAGE_S3_URL` | - | S3 endpoint URL | +| `NORA_STORAGE_BUCKET` | registry | S3 bucket name | +| `NORA_AUTH_ENABLED` | false | Enable authentication | + +### config.toml + +```toml +[server] +host = "0.0.0.0" +port = 4000 + +[storage] +mode = "local" +path = "data/storage" + +[auth] +enabled = false +htpasswd_file = "users.htpasswd" +``` + +## Endpoints + +| URL | Description | +|-----|-------------| +| `/ui/` | Web UI | +| `/api-docs` | Swagger UI | +| `/health` | Health check | +| `/ready` | Readiness probe | +| `/metrics` | Prometheus metrics | +| `/v2/` | Docker Registry | +| `/maven2/` | Maven | +| `/npm/` | npm | +| `/cargo/` | Cargo | +| `/simple/` | PyPI | + +## Performance + +| Metric | NORA | Nexus | JFrog | +|--------|------|-------|-------| +| Startup | < 3s | 30-60s | 30-60s | +| Memory | < 100 MB | 2-4 GB | 2-4 GB | +| Image Size | 32 MB | 600+ MB | 1+ GB | + +## Author + +**Created and maintained by [DevITWay](https://github.com/devitway)** + +- Website: [devopsway.ru](https://devopsway.ru) +- Telegram: [@DevITWay](https://t.me/DevITWay) +- GitHub: [@devitway](https://github.com/devitway) +- Email: devitway@gmail.com + +## Contributing + +NORA welcomes contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. + +## License + +MIT License - see [LICENSE](LICENSE) + +Copyright (c) 2026 DevITWay + +--- + +**NORA** - Organized like a chipmunk's stash | Built with Rust by [DevITWay](https://t.me/DevITWay) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..621a703 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +services: + nora: + build: . + image: getnora/nora:latest + ports: + - "4000:4000" + volumes: + - nora-data:/data + environment: + - RUST_LOG=info + - NORA_AUTH_ENABLED=false + restart: unless-stopped + +volumes: + nora-data: diff --git a/nora-cli/Cargo.toml b/nora-cli/Cargo.toml new file mode 100644 index 0000000..8fb0378 --- /dev/null +++ b/nora-cli/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "nora-cli" +version.workspace = true +edition.workspace = true +license.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true +description = "CLI tool for NORA registry" + +[[bin]] +name = "nora-cli" +path = "src/main.rs" + +[dependencies] +tokio.workspace = true +reqwest.workspace = true +serde.workspace = true +serde_json.workspace = true +clap = { version = "4", features = ["derive"] } +indicatif = "0.17" +tar = "0.4" +flate2 = "1.0" diff --git a/nora-cli/src/main.rs b/nora-cli/src/main.rs new file mode 100644 index 0000000..f77a401 --- /dev/null +++ b/nora-cli/src/main.rs @@ -0,0 +1,52 @@ +use clap::{Parser, Subcommand}; + +#[derive(Parser)] +#[command(name = "nora-cli")] +#[command(about = "CLI tool for Nora registry")] +struct Cli { + #[command(subcommand)] + command: Commands, +} + +#[derive(Subcommand)] +enum Commands { + /// Login to a registry + Login { + #[arg(long)] + registry: String, + #[arg(short, long)] + username: String, + }, + /// Push an artifact + Push { + #[arg(long)] + registry: String, + path: String, + }, + /// Pull an artifact + Pull { + #[arg(long)] + registry: String, + artifact: String, + }, +} + +#[tokio::main] +async fn main() { + let cli = Cli::parse(); + + match cli.command { + Commands::Login { registry, username } => { + println!("Logging in to {} as {}", registry, username); + // TODO: implement + } + Commands::Push { registry, path } => { + println!("Pushing {} to {}", path, registry); + // TODO: implement + } + Commands::Pull { registry, artifact } => { + println!("Pulling {} from {}", artifact, registry); + // TODO: implement + } + } +} diff --git a/nora-registry/Cargo.toml b/nora-registry/Cargo.toml new file mode 100644 index 0000000..cbcbdd7 --- /dev/null +++ b/nora-registry/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "nora-registry" +version.workspace = true +edition.workspace = true +license.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true +description = "Cloud-Native Artifact Registry - Fast, lightweight, multi-protocol" +keywords = ["registry", "docker", "artifacts", "cloud-native", "devops"] +categories = ["command-line-utilities", "development-tools", "web-programming"] + +[[bin]] +name = "nora" +path = "src/main.rs" + +[dependencies] +tokio.workspace = true +axum.workspace = true +serde.workspace = true +serde_json.workspace = true +tracing.workspace = true +tracing-subscriber.workspace = true +reqwest.workspace = true +sha2.workspace = true +async-trait.workspace = true +toml = "0.8" +uuid = { version = "1", features = ["v4"] } +bcrypt = "0.17" +base64 = "0.22" +prometheus = "0.13" +lazy_static = "1.5" +httpdate = "1" +utoipa = { version = "5", features = ["axum_extras"] } +utoipa-swagger-ui = { version = "9", features = ["axum", "reqwest"] } +clap = { version = "4", features = ["derive"] } +tar = "0.4" +flate2 = "1.0" +indicatif = "0.17" +chrono = { version = "0.4", features = ["serde"] } diff --git a/nora-registry/src/auth.rs b/nora-registry/src/auth.rs new file mode 100644 index 0000000..74bc0b0 --- /dev/null +++ b/nora-registry/src/auth.rs @@ -0,0 +1,315 @@ +use axum::{ + body::Body, + extract::State, + http::{header, Request, StatusCode}, + middleware::Next, + response::{IntoResponse, Response}, +}; +use base64::{engine::general_purpose::STANDARD, Engine}; +use std::collections::HashMap; +use std::path::Path; +use std::sync::Arc; + +use crate::AppState; + +/// Htpasswd-based authentication +#[derive(Clone)] +pub struct HtpasswdAuth { + users: HashMap, // username -> bcrypt hash +} + +impl HtpasswdAuth { + /// Load users from htpasswd file + pub fn from_file(path: &Path) -> Option { + let content = std::fs::read_to_string(path).ok()?; + let mut users = HashMap::new(); + + for line in content.lines() { + let line = line.trim(); + if line.is_empty() || line.starts_with('#') { + continue; + } + if let Some((username, hash)) = line.split_once(':') { + users.insert(username.to_string(), hash.to_string()); + } + } + + if users.is_empty() { + None + } else { + Some(Self { users }) + } + } + + /// Verify username and password + pub fn authenticate(&self, username: &str, password: &str) -> bool { + if let Some(hash) = self.users.get(username) { + bcrypt::verify(password, hash).unwrap_or(false) + } else { + false + } + } + + /// Get list of usernames + pub fn list_users(&self) -> Vec<&str> { + self.users.keys().map(|s| s.as_str()).collect() + } +} + +/// Check if path is public (no auth required) +fn is_public_path(path: &str) -> bool { + matches!( + path, + "/" | "/health" | "/ready" | "/metrics" | "/v2/" | "/v2" + ) || path.starts_with("/ui") + || path.starts_with("/api-docs") + || path.starts_with("/api/ui") + || path.starts_with("/api/tokens") +} + +/// Auth middleware - supports Basic auth and Bearer tokens +pub async fn auth_middleware( + State(state): State>, + request: Request, + next: Next, +) -> Response { + // Skip auth if disabled + let auth = match &state.auth { + Some(auth) => auth, + None => return next.run(request).await, + }; + + // Skip auth for public endpoints + if is_public_path(request.uri().path()) { + return next.run(request).await; + } + + // Extract Authorization header + let auth_header = request + .headers() + .get(header::AUTHORIZATION) + .and_then(|h| h.to_str().ok()); + + let auth_header = match auth_header { + Some(h) => h, + None => return unauthorized_response("Authentication required"), + }; + + // Try Bearer token first + if let Some(token) = auth_header.strip_prefix("Bearer ") { + if let Some(ref token_store) = state.tokens { + match token_store.verify_token(token) { + Ok(_user) => return next.run(request).await, + Err(_) => return unauthorized_response("Invalid or expired token"), + } + } else { + return unauthorized_response("Token authentication not configured"); + } + } + + // Parse Basic auth + if !auth_header.starts_with("Basic ") { + return unauthorized_response("Basic or Bearer authentication required"); + } + + let encoded = &auth_header[6..]; + let decoded = match STANDARD.decode(encoded) { + Ok(d) => d, + Err(_) => return unauthorized_response("Invalid credentials encoding"), + }; + + let credentials = match String::from_utf8(decoded) { + Ok(c) => c, + Err(_) => return unauthorized_response("Invalid credentials encoding"), + }; + + let (username, password) = match credentials.split_once(':') { + Some((u, p)) => (u, p), + None => return unauthorized_response("Invalid credentials format"), + }; + + // Verify credentials + if !auth.authenticate(username, password) { + return unauthorized_response("Invalid username or password"); + } + + // Auth successful + next.run(request).await +} + +fn unauthorized_response(message: &str) -> Response { + ( + StatusCode::UNAUTHORIZED, + [ + (header::WWW_AUTHENTICATE, "Basic realm=\"Nora\""), + (header::CONTENT_TYPE, "application/json"), + ], + format!(r#"{{"error":"{}"}}"#, message), + ) + .into_response() +} + +/// Generate bcrypt hash for password (for CLI user management) +#[allow(dead_code)] +pub fn hash_password(password: &str) -> Result { + bcrypt::hash(password, bcrypt::DEFAULT_COST) +} + +// Token management API routes +use axum::{routing::post, Json, Router}; +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize)] +pub struct CreateTokenRequest { + pub username: String, + pub password: String, + #[serde(default = "default_ttl")] + pub ttl_days: u64, + pub description: Option, +} + +fn default_ttl() -> u64 { + 30 +} + +#[derive(Serialize)] +pub struct CreateTokenResponse { + pub token: String, + pub expires_in_days: u64, +} + +#[derive(Serialize)] +pub struct TokenListItem { + pub hash_prefix: String, + pub created_at: u64, + pub expires_at: u64, + pub last_used: Option, + pub description: Option, +} + +#[derive(Serialize)] +pub struct TokenListResponse { + pub tokens: Vec, +} + +/// Create a new API token (requires Basic auth) +async fn create_token( + State(state): State>, + Json(req): Json, +) -> Response { + // Verify user credentials first + let auth = match &state.auth { + Some(auth) => auth, + None => return (StatusCode::SERVICE_UNAVAILABLE, "Auth not configured").into_response(), + }; + + if !auth.authenticate(&req.username, &req.password) { + return (StatusCode::UNAUTHORIZED, "Invalid credentials").into_response(); + } + + let token_store = match &state.tokens { + Some(ts) => ts, + None => { + return ( + StatusCode::SERVICE_UNAVAILABLE, + "Token storage not configured", + ) + .into_response() + } + }; + + match token_store.create_token(&req.username, req.ttl_days, req.description) { + Ok(token) => Json(CreateTokenResponse { + token, + expires_in_days: req.ttl_days, + }) + .into_response(), + Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(), + } +} + +/// List tokens for authenticated user +async fn list_tokens( + State(state): State>, + Json(req): Json, +) -> Response { + let auth = match &state.auth { + Some(auth) => auth, + None => return (StatusCode::SERVICE_UNAVAILABLE, "Auth not configured").into_response(), + }; + + if !auth.authenticate(&req.username, &req.password) { + return (StatusCode::UNAUTHORIZED, "Invalid credentials").into_response(); + } + + let token_store = match &state.tokens { + Some(ts) => ts, + None => { + return ( + StatusCode::SERVICE_UNAVAILABLE, + "Token storage not configured", + ) + .into_response() + } + }; + + let tokens: Vec = token_store + .list_tokens(&req.username) + .into_iter() + .map(|t| TokenListItem { + hash_prefix: t.token_hash[..16].to_string(), + created_at: t.created_at, + expires_at: t.expires_at, + last_used: t.last_used, + description: t.description, + }) + .collect(); + + Json(TokenListResponse { tokens }).into_response() +} + +#[derive(Deserialize)] +pub struct RevokeRequest { + pub username: String, + pub password: String, + pub hash_prefix: String, +} + +/// Revoke a token +async fn revoke_token( + State(state): State>, + Json(req): Json, +) -> Response { + let auth = match &state.auth { + Some(auth) => auth, + None => return (StatusCode::SERVICE_UNAVAILABLE, "Auth not configured").into_response(), + }; + + if !auth.authenticate(&req.username, &req.password) { + return (StatusCode::UNAUTHORIZED, "Invalid credentials").into_response(); + } + + let token_store = match &state.tokens { + Some(ts) => ts, + None => { + return ( + StatusCode::SERVICE_UNAVAILABLE, + "Token storage not configured", + ) + .into_response() + } + }; + + match token_store.revoke_token(&req.hash_prefix) { + Ok(()) => (StatusCode::OK, "Token revoked").into_response(), + Err(e) => (StatusCode::NOT_FOUND, e.to_string()).into_response(), + } +} + +/// Token management routes +pub fn token_routes() -> Router> { + Router::new() + .route("/api/tokens", post(create_token)) + .route("/api/tokens/list", post(list_tokens)) + .route("/api/tokens/revoke", post(revoke_token)) +} diff --git a/nora-registry/src/backup.rs b/nora-registry/src/backup.rs new file mode 100644 index 0000000..0ee41d4 --- /dev/null +++ b/nora-registry/src/backup.rs @@ -0,0 +1,299 @@ +//! Backup and restore functionality for Nora +//! +//! Exports all artifacts to a tar.gz file and restores from backups. + +use crate::storage::Storage; +use chrono::{DateTime, Utc}; +use flate2::read::GzDecoder; +use flate2::write::GzEncoder; +use flate2::Compression; +use indicatif::{ProgressBar, ProgressStyle}; +use serde::{Deserialize, Serialize}; +use std::fs::File; +use std::io::Read; +use std::path::Path; +use tar::{Archive, Builder, Header}; + +/// Backup metadata stored in metadata.json +#[derive(Debug, Serialize, Deserialize)] +pub struct BackupMetadata { + pub version: String, + pub created_at: DateTime, + pub artifact_count: usize, + pub total_bytes: u64, + pub storage_backend: String, +} + +/// Statistics returned after backup +#[derive(Debug)] +pub struct BackupStats { + pub artifact_count: usize, + pub total_bytes: u64, + pub output_size: u64, +} + +/// Statistics returned after restore +#[derive(Debug)] +pub struct RestoreStats { + pub artifact_count: usize, + pub total_bytes: u64, +} + +/// Create a backup of all artifacts to a tar.gz file +pub async fn create_backup(storage: &Storage, output: &Path) -> Result { + println!("Creating backup to: {}", output.display()); + println!("Storage backend: {}", storage.backend_name()); + + // List all keys + println!("Scanning storage..."); + let keys = storage.list("").await; + + if keys.is_empty() { + println!("No artifacts found in storage. Creating empty backup."); + } else { + println!("Found {} artifacts", keys.len()); + } + + // Create output file + let file = File::create(output).map_err(|e| format!("Failed to create output file: {}", e))?; + let encoder = GzEncoder::new(file, Compression::default()); + let mut archive = Builder::new(encoder); + + // Progress bar + let pb = ProgressBar::new(keys.len() as u64); + pb.set_style( + ProgressStyle::default_bar() + .template( + "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})", + ) + .expect("Invalid progress template") + .progress_chars("#>-"), + ); + + let mut total_bytes: u64 = 0; + let mut artifact_count = 0; + + for key in &keys { + // Get file data + let data = match storage.get(key).await { + Ok(data) => data, + Err(e) => { + pb.println(format!("Warning: Failed to read {}: {}", key, e)); + continue; + } + }; + + // Create tar header + let mut header = Header::new_gnu(); + header.set_size(data.len() as u64); + header.set_mode(0o644); + header.set_mtime( + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap_or_default() + .as_secs(), + ); + header.set_cksum(); + + // Add to archive + archive + .append_data(&mut header, key, &*data) + .map_err(|e| format!("Failed to add {} to archive: {}", key, e))?; + + total_bytes += data.len() as u64; + artifact_count += 1; + pb.inc(1); + } + + // Add metadata.json + let metadata = BackupMetadata { + version: env!("CARGO_PKG_VERSION").to_string(), + created_at: Utc::now(), + artifact_count, + total_bytes, + storage_backend: storage.backend_name().to_string(), + }; + + let metadata_json = serde_json::to_vec_pretty(&metadata) + .map_err(|e| format!("Failed to serialize metadata: {}", e))?; + + let mut header = Header::new_gnu(); + header.set_size(metadata_json.len() as u64); + header.set_mode(0o644); + header.set_mtime( + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap_or_default() + .as_secs(), + ); + header.set_cksum(); + + archive + .append_data(&mut header, "metadata.json", metadata_json.as_slice()) + .map_err(|e| format!("Failed to add metadata.json: {}", e))?; + + // Finish archive + let encoder = archive + .into_inner() + .map_err(|e| format!("Failed to finish archive: {}", e))?; + encoder + .finish() + .map_err(|e| format!("Failed to finish compression: {}", e))?; + + pb.finish_with_message("Backup complete"); + + // Get output file size + let output_size = std::fs::metadata(output).map(|m| m.len()).unwrap_or(0); + + let stats = BackupStats { + artifact_count, + total_bytes, + output_size, + }; + + println!(); + println!("Backup complete:"); + println!(" Artifacts: {}", stats.artifact_count); + println!(" Total data: {} bytes", stats.total_bytes); + println!(" Backup file: {} bytes", stats.output_size); + println!( + " Compression ratio: {:.1}%", + if stats.total_bytes > 0 { + (stats.output_size as f64 / stats.total_bytes as f64) * 100.0 + } else { + 100.0 + } + ); + + Ok(stats) +} + +/// Restore artifacts from a backup file +pub async fn restore_backup(storage: &Storage, input: &Path) -> Result { + println!("Restoring from: {}", input.display()); + println!("Storage backend: {}", storage.backend_name()); + + // Open backup file + let file = File::open(input).map_err(|e| format!("Failed to open backup file: {}", e))?; + let decoder = GzDecoder::new(file); + let mut archive = Archive::new(decoder); + + // First pass: count entries and read metadata + let file = File::open(input).map_err(|e| format!("Failed to open backup file: {}", e))?; + let decoder = GzDecoder::new(file); + let mut archive_count = Archive::new(decoder); + + let mut entry_count = 0; + let mut metadata: Option = None; + + for entry in archive_count + .entries() + .map_err(|e| format!("Failed to read archive: {}", e))? + { + let mut entry = entry.map_err(|e| format!("Failed to read entry: {}", e))?; + let path = entry + .path() + .map_err(|e| format!("Failed to read path: {}", e))? + .to_string_lossy() + .to_string(); + + if path == "metadata.json" { + let mut data = Vec::new(); + entry + .read_to_end(&mut data) + .map_err(|e| format!("Failed to read metadata: {}", e))?; + metadata = serde_json::from_slice(&data).ok(); + } else { + entry_count += 1; + } + } + + if let Some(ref meta) = metadata { + println!("Backup info:"); + println!(" Version: {}", meta.version); + println!(" Created: {}", meta.created_at); + println!(" Artifacts: {}", meta.artifact_count); + println!(" Original size: {} bytes", meta.total_bytes); + println!(); + } + + // Progress bar + let pb = ProgressBar::new(entry_count as u64); + pb.set_style( + ProgressStyle::default_bar() + .template( + "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})", + ) + .expect("Invalid progress template") + .progress_chars("#>-"), + ); + + let mut total_bytes: u64 = 0; + let mut artifact_count = 0; + + // Second pass: restore files + for entry in archive + .entries() + .map_err(|e| format!("Failed to read archive: {}", e))? + { + let mut entry = entry.map_err(|e| format!("Failed to read entry: {}", e))?; + let path = entry + .path() + .map_err(|e| format!("Failed to read path: {}", e))? + .to_string_lossy() + .to_string(); + + // Skip metadata file + if path == "metadata.json" { + continue; + } + + // Read data + let mut data = Vec::new(); + entry + .read_to_end(&mut data) + .map_err(|e| format!("Failed to read {}: {}", path, e))?; + + // Put to storage + storage + .put(&path, &data) + .await + .map_err(|e| format!("Failed to store {}: {}", path, e))?; + + total_bytes += data.len() as u64; + artifact_count += 1; + pb.inc(1); + } + + pb.finish_with_message("Restore complete"); + + let stats = RestoreStats { + artifact_count, + total_bytes, + }; + + println!(); + println!("Restore complete:"); + println!(" Artifacts: {}", stats.artifact_count); + println!(" Total data: {} bytes", stats.total_bytes); + + Ok(stats) +} + +/// Format bytes for human-readable display +#[allow(dead_code)] +fn format_bytes(bytes: u64) -> String { + const KB: u64 = 1024; + const MB: u64 = KB * 1024; + const GB: u64 = MB * 1024; + + if bytes >= GB { + format!("{:.2} GB", bytes as f64 / GB as f64) + } else if bytes >= MB { + format!("{:.2} MB", bytes as f64 / MB as f64) + } else if bytes >= KB { + format!("{:.2} KB", bytes as f64 / KB as f64) + } else { + format!("{} B", bytes) + } +} diff --git a/nora-registry/src/config.rs b/nora-registry/src/config.rs new file mode 100644 index 0000000..bc54d62 --- /dev/null +++ b/nora-registry/src/config.rs @@ -0,0 +1,218 @@ +use serde::{Deserialize, Serialize}; +use std::env; +use std::fs; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Config { + pub server: ServerConfig, + pub storage: StorageConfig, + #[serde(default)] + pub maven: MavenConfig, + #[serde(default)] + pub npm: NpmConfig, + #[serde(default)] + pub auth: AuthConfig, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServerConfig { + pub host: String, + pub port: u16, +} + +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum StorageMode { + #[default] + Local, + S3, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct StorageConfig { + #[serde(default)] + pub mode: StorageMode, + #[serde(default = "default_storage_path")] + pub path: String, + #[serde(default = "default_s3_url")] + pub s3_url: String, + #[serde(default = "default_bucket")] + pub bucket: String, +} + +fn default_storage_path() -> String { + "data/storage".to_string() +} + +fn default_s3_url() -> String { + "http://127.0.0.1:3000".to_string() +} + +fn default_bucket() -> String { + "registry".to_string() +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct MavenConfig { + #[serde(default)] + pub proxies: Vec, + #[serde(default = "default_timeout")] + pub proxy_timeout: u64, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct NpmConfig { + #[serde(default)] + pub proxy: Option, + #[serde(default = "default_timeout")] + pub proxy_timeout: u64, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AuthConfig { + #[serde(default)] + pub enabled: bool, + #[serde(default = "default_htpasswd_file")] + pub htpasswd_file: String, + #[serde(default = "default_token_storage")] + pub token_storage: String, +} + +fn default_htpasswd_file() -> String { + "users.htpasswd".to_string() +} + +fn default_token_storage() -> String { + "data/tokens".to_string() +} + +fn default_timeout() -> u64 { + 30 +} + +impl Default for MavenConfig { + fn default() -> Self { + Self { + proxies: vec!["https://repo1.maven.org/maven2".to_string()], + proxy_timeout: 30, + } + } +} + +impl Default for NpmConfig { + fn default() -> Self { + Self { + proxy: Some("https://registry.npmjs.org".to_string()), + proxy_timeout: 30, + } + } +} + +impl Default for AuthConfig { + fn default() -> Self { + Self { + enabled: false, + htpasswd_file: "users.htpasswd".to_string(), + token_storage: "data/tokens".to_string(), + } + } +} + +impl Config { + /// Load configuration with priority: ENV > config.toml > defaults + pub fn load() -> Self { + // 1. Start with defaults + // 2. Override with config.toml if exists + let mut config: Config = fs::read_to_string("config.toml") + .ok() + .and_then(|content| toml::from_str(&content).ok()) + .unwrap_or_default(); + + // 3. Override with ENV vars (highest priority) + config.apply_env_overrides(); + config + } + + /// Apply environment variable overrides + fn apply_env_overrides(&mut self) { + // Server config + if let Ok(val) = env::var("NORA_HOST") { + self.server.host = val; + } + if let Ok(val) = env::var("NORA_PORT") { + if let Ok(port) = val.parse() { + self.server.port = port; + } + } + + // Storage config + if let Ok(val) = env::var("NORA_STORAGE_MODE") { + self.storage.mode = match val.to_lowercase().as_str() { + "s3" => StorageMode::S3, + _ => StorageMode::Local, + }; + } + if let Ok(val) = env::var("NORA_STORAGE_PATH") { + self.storage.path = val; + } + if let Ok(val) = env::var("NORA_STORAGE_S3_URL") { + self.storage.s3_url = val; + } + if let Ok(val) = env::var("NORA_STORAGE_BUCKET") { + self.storage.bucket = val; + } + + // Auth config + if let Ok(val) = env::var("NORA_AUTH_ENABLED") { + self.auth.enabled = val.to_lowercase() == "true" || val == "1"; + } + if let Ok(val) = env::var("NORA_AUTH_HTPASSWD_FILE") { + self.auth.htpasswd_file = val; + } + + // Maven config + if let Ok(val) = env::var("NORA_MAVEN_PROXIES") { + self.maven.proxies = val.split(',').map(|s| s.trim().to_string()).collect(); + } + if let Ok(val) = env::var("NORA_MAVEN_PROXY_TIMEOUT") { + if let Ok(timeout) = val.parse() { + self.maven.proxy_timeout = timeout; + } + } + + // npm config + if let Ok(val) = env::var("NORA_NPM_PROXY") { + self.npm.proxy = if val.is_empty() { None } else { Some(val) }; + } + if let Ok(val) = env::var("NORA_NPM_PROXY_TIMEOUT") { + if let Ok(timeout) = val.parse() { + self.npm.proxy_timeout = timeout; + } + } + + // Token storage + if let Ok(val) = env::var("NORA_AUTH_TOKEN_STORAGE") { + self.auth.token_storage = val; + } + } +} + +impl Default for Config { + fn default() -> Self { + Self { + server: ServerConfig { + host: String::from("127.0.0.1"), + port: 4000, + }, + storage: StorageConfig { + mode: StorageMode::Local, + path: String::from("data/storage"), + s3_url: String::from("http://127.0.0.1:3000"), + bucket: String::from("registry"), + }, + maven: MavenConfig::default(), + npm: NpmConfig::default(), + auth: AuthConfig::default(), + } + } +} diff --git a/nora-registry/src/health.rs b/nora-registry/src/health.rs new file mode 100644 index 0000000..4948a53 --- /dev/null +++ b/nora-registry/src/health.rs @@ -0,0 +1,89 @@ +use axum::{extract::State, http::StatusCode, response::Json, routing::get, Router}; +use serde::Serialize; +use std::sync::Arc; + +use crate::AppState; + +#[derive(Serialize)] +pub struct HealthStatus { + pub status: String, + pub version: String, + pub uptime_seconds: u64, + pub storage: StorageHealth, + pub registries: RegistriesHealth, +} + +#[derive(Serialize)] +pub struct StorageHealth { + pub backend: String, + pub reachable: bool, + pub endpoint: String, +} + +#[derive(Serialize)] +pub struct RegistriesHealth { + pub docker: String, + pub maven: String, + pub npm: String, + pub cargo: String, + pub pypi: String, +} + +pub fn routes() -> Router> { + Router::new() + .route("/health", get(health_check)) + .route("/ready", get(readiness_check)) +} + +async fn health_check(State(state): State>) -> (StatusCode, Json) { + let storage_reachable = check_storage_reachable(&state).await; + + let status = if storage_reachable { + "healthy" + } else { + "unhealthy" + }; + + let uptime = state.start_time.elapsed().as_secs(); + + let health = HealthStatus { + status: status.to_string(), + version: env!("CARGO_PKG_VERSION").to_string(), + uptime_seconds: uptime, + storage: StorageHealth { + backend: state.storage.backend_name().to_string(), + reachable: storage_reachable, + endpoint: match state.storage.backend_name() { + "s3" => state.config.storage.s3_url.clone(), + _ => state.config.storage.path.clone(), + }, + }, + registries: RegistriesHealth { + docker: "ok".to_string(), + maven: "ok".to_string(), + npm: "ok".to_string(), + cargo: "ok".to_string(), + pypi: "ok".to_string(), + }, + }; + + let status_code = if storage_reachable { + StatusCode::OK + } else { + StatusCode::SERVICE_UNAVAILABLE + }; + + (status_code, Json(health)) +} + +async fn readiness_check(State(state): State>) -> StatusCode { + if check_storage_reachable(&state).await { + StatusCode::OK + } else { + StatusCode::SERVICE_UNAVAILABLE + } +} + +async fn check_storage_reachable(state: &AppState) -> bool { + state.storage.health_check().await +} diff --git a/nora-registry/src/main.rs b/nora-registry/src/main.rs new file mode 100644 index 0000000..6d617aa --- /dev/null +++ b/nora-registry/src/main.rs @@ -0,0 +1,267 @@ +mod auth; +mod backup; +mod config; +mod health; +mod metrics; +mod openapi; +mod registry; +mod storage; +mod tokens; +mod ui; + +use axum::{middleware, Router}; +use clap::{Parser, Subcommand}; +use std::path::{Path, PathBuf}; +use std::sync::Arc; +use std::time::Instant; +use tokio::signal; +use tracing::{error, info, warn}; +use tracing_subscriber::{fmt, prelude::*, EnvFilter}; + +use auth::HtpasswdAuth; +use config::{Config, StorageMode}; +pub use storage::Storage; +use tokens::TokenStore; + +#[derive(Parser)] +#[command( + name = "nora", + version, + about = "Multi-protocol artifact registry" +)] +struct Cli { + #[command(subcommand)] + command: Option, +} + +#[derive(Subcommand)] +enum Commands { + /// Start the registry server (default) + Serve, + /// Backup all artifacts to a tar.gz file + Backup { + /// Output file path (e.g., backup.tar.gz) + #[arg(short, long)] + output: PathBuf, + }, + /// Restore artifacts from a backup file + Restore { + /// Input backup file path + #[arg(short, long)] + input: PathBuf, + }, + /// Migrate artifacts between storage backends + Migrate { + /// Source storage: local or s3 + #[arg(long)] + from: String, + /// Destination storage: local or s3 + #[arg(long)] + to: String, + /// Dry run - show what would be migrated without copying + #[arg(long, default_value = "false")] + dry_run: bool, + }, +} + +pub struct AppState { + pub storage: Storage, + pub config: Config, + pub start_time: Instant, + pub auth: Option, + pub tokens: Option, +} + +#[tokio::main] +async fn main() { + let cli = Cli::parse(); + + // Initialize logging (JSON for server, plain for CLI commands) + let is_server = matches!(cli.command, None | Some(Commands::Serve)); + init_logging(is_server); + + let config = Config::load(); + + // Initialize storage based on mode + let storage = match config.storage.mode { + StorageMode::Local => { + if is_server { + info!(path = %config.storage.path, "Using local storage"); + } + Storage::new_local(&config.storage.path) + } + StorageMode::S3 => { + if is_server { + info!( + s3_url = %config.storage.s3_url, + bucket = %config.storage.bucket, + "Using S3 storage" + ); + } + Storage::new_s3(&config.storage.s3_url, &config.storage.bucket) + } + }; + + // Dispatch to command + match cli.command { + None | Some(Commands::Serve) => { + run_server(config, storage).await; + } + Some(Commands::Backup { output }) => { + if let Err(e) = backup::create_backup(&storage, &output).await { + error!("Backup failed: {}", e); + std::process::exit(1); + } + } + Some(Commands::Restore { input }) => { + if let Err(e) = backup::restore_backup(&storage, &input).await { + error!("Restore failed: {}", e); + std::process::exit(1); + } + } + Some(Commands::Migrate { from, to, dry_run }) => { + eprintln!("Migration from '{}' to '{}' (dry_run: {})", from, to, dry_run); + eprintln!("TODO: Migration not yet implemented"); + std::process::exit(1); + } + } +} + +fn init_logging(json_format: bool) { + let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); + + if json_format { + tracing_subscriber::registry() + .with(env_filter) + .with(fmt::layer().json().with_target(true)) + .init(); + } else { + tracing_subscriber::registry() + .with(env_filter) + .with(fmt::layer().with_target(false)) + .init(); + } +} + +async fn run_server(config: Config, storage: Storage) { + let start_time = Instant::now(); + + // Load auth if enabled + let auth = if config.auth.enabled { + let path = Path::new(&config.auth.htpasswd_file); + match HtpasswdAuth::from_file(path) { + Some(auth) => { + info!(users = auth.list_users().len(), "Auth enabled"); + Some(auth) + } + None => { + warn!(file = %config.auth.htpasswd_file, "Auth enabled but htpasswd file not found or empty"); + None + } + } + } else { + None + }; + + // Initialize token store if auth is enabled + let tokens = if config.auth.enabled { + let token_path = Path::new(&config.auth.token_storage); + info!(path = %config.auth.token_storage, "Token storage initialized"); + Some(TokenStore::new(token_path)) + } else { + None + }; + + let state = Arc::new(AppState { + storage, + config, + start_time, + auth, + tokens, + }); + + let app = Router::new() + .merge(health::routes()) + .merge(metrics::routes()) + .merge(ui::routes()) + .merge(openapi::routes()) + .merge(auth::token_routes()) + .merge(registry::docker_routes()) + .merge(registry::maven_routes()) + .merge(registry::npm_routes()) + .merge(registry::cargo_routes()) + .merge(registry::pypi_routes()) + .layer(middleware::from_fn(metrics::metrics_middleware)) + .layer(middleware::from_fn_with_state( + state.clone(), + auth::auth_middleware, + )) + .with_state(state.clone()); + + let addr = format!("{}:{}", state.config.server.host, state.config.server.port); + let listener = tokio::net::TcpListener::bind(&addr) + .await + .expect("Failed to bind"); + + info!( + address = %addr, + version = env!("CARGO_PKG_VERSION"), + storage = state.storage.backend_name(), + auth_enabled = state.auth.is_some(), + "Nora started" + ); + + info!( + health = "/health", + ready = "/ready", + metrics = "/metrics", + ui = "/ui/", + api_docs = "/api-docs", + docker = "/v2/", + maven = "/maven2/", + npm = "/npm/", + cargo = "/cargo/", + pypi = "/simple/", + "Available endpoints" + ); + + // Graceful shutdown on SIGTERM/SIGINT + axum::serve(listener, app) + .with_graceful_shutdown(shutdown_signal()) + .await + .expect("Server error"); + + info!( + uptime_seconds = state.start_time.elapsed().as_secs(), + "Nora shutdown complete" + ); +} + +/// Wait for shutdown signal (SIGTERM or SIGINT) +async fn shutdown_signal() { + let ctrl_c = async { + signal::ctrl_c() + .await + .expect("Failed to install Ctrl+C handler"); + }; + + #[cfg(unix)] + let terminate = async { + signal::unix::signal(signal::unix::SignalKind::terminate()) + .expect("Failed to install SIGTERM handler") + .recv() + .await; + }; + + #[cfg(not(unix))] + let terminate = std::future::pending::<()>(); + + tokio::select! { + _ = ctrl_c => { + info!("Received SIGINT, starting graceful shutdown..."); + } + _ = terminate => { + info!("Received SIGTERM, starting graceful shutdown..."); + } + } +} diff --git a/nora-registry/src/metrics.rs b/nora-registry/src/metrics.rs new file mode 100644 index 0000000..8560c94 --- /dev/null +++ b/nora-registry/src/metrics.rs @@ -0,0 +1,147 @@ +use axum::{ + body::Body, + extract::MatchedPath, + http::Request, + middleware::Next, + response::{IntoResponse, Response}, + routing::get, + Router, +}; +use lazy_static::lazy_static; +use prometheus::{ + register_histogram_vec, register_int_counter_vec, Encoder, HistogramVec, IntCounterVec, + TextEncoder, +}; +use std::sync::Arc; +use std::time::Instant; + +use crate::AppState; + +lazy_static! { + /// Total HTTP requests counter + pub static ref HTTP_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!( + "nora_http_requests_total", + "Total number of HTTP requests", + &["registry", "method", "status"] + ).expect("metric can be created"); + + /// HTTP request duration histogram + pub static ref HTTP_REQUEST_DURATION: HistogramVec = register_histogram_vec!( + "nora_http_request_duration_seconds", + "HTTP request latency in seconds", + &["registry", "method"], + vec![0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0] + ).expect("metric can be created"); + + /// Cache requests counter (hit/miss) + pub static ref CACHE_REQUESTS: IntCounterVec = register_int_counter_vec!( + "nora_cache_requests_total", + "Total cache requests", + &["registry", "result"] + ).expect("metric can be created"); + + /// Storage operations counter + pub static ref STORAGE_OPERATIONS: IntCounterVec = register_int_counter_vec!( + "nora_storage_operations_total", + "Total storage operations", + &["operation", "status"] + ).expect("metric can be created"); + + /// Artifacts count by registry + pub static ref ARTIFACTS_TOTAL: IntCounterVec = register_int_counter_vec!( + "nora_artifacts_total", + "Total artifacts stored", + &["registry"] + ).expect("metric can be created"); +} + +/// Routes for metrics endpoint +pub fn routes() -> Router> { + Router::new().route("/metrics", get(metrics_handler)) +} + +/// Handler for /metrics endpoint +async fn metrics_handler() -> impl IntoResponse { + let encoder = TextEncoder::new(); + let metric_families = prometheus::gather(); + let mut buffer = Vec::new(); + + encoder + .encode(&metric_families, &mut buffer) + .unwrap_or_default(); + + ([("content-type", "text/plain; charset=utf-8")], buffer) +} + +/// Middleware to record request metrics +pub async fn metrics_middleware( + matched_path: Option, + request: Request, + next: Next, +) -> Response { + let start = Instant::now(); + let method = request.method().to_string(); + let path = matched_path + .map(|p| p.as_str().to_string()) + .unwrap_or_else(|| request.uri().path().to_string()); + + // Determine registry from path + let registry = detect_registry(&path); + + // Process request + let response = next.run(request).await; + + let duration = start.elapsed().as_secs_f64(); + let status = response.status().as_u16().to_string(); + + // Record metrics + HTTP_REQUESTS_TOTAL + .with_label_values(&[®istry, &method, &status]) + .inc(); + + HTTP_REQUEST_DURATION + .with_label_values(&[®istry, &method]) + .observe(duration); + + response +} + +/// Detect registry type from path +fn detect_registry(path: &str) -> String { + if path.starts_with("/v2") { + "docker".to_string() + } else if path.starts_with("/maven2") { + "maven".to_string() + } else if path.starts_with("/npm") { + "npm".to_string() + } else if path.starts_with("/cargo") { + "cargo".to_string() + } else if path.starts_with("/simple") || path.starts_with("/packages") { + "pypi".to_string() + } else if path.starts_with("/ui") { + "ui".to_string() + } else { + "other".to_string() + } +} + +/// Record cache hit +#[allow(dead_code)] +pub fn record_cache_hit(registry: &str) { + CACHE_REQUESTS.with_label_values(&[registry, "hit"]).inc(); +} + +/// Record cache miss +#[allow(dead_code)] +pub fn record_cache_miss(registry: &str) { + CACHE_REQUESTS.with_label_values(&[registry, "miss"]).inc(); +} + +/// Record storage operation +#[allow(dead_code)] +pub fn record_storage_op(operation: &str, success: bool) { + let status = if success { "success" } else { "error" }; + STORAGE_OPERATIONS + .with_label_values(&[operation, status]) + .inc(); +} diff --git a/nora-registry/src/openapi.rs b/nora-registry/src/openapi.rs new file mode 100644 index 0000000..82c5c48 --- /dev/null +++ b/nora-registry/src/openapi.rs @@ -0,0 +1,382 @@ +//! OpenAPI documentation and Swagger UI +//! +//! Functions in this module are stubs used only for generating OpenAPI documentation. + +#![allow(dead_code)] + +use axum::Router; +use std::sync::Arc; +use utoipa::OpenApi; +use utoipa_swagger_ui::SwaggerUi; + +use crate::AppState; + +#[derive(OpenApi)] +#[openapi( + info( + title = "Nora", + version = "0.1.0", + description = "Multi-protocol package registry supporting Docker, Maven, npm, Cargo, and PyPI", + license(name = "MIT"), + contact(name = "DevITWay", url = "https://github.com/getnora-io/nora") + ), + servers( + (url = "/", description = "Current server") + ), + tags( + (name = "health", description = "Health check endpoints"), + (name = "docker", description = "Docker Registry v2 API"), + (name = "maven", description = "Maven Repository API"), + (name = "npm", description = "npm Registry API"), + (name = "cargo", description = "Cargo Registry API"), + (name = "pypi", description = "PyPI Simple API"), + (name = "auth", description = "Authentication & API Tokens") + ), + paths( + // Health + crate::openapi::health_check, + crate::openapi::readiness_check, + // Docker + crate::openapi::docker_version, + crate::openapi::docker_catalog, + crate::openapi::docker_tags, + crate::openapi::docker_manifest, + crate::openapi::docker_blob, + // Maven + crate::openapi::maven_artifact, + // npm + crate::openapi::npm_package, + // PyPI + crate::openapi::pypi_simple, + crate::openapi::pypi_package, + // Tokens + crate::openapi::create_token, + crate::openapi::list_tokens, + crate::openapi::revoke_token, + ), + components( + schemas( + HealthResponse, + StorageHealth, + RegistriesHealth, + DockerVersion, + DockerCatalog, + DockerTags, + TokenRequest, + TokenResponse, + TokenListResponse, + TokenInfo, + ErrorResponse + ) + ) +)] +pub struct ApiDoc; + +// ============ Schemas ============ + +use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; + +#[derive(Serialize, ToSchema)] +pub struct HealthResponse { + /// Current health status + pub status: String, + /// Application version + pub version: String, + /// Uptime in seconds + pub uptime_seconds: u64, + /// Storage backend health + pub storage: StorageHealth, + /// Registry health status + pub registries: RegistriesHealth, +} + +#[derive(Serialize, ToSchema)] +pub struct StorageHealth { + /// Backend type (local, s3) + pub backend: String, + /// Whether storage is reachable + pub reachable: bool, + /// Storage endpoint/path + pub endpoint: String, +} + +#[derive(Serialize, ToSchema)] +pub struct RegistriesHealth { + pub docker: String, + pub maven: String, + pub npm: String, + pub cargo: String, + pub pypi: String, +} + +#[derive(Serialize, ToSchema)] +pub struct DockerVersion { + /// API version + #[serde(rename = "Docker-Distribution-API-Version")] + pub version: String, +} + +#[derive(Serialize, ToSchema)] +pub struct DockerCatalog { + /// List of repository names + pub repositories: Vec, +} + +#[derive(Serialize, ToSchema)] +pub struct DockerTags { + /// Repository name + pub name: String, + /// List of tags + pub tags: Vec, +} + +#[derive(Deserialize, ToSchema)] +pub struct TokenRequest { + /// Username for authentication + pub username: String, + /// Password for authentication + pub password: String, + /// Token TTL in days (default: 30) + #[serde(default = "default_ttl")] + pub ttl_days: u32, + /// Optional description + pub description: Option, +} + +fn default_ttl() -> u32 { + 30 +} + +#[derive(Serialize, ToSchema)] +pub struct TokenResponse { + /// Generated API token (starts with nra_) + pub token: String, + /// Token expiration in days + pub expires_in_days: u32, +} + +#[derive(Serialize, ToSchema)] +pub struct TokenListResponse { + /// List of tokens + pub tokens: Vec, +} + +#[derive(Serialize, ToSchema)] +pub struct TokenInfo { + /// Token hash prefix (for identification) + pub hash_prefix: String, + /// Creation timestamp + pub created_at: u64, + /// Expiration timestamp + pub expires_at: u64, + /// Last used timestamp + pub last_used: Option, + /// Description + pub description: Option, +} + +#[derive(Serialize, ToSchema)] +pub struct ErrorResponse { + /// Error message + pub error: String, +} + +// ============ Path Operations (documentation only) ============ + +/// Health check endpoint +#[utoipa::path( + get, + path = "/health", + tag = "health", + responses( + (status = 200, description = "Service is healthy", body = HealthResponse), + (status = 503, description = "Service is unhealthy", body = HealthResponse) + ) +)] +pub async fn health_check() {} + +/// Readiness probe +#[utoipa::path( + get, + path = "/ready", + tag = "health", + responses( + (status = 200, description = "Service is ready"), + (status = 503, description = "Service is not ready") + ) +)] +pub async fn readiness_check() {} + +/// Docker Registry version check +#[utoipa::path( + get, + path = "/v2/", + tag = "docker", + responses( + (status = 200, description = "Registry is available", body = DockerVersion), + (status = 401, description = "Authentication required") + ) +)] +pub async fn docker_version() {} + +/// List all repositories +#[utoipa::path( + get, + path = "/v2/_catalog", + tag = "docker", + responses( + (status = 200, description = "Repository list", body = DockerCatalog) + ) +)] +pub async fn docker_catalog() {} + +/// List tags for a repository +#[utoipa::path( + get, + path = "/v2/{name}/tags/list", + tag = "docker", + params( + ("name" = String, Path, description = "Repository name") + ), + responses( + (status = 200, description = "Tag list", body = DockerTags), + (status = 404, description = "Repository not found") + ) +)] +pub async fn docker_tags() {} + +/// Get manifest +#[utoipa::path( + get, + path = "/v2/{name}/manifests/{reference}", + tag = "docker", + params( + ("name" = String, Path, description = "Repository name"), + ("reference" = String, Path, description = "Tag or digest") + ), + responses( + (status = 200, description = "Manifest content"), + (status = 404, description = "Manifest not found") + ) +)] +pub async fn docker_manifest() {} + +/// Get blob +#[utoipa::path( + get, + path = "/v2/{name}/blobs/{digest}", + tag = "docker", + params( + ("name" = String, Path, description = "Repository name"), + ("digest" = String, Path, description = "Blob digest (sha256:...)") + ), + responses( + (status = 200, description = "Blob content"), + (status = 404, description = "Blob not found") + ) +)] +pub async fn docker_blob() {} + +/// Get Maven artifact +#[utoipa::path( + get, + path = "/maven2/{path}", + tag = "maven", + params( + ("path" = String, Path, description = "Artifact path (e.g., org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar)") + ), + responses( + (status = 200, description = "Artifact content"), + (status = 404, description = "Artifact not found, trying upstream proxies") + ) +)] +pub async fn maven_artifact() {} + +/// Get npm package metadata +#[utoipa::path( + get, + path = "/npm/{name}", + tag = "npm", + params( + ("name" = String, Path, description = "Package name") + ), + responses( + (status = 200, description = "Package metadata (JSON)"), + (status = 404, description = "Package not found") + ) +)] +pub async fn npm_package() {} + +/// PyPI Simple index +#[utoipa::path( + get, + path = "/simple/", + tag = "pypi", + responses( + (status = 200, description = "HTML list of packages") + ) +)] +pub async fn pypi_simple() {} + +/// PyPI package page +#[utoipa::path( + get, + path = "/simple/{name}/", + tag = "pypi", + params( + ("name" = String, Path, description = "Package name") + ), + responses( + (status = 200, description = "HTML list of package files"), + (status = 404, description = "Package not found") + ) +)] +pub async fn pypi_package() {} + +/// Create API token +#[utoipa::path( + post, + path = "/api/tokens", + tag = "auth", + request_body = TokenRequest, + responses( + (status = 200, description = "Token created", body = TokenResponse), + (status = 401, description = "Invalid credentials", body = ErrorResponse), + (status = 400, description = "Auth not configured", body = ErrorResponse) + ) +)] +pub async fn create_token() {} + +/// List user's tokens +#[utoipa::path( + post, + path = "/api/tokens/list", + tag = "auth", + request_body = TokenRequest, + responses( + (status = 200, description = "Token list", body = TokenListResponse), + (status = 401, description = "Invalid credentials", body = ErrorResponse) + ) +)] +pub async fn list_tokens() {} + +/// Revoke a token +#[utoipa::path( + post, + path = "/api/tokens/revoke", + tag = "auth", + responses( + (status = 200, description = "Token revoked"), + (status = 401, description = "Invalid credentials", body = ErrorResponse), + (status = 404, description = "Token not found", body = ErrorResponse) + ) +)] +pub async fn revoke_token() {} + +// ============ Routes ============ + +pub fn routes() -> Router> { + Router::new() + .merge(SwaggerUi::new("/api-docs").url("/api-docs/openapi.json", ApiDoc::openapi())) +} diff --git a/nora-registry/src/registry/cargo_registry.rs b/nora-registry/src/registry/cargo_registry.rs new file mode 100644 index 0000000..9b2edf4 --- /dev/null +++ b/nora-registry/src/registry/cargo_registry.rs @@ -0,0 +1,43 @@ +use crate::AppState; +use axum::{ + extract::{Path, State}, + http::StatusCode, + response::{IntoResponse, Response}, + routing::get, + Router, +}; +use std::sync::Arc; + +pub fn routes() -> Router> { + Router::new() + .route("/cargo/api/v1/crates/{crate_name}", get(get_metadata)) + .route( + "/cargo/api/v1/crates/{crate_name}/{version}/download", + get(download), + ) +} + +async fn get_metadata( + State(state): State>, + Path(crate_name): Path, +) -> Response { + let key = format!("cargo/{}/metadata.json", crate_name); + match state.storage.get(&key).await { + Ok(data) => (StatusCode::OK, data).into_response(), + Err(_) => StatusCode::NOT_FOUND.into_response(), + } +} + +async fn download( + State(state): State>, + Path((crate_name, version)): Path<(String, String)>, +) -> Response { + let key = format!( + "cargo/{}/{}/{}-{}.crate", + crate_name, version, crate_name, version + ); + match state.storage.get(&key).await { + Ok(data) => (StatusCode::OK, data).into_response(), + Err(_) => StatusCode::NOT_FOUND.into_response(), + } +} diff --git a/nora-registry/src/registry/docker.rs b/nora-registry/src/registry/docker.rs new file mode 100644 index 0000000..54128fe --- /dev/null +++ b/nora-registry/src/registry/docker.rs @@ -0,0 +1,154 @@ +use crate::AppState; +use axum::{ + body::Bytes, + extract::{Path, State}, + http::{header, StatusCode}, + response::{IntoResponse, Response}, + routing::{get, head, put}, + Json, Router, +}; +use serde_json::{json, Value}; +use std::sync::Arc; + +pub fn routes() -> Router> { + Router::new() + .route("/v2/", get(check)) + .route("/v2/{name}/blobs/{digest}", head(check_blob)) + .route("/v2/{name}/blobs/{digest}", get(download_blob)) + .route( + "/v2/{name}/blobs/uploads/", + axum::routing::post(start_upload), + ) + .route("/v2/{name}/blobs/uploads/{uuid}", put(upload_blob)) + .route("/v2/{name}/manifests/{reference}", get(get_manifest)) + .route("/v2/{name}/manifests/{reference}", put(put_manifest)) + .route("/v2/{name}/tags/list", get(list_tags)) +} + +async fn check() -> (StatusCode, Json) { + (StatusCode::OK, Json(json!({}))) +} + +async fn check_blob( + State(state): State>, + Path((name, digest)): Path<(String, String)>, +) -> Response { + let key = format!("docker/{}/blobs/{}", name, digest); + match state.storage.get(&key).await { + Ok(data) => ( + StatusCode::OK, + [(header::CONTENT_LENGTH, data.len().to_string())], + ) + .into_response(), + Err(_) => StatusCode::NOT_FOUND.into_response(), + } +} + +async fn download_blob( + State(state): State>, + Path((name, digest)): Path<(String, String)>, +) -> Response { + let key = format!("docker/{}/blobs/{}", name, digest); + match state.storage.get(&key).await { + Ok(data) => ( + StatusCode::OK, + [(header::CONTENT_TYPE, "application/octet-stream")], + data, + ) + .into_response(), + Err(_) => StatusCode::NOT_FOUND.into_response(), + } +} + +async fn start_upload(Path(name): Path) -> Response { + let uuid = uuid::Uuid::new_v4().to_string(); + let location = format!("/v2/{}/blobs/uploads/{}", name, uuid); + ( + StatusCode::ACCEPTED, + [ + (header::LOCATION, location.clone()), + ("Docker-Upload-UUID".parse().unwrap(), uuid), + ], + ) + .into_response() +} + +async fn upload_blob( + State(state): State>, + Path((name, _uuid)): Path<(String, String)>, + axum::extract::Query(params): axum::extract::Query>, + body: Bytes, +) -> Response { + let digest = match params.get("digest") { + Some(d) => d, + None => return StatusCode::BAD_REQUEST.into_response(), + }; + let key = format!("docker/{}/blobs/{}", name, digest); + match state.storage.put(&key, &body).await { + Ok(()) => { + let location = format!("/v2/{}/blobs/{}", name, digest); + (StatusCode::CREATED, [(header::LOCATION, location)]).into_response() + } + Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), + } +} + +async fn get_manifest( + State(state): State>, + Path((name, reference)): Path<(String, String)>, +) -> Response { + let key = format!("docker/{}/manifests/{}.json", name, reference); + match state.storage.get(&key).await { + Ok(data) => ( + StatusCode::OK, + [( + header::CONTENT_TYPE, + "application/vnd.docker.distribution.manifest.v2+json", + )], + data, + ) + .into_response(), + Err(_) => StatusCode::NOT_FOUND.into_response(), + } +} + +async fn put_manifest( + State(state): State>, + Path((name, reference)): Path<(String, String)>, + body: Bytes, +) -> Response { + let key = format!("docker/{}/manifests/{}.json", name, reference); + match state.storage.put(&key, &body).await { + Ok(()) => { + use sha2::Digest; + let digest = format!("sha256:{:x}", sha2::Sha256::digest(&body)); + let location = format!("/v2/{}/manifests/{}", name, reference); + ( + StatusCode::CREATED, + [ + (header::LOCATION, location), + ("Docker-Content-Digest".parse().unwrap(), digest), + ], + ) + .into_response() + } + Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), + } +} + +async fn list_tags( + State(state): State>, + Path(name): Path, +) -> (StatusCode, Json) { + let prefix = format!("docker/{}/manifests/", name); + let keys = state.storage.list(&prefix).await; + let tags: Vec = keys + .iter() + .filter_map(|k| { + k.strip_prefix(&prefix) + .and_then(|t| t.strip_suffix(".json")) + .map(String::from) + }) + .collect(); + (StatusCode::OK, Json(json!({"name": name, "tags": tags}))) +} diff --git a/nora-registry/src/registry/maven.rs b/nora-registry/src/registry/maven.rs new file mode 100644 index 0000000..c16d8fb --- /dev/null +++ b/nora-registry/src/registry/maven.rs @@ -0,0 +1,94 @@ +use crate::AppState; +use axum::{ + body::Bytes, + extract::{Path, State}, + http::{header, StatusCode}, + response::{IntoResponse, Response}, + routing::{get, put}, + Router, +}; +use std::sync::Arc; +use std::time::Duration; + +pub fn routes() -> Router> { + Router::new() + .route("/maven2/{*path}", get(download)) + .route("/maven2/{*path}", put(upload)) +} + +async fn download(State(state): State>, Path(path): Path) -> Response { + let key = format!("maven/{}", path); + + // Try local storage first + if let Ok(data) = state.storage.get(&key).await { + return with_content_type(&path, data).into_response(); + } + + // Try proxy servers + for proxy_url in &state.config.maven.proxies { + let url = format!("{}/{}", proxy_url.trim_end_matches('/'), path); + + match fetch_from_proxy(&url, state.config.maven.proxy_timeout).await { + Ok(data) => { + // Cache in local storage (fire and forget) + let storage = state.storage.clone(); + let key_clone = key.clone(); + let data_clone = data.clone(); + tokio::spawn(async move { + let _ = storage.put(&key_clone, &data_clone).await; + }); + + return with_content_type(&path, data.into()).into_response(); + } + Err(_) => continue, + } + } + + StatusCode::NOT_FOUND.into_response() +} + +async fn upload( + State(state): State>, + Path(path): Path, + body: Bytes, +) -> StatusCode { + let key = format!("maven/{}", path); + match state.storage.put(&key, &body).await { + Ok(()) => StatusCode::CREATED, + Err(_) => StatusCode::INTERNAL_SERVER_ERROR, + } +} + +async fn fetch_from_proxy(url: &str, timeout_secs: u64) -> Result, ()> { + let client = reqwest::Client::builder() + .timeout(Duration::from_secs(timeout_secs)) + .build() + .map_err(|_| ())?; + + let response = client.get(url).send().await.map_err(|_| ())?; + + if !response.status().is_success() { + return Err(()); + } + + response.bytes().await.map(|b| b.to_vec()).map_err(|_| ()) +} + +fn with_content_type( + path: &str, + data: Bytes, +) -> (StatusCode, [(header::HeaderName, &'static str); 1], Bytes) { + let content_type = if path.ends_with(".pom") { + "application/xml" + } else if path.ends_with(".jar") { + "application/java-archive" + } else if path.ends_with(".xml") { + "application/xml" + } else if path.ends_with(".sha1") || path.ends_with(".md5") { + "text/plain" + } else { + "application/octet-stream" + }; + + (StatusCode::OK, [(header::CONTENT_TYPE, content_type)], data) +} diff --git a/nora-registry/src/registry/mod.rs b/nora-registry/src/registry/mod.rs new file mode 100644 index 0000000..78584d5 --- /dev/null +++ b/nora-registry/src/registry/mod.rs @@ -0,0 +1,11 @@ +mod cargo_registry; +mod docker; +mod maven; +mod npm; +mod pypi; + +pub use cargo_registry::routes as cargo_routes; +pub use docker::routes as docker_routes; +pub use maven::routes as maven_routes; +pub use npm::routes as npm_routes; +pub use pypi::routes as pypi_routes; diff --git a/nora-registry/src/registry/npm.rs b/nora-registry/src/registry/npm.rs new file mode 100644 index 0000000..af6e72d --- /dev/null +++ b/nora-registry/src/registry/npm.rs @@ -0,0 +1,89 @@ +use crate::AppState; +use axum::{ + body::Bytes, + extract::{Path, State}, + http::{header, StatusCode}, + response::{IntoResponse, Response}, + routing::get, + Router, +}; +use std::sync::Arc; +use std::time::Duration; + +pub fn routes() -> Router> { + Router::new().route("/npm/{*path}", get(handle_request)) +} + +async fn handle_request(State(state): State>, Path(path): Path) -> Response { + // Determine if this is a tarball request or metadata request + let is_tarball = path.contains("/-/"); + + let key = if is_tarball { + let parts: Vec<&str> = path.split("/-/").collect(); + if parts.len() == 2 { + format!("npm/{}/tarballs/{}", parts[0], parts[1]) + } else { + format!("npm/{}", path) + } + } else { + format!("npm/{}/metadata.json", path) + }; + + // Try local storage first + if let Ok(data) = state.storage.get(&key).await { + return with_content_type(is_tarball, data).into_response(); + } + + // Try proxy if configured + if let Some(proxy_url) = &state.config.npm.proxy { + let url = if is_tarball { + // Tarball URL: https://registry.npmjs.org/package/-/package-version.tgz + format!("{}/{}", proxy_url.trim_end_matches('/'), path) + } else { + // Metadata URL: https://registry.npmjs.org/package + format!("{}/{}", proxy_url.trim_end_matches('/'), path) + }; + + if let Ok(data) = fetch_from_proxy(&url, state.config.npm.proxy_timeout).await { + // Cache in local storage (fire and forget) + let storage = state.storage.clone(); + let key_clone = key.clone(); + let data_clone = data.clone(); + tokio::spawn(async move { + let _ = storage.put(&key_clone, &data_clone).await; + }); + + return with_content_type(is_tarball, data.into()).into_response(); + } + } + + StatusCode::NOT_FOUND.into_response() +} + +async fn fetch_from_proxy(url: &str, timeout_secs: u64) -> Result, ()> { + let client = reqwest::Client::builder() + .timeout(Duration::from_secs(timeout_secs)) + .build() + .map_err(|_| ())?; + + let response = client.get(url).send().await.map_err(|_| ())?; + + if !response.status().is_success() { + return Err(()); + } + + response.bytes().await.map(|b| b.to_vec()).map_err(|_| ()) +} + +fn with_content_type( + is_tarball: bool, + data: Bytes, +) -> (StatusCode, [(header::HeaderName, &'static str); 1], Bytes) { + let content_type = if is_tarball { + "application/octet-stream" + } else { + "application/json" + }; + + (StatusCode::OK, [(header::CONTENT_TYPE, content_type)], data) +} diff --git a/nora-registry/src/registry/pypi.rs b/nora-registry/src/registry/pypi.rs new file mode 100644 index 0000000..2d0db15 --- /dev/null +++ b/nora-registry/src/registry/pypi.rs @@ -0,0 +1,35 @@ +use crate::AppState; +use axum::{ + extract::State, + http::StatusCode, + response::{Html, IntoResponse}, + routing::get, + Router, +}; +use std::sync::Arc; + +pub fn routes() -> Router> { + Router::new().route("/simple/", get(list_packages)) +} + +async fn list_packages(State(state): State>) -> impl IntoResponse { + let keys = state.storage.list("pypi/").await; + let mut packages = std::collections::HashSet::new(); + + for key in keys { + if let Some(pkg) = key.strip_prefix("pypi/").and_then(|k| k.split('/').next()) { + packages.insert(pkg.to_string()); + } + } + + let mut html = String::from("

Simple Index

"); + let mut pkg_list: Vec<_> = packages.into_iter().collect(); + pkg_list.sort(); + + for pkg in pkg_list { + html.push_str(&format!("{}
", pkg, pkg)); + } + html.push_str(""); + + (StatusCode::OK, Html(html)) +} diff --git a/nora-registry/src/storage/local.rs b/nora-registry/src/storage/local.rs new file mode 100644 index 0000000..b10f75f --- /dev/null +++ b/nora-registry/src/storage/local.rs @@ -0,0 +1,131 @@ +use async_trait::async_trait; +use axum::body::Bytes; +use std::path::PathBuf; +use tokio::fs; +use tokio::io::AsyncReadExt; + +use super::{FileMeta, Result, StorageBackend, StorageError}; + +/// Local filesystem storage backend (zero-config default) +pub struct LocalStorage { + base_path: PathBuf, +} + +impl LocalStorage { + pub fn new(path: &str) -> Self { + Self { + base_path: PathBuf::from(path), + } + } + + fn key_to_path(&self, key: &str) -> PathBuf { + self.base_path.join(key) + } + + /// Recursively list all files under a directory (sync helper) + fn list_files_sync(dir: &PathBuf, base: &PathBuf, prefix: &str, results: &mut Vec) { + if let Ok(entries) = std::fs::read_dir(dir) { + for entry in entries.flatten() { + let path = entry.path(); + if path.is_file() { + if let Ok(rel_path) = path.strip_prefix(base) { + let key = rel_path.to_string_lossy().replace('\\', "/"); + if key.starts_with(prefix) || prefix.is_empty() { + results.push(key); + } + } + } else if path.is_dir() { + Self::list_files_sync(&path, base, prefix, results); + } + } + } + } +} + +#[async_trait] +impl StorageBackend for LocalStorage { + async fn put(&self, key: &str, data: &[u8]) -> Result<()> { + let path = self.key_to_path(key); + + // Create parent directories + if let Some(parent) = path.parent() { + fs::create_dir_all(parent) + .await + .map_err(|e| StorageError::Io(e.to_string()))?; + } + + // Write file + fs::write(&path, data) + .await + .map_err(|e| StorageError::Io(e.to_string()))?; + + Ok(()) + } + + async fn get(&self, key: &str) -> Result { + let path = self.key_to_path(key); + + if !path.exists() { + return Err(StorageError::NotFound); + } + + let mut file = fs::File::open(&path).await.map_err(|e| { + if e.kind() == std::io::ErrorKind::NotFound { + StorageError::NotFound + } else { + StorageError::Io(e.to_string()) + } + })?; + + let mut buffer = Vec::new(); + file.read_to_end(&mut buffer) + .await + .map_err(|e| StorageError::Io(e.to_string()))?; + + Ok(Bytes::from(buffer)) + } + + async fn list(&self, prefix: &str) -> Vec { + let base = self.base_path.clone(); + let prefix = prefix.to_string(); + + // Use blocking task for filesystem traversal + tokio::task::spawn_blocking(move || { + let mut results = Vec::new(); + if base.exists() { + Self::list_files_sync(&base, &base, &prefix, &mut results); + } + results.sort(); + results + }) + .await + .unwrap_or_default() + } + + async fn stat(&self, key: &str) -> Option { + let path = self.key_to_path(key); + let metadata = fs::metadata(&path).await.ok()?; + let modified = metadata + .modified() + .ok()? + .duration_since(std::time::UNIX_EPOCH) + .ok()? + .as_secs(); + Some(FileMeta { + size: metadata.len(), + modified, + }) + } + + async fn health_check(&self) -> bool { + // For local storage, just check if base directory exists or can be created + if self.base_path.exists() { + return true; + } + fs::create_dir_all(&self.base_path).await.is_ok() + } + + fn backend_name(&self) -> &'static str { + "local" + } +} diff --git a/nora-registry/src/storage/mod.rs b/nora-registry/src/storage/mod.rs new file mode 100644 index 0000000..4497d92 --- /dev/null +++ b/nora-registry/src/storage/mod.rs @@ -0,0 +1,93 @@ +mod local; +mod s3; + +pub use local::LocalStorage; +pub use s3::S3Storage; + +use async_trait::async_trait; +use axum::body::Bytes; +use std::fmt; +use std::sync::Arc; + +/// File metadata +#[derive(Debug, Clone)] +pub struct FileMeta { + pub size: u64, + pub modified: u64, // Unix timestamp +} + +#[derive(Debug)] +pub enum StorageError { + Network(String), + NotFound, + Io(String), +} + +impl fmt::Display for StorageError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Network(msg) => write!(f, "Network error: {}", msg), + Self::NotFound => write!(f, "Object not found"), + Self::Io(msg) => write!(f, "IO error: {}", msg), + } + } +} + +impl std::error::Error for StorageError {} + +pub type Result = std::result::Result; + +/// Storage backend trait +#[async_trait] +pub trait StorageBackend: Send + Sync { + async fn put(&self, key: &str, data: &[u8]) -> Result<()>; + async fn get(&self, key: &str) -> Result; + async fn list(&self, prefix: &str) -> Vec; + async fn stat(&self, key: &str) -> Option; + async fn health_check(&self) -> bool; + fn backend_name(&self) -> &'static str; +} + +/// Storage wrapper for dynamic dispatch +#[derive(Clone)] +pub struct Storage { + inner: Arc, +} + +impl Storage { + pub fn new_local(path: &str) -> Self { + Self { + inner: Arc::new(LocalStorage::new(path)), + } + } + + pub fn new_s3(s3_url: &str, bucket: &str) -> Self { + Self { + inner: Arc::new(S3Storage::new(s3_url, bucket)), + } + } + + pub async fn put(&self, key: &str, data: &[u8]) -> Result<()> { + self.inner.put(key, data).await + } + + pub async fn get(&self, key: &str) -> Result { + self.inner.get(key).await + } + + pub async fn list(&self, prefix: &str) -> Vec { + self.inner.list(prefix).await + } + + pub async fn stat(&self, key: &str) -> Option { + self.inner.stat(key).await + } + + pub async fn health_check(&self) -> bool { + self.inner.health_check().await + } + + pub fn backend_name(&self) -> &'static str { + self.inner.backend_name() + } +} diff --git a/nora-registry/src/storage/s3.rs b/nora-registry/src/storage/s3.rs new file mode 100644 index 0000000..e37d8d9 --- /dev/null +++ b/nora-registry/src/storage/s3.rs @@ -0,0 +1,129 @@ +use async_trait::async_trait; +use axum::body::Bytes; + +use super::{FileMeta, Result, StorageBackend, StorageError}; + +/// S3-compatible storage backend (MinIO, AWS S3) +pub struct S3Storage { + s3_url: String, + bucket: String, + client: reqwest::Client, +} + +impl S3Storage { + pub fn new(s3_url: &str, bucket: &str) -> Self { + Self { + s3_url: s3_url.to_string(), + bucket: bucket.to_string(), + client: reqwest::Client::new(), + } + } + + fn parse_s3_keys(xml: &str, prefix: &str) -> Vec { + xml.split("") + .filter_map(|part| part.split("").next()) + .filter(|key| key.starts_with(prefix)) + .map(String::from) + .collect() + } +} + +#[async_trait] +impl StorageBackend for S3Storage { + async fn put(&self, key: &str, data: &[u8]) -> Result<()> { + let url = format!("{}/{}/{}", self.s3_url, self.bucket, key); + let response = self + .client + .put(&url) + .body(data.to_vec()) + .send() + .await + .map_err(|e| StorageError::Network(e.to_string()))?; + + if response.status().is_success() { + Ok(()) + } else { + Err(StorageError::Network(format!( + "PUT failed: {}", + response.status() + ))) + } + } + + async fn get(&self, key: &str) -> Result { + let url = format!("{}/{}/{}", self.s3_url, self.bucket, key); + let response = self + .client + .get(&url) + .send() + .await + .map_err(|e| StorageError::Network(e.to_string()))?; + + if response.status().is_success() { + response + .bytes() + .await + .map_err(|e| StorageError::Network(e.to_string())) + } else if response.status().as_u16() == 404 { + Err(StorageError::NotFound) + } else { + Err(StorageError::Network(format!( + "GET failed: {}", + response.status() + ))) + } + } + + async fn list(&self, prefix: &str) -> Vec { + let url = format!("{}/{}", self.s3_url, self.bucket); + match self.client.get(&url).send().await { + Ok(response) if response.status().is_success() => { + if let Ok(xml) = response.text().await { + Self::parse_s3_keys(&xml, prefix) + } else { + Vec::new() + } + } + _ => Vec::new(), + } + } + + async fn stat(&self, key: &str) -> Option { + let url = format!("{}/{}/{}", self.s3_url, self.bucket, key); + let response = self.client.head(&url).send().await.ok()?; + if !response.status().is_success() { + return None; + } + let size = response + .headers() + .get("content-length") + .and_then(|v| v.to_str().ok()) + .and_then(|v| v.parse().ok()) + .unwrap_or(0); + // S3 uses Last-Modified header, but for simplicity use current time if unavailable + let modified = response + .headers() + .get("last-modified") + .and_then(|v| v.to_str().ok()) + .and_then(|v| httpdate::parse_http_date(v).ok()) + .map(|t| { + t.duration_since(std::time::UNIX_EPOCH) + .unwrap_or_default() + .as_secs() + }) + .unwrap_or(0); + Some(FileMeta { size, modified }) + } + + async fn health_check(&self) -> bool { + let url = format!("{}/{}", self.s3_url, self.bucket); + match self.client.head(&url).send().await { + Ok(response) => response.status().is_success() || response.status().as_u16() == 404, + Err(_) => false, + } + } + + fn backend_name(&self) -> &'static str { + "s3" + } +} diff --git a/nora-registry/src/tokens.rs b/nora-registry/src/tokens.rs new file mode 100644 index 0000000..81db839 --- /dev/null +++ b/nora-registry/src/tokens.rs @@ -0,0 +1,202 @@ +use serde::{Deserialize, Serialize}; +use sha2::{Digest, Sha256}; +use std::fs; +use std::path::{Path, PathBuf}; +use std::time::{SystemTime, UNIX_EPOCH}; +use uuid::Uuid; + +const TOKEN_PREFIX: &str = "nra_"; + +/// API Token metadata stored on disk +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TokenInfo { + pub token_hash: String, + pub user: String, + pub created_at: u64, + pub expires_at: u64, + pub last_used: Option, + pub description: Option, +} + +/// Token store for managing API tokens +#[derive(Clone)] +pub struct TokenStore { + storage_path: PathBuf, +} + +impl TokenStore { + /// Create a new token store + pub fn new(storage_path: &Path) -> Self { + // Ensure directory exists + let _ = fs::create_dir_all(storage_path); + Self { + storage_path: storage_path.to_path_buf(), + } + } + + /// Generate a new API token for a user + pub fn create_token( + &self, + user: &str, + ttl_days: u64, + description: Option, + ) -> Result { + // Generate random token + let raw_token = format!( + "{}{}", + TOKEN_PREFIX, + Uuid::new_v4().to_string().replace("-", "") + ); + let token_hash = hash_token(&raw_token); + + let now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_secs(); + + let expires_at = now + (ttl_days * 24 * 60 * 60); + + let info = TokenInfo { + token_hash: token_hash.clone(), + user: user.to_string(), + created_at: now, + expires_at, + last_used: None, + description, + }; + + // Save to file + let file_path = self + .storage_path + .join(format!("{}.json", &token_hash[..16])); + let json = + serde_json::to_string_pretty(&info).map_err(|e| TokenError::Storage(e.to_string()))?; + fs::write(&file_path, json).map_err(|e| TokenError::Storage(e.to_string()))?; + + Ok(raw_token) + } + + /// Verify a token and return user info if valid + pub fn verify_token(&self, token: &str) -> Result { + if !token.starts_with(TOKEN_PREFIX) { + return Err(TokenError::InvalidFormat); + } + + let token_hash = hash_token(token); + let file_path = self + .storage_path + .join(format!("{}.json", &token_hash[..16])); + + if !file_path.exists() { + return Err(TokenError::NotFound); + } + + let content = + fs::read_to_string(&file_path).map_err(|e| TokenError::Storage(e.to_string()))?; + let mut info: TokenInfo = + serde_json::from_str(&content).map_err(|e| TokenError::Storage(e.to_string()))?; + + // Verify hash matches + if info.token_hash != token_hash { + return Err(TokenError::NotFound); + } + + // Check expiration + let now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_secs(); + + if now > info.expires_at { + return Err(TokenError::Expired); + } + + // Update last_used + info.last_used = Some(now); + if let Ok(json) = serde_json::to_string_pretty(&info) { + let _ = fs::write(&file_path, json); + } + + Ok(info.user) + } + + /// List all tokens for a user + pub fn list_tokens(&self, user: &str) -> Vec { + let mut tokens = Vec::new(); + + if let Ok(entries) = fs::read_dir(&self.storage_path) { + for entry in entries.flatten() { + if let Ok(content) = fs::read_to_string(entry.path()) { + if let Ok(info) = serde_json::from_str::(&content) { + if info.user == user { + tokens.push(info); + } + } + } + } + } + + tokens.sort_by(|a, b| b.created_at.cmp(&a.created_at)); + tokens + } + + /// Revoke a token by its hash prefix + pub fn revoke_token(&self, hash_prefix: &str) -> Result<(), TokenError> { + let file_path = self.storage_path.join(format!("{}.json", hash_prefix)); + + if !file_path.exists() { + return Err(TokenError::NotFound); + } + + fs::remove_file(&file_path).map_err(|e| TokenError::Storage(e.to_string()))?; + + Ok(()) + } + + /// Revoke all tokens for a user + pub fn revoke_all_for_user(&self, user: &str) -> usize { + let mut count = 0; + + if let Ok(entries) = fs::read_dir(&self.storage_path) { + for entry in entries.flatten() { + if let Ok(content) = fs::read_to_string(entry.path()) { + if let Ok(info) = serde_json::from_str::(&content) { + if info.user == user && fs::remove_file(entry.path()).is_ok() { + count += 1; + } + } + } + } + } + + count + } +} + +/// Hash a token using SHA256 +fn hash_token(token: &str) -> String { + let mut hasher = Sha256::new(); + hasher.update(token.as_bytes()); + format!("{:x}", hasher.finalize()) +} + +#[derive(Debug)] +pub enum TokenError { + InvalidFormat, + NotFound, + Expired, + Storage(String), +} + +impl std::fmt::Display for TokenError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::InvalidFormat => write!(f, "Invalid token format"), + Self::NotFound => write!(f, "Token not found"), + Self::Expired => write!(f, "Token expired"), + Self::Storage(msg) => write!(f, "Storage error: {}", msg), + } + } +} + +impl std::error::Error for TokenError {} diff --git a/nora-registry/src/ui/api.rs b/nora-registry/src/ui/api.rs new file mode 100644 index 0000000..32b4fb7 --- /dev/null +++ b/nora-registry/src/ui/api.rs @@ -0,0 +1,580 @@ +use super::components::{format_size, format_timestamp, html_escape}; +use super::templates::encode_uri_component; +use crate::AppState; +use crate::Storage; +use axum::{ + extract::{Path, Query, State}, + response::Json, +}; +use serde::{Deserialize, Serialize}; +use std::collections::{HashMap, HashSet}; +use std::sync::Arc; + +#[derive(Serialize)] +pub struct RegistryStats { + pub docker: usize, + pub maven: usize, + pub npm: usize, + pub cargo: usize, + pub pypi: usize, +} + +#[derive(Serialize, Clone)] +pub struct RepoInfo { + pub name: String, + pub versions: usize, + pub size: u64, + pub updated: String, +} + +#[derive(Serialize)] +pub struct TagInfo { + pub name: String, + pub size: u64, + pub created: String, +} + +#[derive(Serialize)] +pub struct DockerDetail { + pub tags: Vec, +} + +#[derive(Serialize)] +pub struct VersionInfo { + pub version: String, + pub size: u64, + pub published: String, +} + +#[derive(Serialize)] +pub struct PackageDetail { + pub versions: Vec, +} + +#[derive(Serialize)] +pub struct MavenArtifact { + pub filename: String, + pub size: u64, +} + +#[derive(Serialize)] +pub struct MavenDetail { + pub artifacts: Vec, +} + +#[derive(Deserialize)] +pub struct SearchQuery { + pub q: Option, +} + +// ============ API Handlers ============ + +pub async fn api_stats(State(state): State>) -> Json { + let stats = get_registry_stats(&state.storage).await; + Json(stats) +} + +pub async fn api_list( + State(state): State>, + Path(registry_type): Path, +) -> Json> { + let repos = match registry_type.as_str() { + "docker" => get_docker_repos(&state.storage).await, + "maven" => get_maven_repos(&state.storage).await, + "npm" => get_npm_packages(&state.storage).await, + "cargo" => get_cargo_crates(&state.storage).await, + "pypi" => get_pypi_packages(&state.storage).await, + _ => vec![], + }; + Json(repos) +} + +pub async fn api_detail( + State(state): State>, + Path((registry_type, name)): Path<(String, String)>, +) -> Json { + match registry_type.as_str() { + "docker" => { + let detail = get_docker_detail(&state.storage, &name).await; + Json(serde_json::to_value(detail).unwrap_or_default()) + } + "npm" => { + let detail = get_npm_detail(&state.storage, &name).await; + Json(serde_json::to_value(detail).unwrap_or_default()) + } + "cargo" => { + let detail = get_cargo_detail(&state.storage, &name).await; + Json(serde_json::to_value(detail).unwrap_or_default()) + } + _ => Json(serde_json::json!({})), + } +} + +pub async fn api_search( + State(state): State>, + Path(registry_type): Path, + Query(params): Query, +) -> axum::response::Html { + let query = params.q.unwrap_or_default().to_lowercase(); + + let repos = match registry_type.as_str() { + "docker" => get_docker_repos(&state.storage).await, + "maven" => get_maven_repos(&state.storage).await, + "npm" => get_npm_packages(&state.storage).await, + "cargo" => get_cargo_crates(&state.storage).await, + "pypi" => get_pypi_packages(&state.storage).await, + _ => vec![], + }; + + let filtered: Vec<_> = if query.is_empty() { + repos + } else { + repos + .into_iter() + .filter(|r| r.name.to_lowercase().contains(&query)) + .collect() + }; + + // Return HTML fragment for HTMX + let html = if filtered.is_empty() { + r#" +
🔍
+
No matching repositories found
+ "# + .to_string() + } else { + filtered + .iter() + .map(|repo| { + let detail_url = + format!("/ui/{}/{}", registry_type, encode_uri_component(&repo.name)); + format!( + r#" + + + {} + + {} + {} + {} + + "#, + detail_url, + detail_url, + html_escape(&repo.name), + repo.versions, + format_size(repo.size), + &repo.updated + ) + }) + .collect::>() + .join("") + }; + + axum::response::Html(html) +} + +// ============ Data Fetching Functions ============ + +pub async fn get_registry_stats(storage: &Storage) -> RegistryStats { + let all_keys = storage.list("").await; + + let docker = all_keys + .iter() + .filter(|k| k.starts_with("docker/") && k.contains("/manifests/")) + .filter_map(|k| k.split('/').nth(1)) + .collect::>() + .len(); + + let maven = all_keys + .iter() + .filter(|k| k.starts_with("maven/")) + .filter_map(|k| { + // Extract groupId/artifactId from maven path + let parts: Vec<_> = k.strip_prefix("maven/")?.split('/').collect(); + if parts.len() >= 2 { + Some(parts[..parts.len() - 1].join("/")) + } else { + None + } + }) + .collect::>() + .len(); + + let npm = all_keys + .iter() + .filter(|k| k.starts_with("npm/") && k.ends_with("/metadata.json")) + .count(); + + let cargo = all_keys + .iter() + .filter(|k| k.starts_with("cargo/") && k.ends_with("/metadata.json")) + .count(); + + let pypi = all_keys + .iter() + .filter(|k| k.starts_with("pypi/")) + .filter_map(|k| k.strip_prefix("pypi/")?.split('/').next()) + .collect::>() + .len(); + + RegistryStats { + docker, + maven, + npm, + cargo, + pypi, + } +} + +pub async fn get_docker_repos(storage: &Storage) -> Vec { + let keys = storage.list("docker/").await; + + let mut repos: HashMap = HashMap::new(); // (info, latest_modified) + + for key in &keys { + if let Some(rest) = key.strip_prefix("docker/") { + let parts: Vec<_> = rest.split('/').collect(); + if parts.len() >= 3 { + let name = parts[0].to_string(); + let entry = repos.entry(name.clone()).or_insert_with(|| { + ( + RepoInfo { + name, + versions: 0, + size: 0, + updated: "N/A".to_string(), + }, + 0, + ) + }); + + if parts[1] == "manifests" { + entry.0.versions += 1; + if let Some(meta) = storage.stat(key).await { + entry.0.size += meta.size; + if meta.modified > entry.1 { + entry.1 = meta.modified; + entry.0.updated = format_timestamp(meta.modified); + } + } + } + } + } + } + + let mut result: Vec<_> = repos.into_values().map(|(r, _)| r).collect(); + result.sort_by(|a, b| a.name.cmp(&b.name)); + result +} + +pub async fn get_docker_detail(storage: &Storage, name: &str) -> DockerDetail { + let prefix = format!("docker/{}/manifests/", name); + let keys = storage.list(&prefix).await; + + let mut tags = Vec::new(); + for key in &keys { + if let Some(tag_name) = key + .strip_prefix(&prefix) + .and_then(|s| s.strip_suffix(".json")) + { + let (size, created) = if let Some(meta) = storage.stat(key).await { + (meta.size, format_timestamp(meta.modified)) + } else { + (0, "N/A".to_string()) + }; + tags.push(TagInfo { + name: tag_name.to_string(), + size, + created, + }); + } + } + + DockerDetail { tags } +} + +pub async fn get_maven_repos(storage: &Storage) -> Vec { + let keys = storage.list("maven/").await; + + let mut repos: HashMap = HashMap::new(); + + for key in &keys { + if let Some(rest) = key.strip_prefix("maven/") { + let parts: Vec<_> = rest.split('/').collect(); + if parts.len() >= 2 { + let artifact_path = parts[..parts.len() - 1].join("/"); + let entry = repos.entry(artifact_path.clone()).or_insert_with(|| { + ( + RepoInfo { + name: artifact_path, + versions: 0, + size: 0, + updated: "N/A".to_string(), + }, + 0, + ) + }); + entry.0.versions += 1; + if let Some(meta) = storage.stat(key).await { + entry.0.size += meta.size; + if meta.modified > entry.1 { + entry.1 = meta.modified; + entry.0.updated = format_timestamp(meta.modified); + } + } + } + } + } + + let mut result: Vec<_> = repos.into_values().map(|(r, _)| r).collect(); + result.sort_by(|a, b| a.name.cmp(&b.name)); + result +} + +pub async fn get_maven_detail(storage: &Storage, path: &str) -> MavenDetail { + let prefix = format!("maven/{}/", path); + let keys = storage.list(&prefix).await; + + let mut artifacts = Vec::new(); + for key in &keys { + if let Some(filename) = key.strip_prefix(&prefix) { + if filename.contains('/') { + continue; + } + let size = storage.stat(key).await.map(|m| m.size).unwrap_or(0); + artifacts.push(MavenArtifact { + filename: filename.to_string(), + size, + }); + } + } + + MavenDetail { artifacts } +} + +pub async fn get_npm_packages(storage: &Storage) -> Vec { + let keys = storage.list("npm/").await; + + let mut packages: HashMap = HashMap::new(); + + for key in &keys { + if let Some(rest) = key.strip_prefix("npm/") { + let parts: Vec<_> = rest.split('/').collect(); + if !parts.is_empty() { + let name = parts[0].to_string(); + let entry = packages.entry(name.clone()).or_insert_with(|| { + ( + RepoInfo { + name, + versions: 0, + size: 0, + updated: "N/A".to_string(), + }, + 0, + ) + }); + + if parts.len() >= 3 && parts[1] == "tarballs" { + entry.0.versions += 1; + if let Some(meta) = storage.stat(key).await { + entry.0.size += meta.size; + if meta.modified > entry.1 { + entry.1 = meta.modified; + entry.0.updated = format_timestamp(meta.modified); + } + } + } + } + } + } + + let mut result: Vec<_> = packages.into_values().map(|(r, _)| r).collect(); + result.sort_by(|a, b| a.name.cmp(&b.name)); + result +} + +pub async fn get_npm_detail(storage: &Storage, name: &str) -> PackageDetail { + let prefix = format!("npm/{}/tarballs/", name); + let keys = storage.list(&prefix).await; + + let mut versions = Vec::new(); + for key in &keys { + if let Some(tarball) = key.strip_prefix(&prefix) { + if let Some(version) = tarball + .strip_prefix(&format!("{}-", name)) + .and_then(|s| s.strip_suffix(".tgz")) + { + let (size, published) = if let Some(meta) = storage.stat(key).await { + (meta.size, format_timestamp(meta.modified)) + } else { + (0, "N/A".to_string()) + }; + versions.push(VersionInfo { + version: version.to_string(), + size, + published, + }); + } + } + } + + PackageDetail { versions } +} + +pub async fn get_cargo_crates(storage: &Storage) -> Vec { + let keys = storage.list("cargo/").await; + + let mut crates: HashMap = HashMap::new(); + + for key in &keys { + if let Some(rest) = key.strip_prefix("cargo/") { + let parts: Vec<_> = rest.split('/').collect(); + if !parts.is_empty() { + let name = parts[0].to_string(); + let entry = crates.entry(name.clone()).or_insert_with(|| { + ( + RepoInfo { + name, + versions: 0, + size: 0, + updated: "N/A".to_string(), + }, + 0, + ) + }); + + if parts.len() >= 3 && key.ends_with(".crate") { + entry.0.versions += 1; + if let Some(meta) = storage.stat(key).await { + entry.0.size += meta.size; + if meta.modified > entry.1 { + entry.1 = meta.modified; + entry.0.updated = format_timestamp(meta.modified); + } + } + } + } + } + } + + let mut result: Vec<_> = crates.into_values().map(|(r, _)| r).collect(); + result.sort_by(|a, b| a.name.cmp(&b.name)); + result +} + +pub async fn get_cargo_detail(storage: &Storage, name: &str) -> PackageDetail { + let prefix = format!("cargo/{}/", name); + let keys = storage.list(&prefix).await; + + let mut versions = Vec::new(); + for key in keys.iter().filter(|k| k.ends_with(".crate")) { + if let Some(rest) = key.strip_prefix(&prefix) { + let parts: Vec<_> = rest.split('/').collect(); + if !parts.is_empty() { + let (size, published) = if let Some(meta) = storage.stat(key).await { + (meta.size, format_timestamp(meta.modified)) + } else { + (0, "N/A".to_string()) + }; + versions.push(VersionInfo { + version: parts[0].to_string(), + size, + published, + }); + } + } + } + + PackageDetail { versions } +} + +pub async fn get_pypi_packages(storage: &Storage) -> Vec { + let keys = storage.list("pypi/").await; + + let mut packages: HashMap = HashMap::new(); + + for key in &keys { + if let Some(rest) = key.strip_prefix("pypi/") { + let parts: Vec<_> = rest.split('/').collect(); + if !parts.is_empty() { + let name = parts[0].to_string(); + let entry = packages.entry(name.clone()).or_insert_with(|| { + ( + RepoInfo { + name, + versions: 0, + size: 0, + updated: "N/A".to_string(), + }, + 0, + ) + }); + + if parts.len() >= 2 { + entry.0.versions += 1; + if let Some(meta) = storage.stat(key).await { + entry.0.size += meta.size; + if meta.modified > entry.1 { + entry.1 = meta.modified; + entry.0.updated = format_timestamp(meta.modified); + } + } + } + } + } + } + + let mut result: Vec<_> = packages.into_values().map(|(r, _)| r).collect(); + result.sort_by(|a, b| a.name.cmp(&b.name)); + result +} + +pub async fn get_pypi_detail(storage: &Storage, name: &str) -> PackageDetail { + let prefix = format!("pypi/{}/", name); + let keys = storage.list(&prefix).await; + + let mut versions = Vec::new(); + for key in &keys { + if let Some(filename) = key.strip_prefix(&prefix) { + if let Some(version) = extract_pypi_version(name, filename) { + let (size, published) = if let Some(meta) = storage.stat(key).await { + (meta.size, format_timestamp(meta.modified)) + } else { + (0, "N/A".to_string()) + }; + versions.push(VersionInfo { + version, + size, + published, + }); + } + } + } + + PackageDetail { versions } +} + +fn extract_pypi_version(name: &str, filename: &str) -> Option { + // Handle both .tar.gz and .whl files + let clean_name = name.replace('-', "_"); + + if filename.ends_with(".tar.gz") { + // package-1.0.0.tar.gz + let base = filename.strip_suffix(".tar.gz")?; + let version = base + .strip_prefix(&format!("{}-", name)) + .or_else(|| base.strip_prefix(&format!("{}-", clean_name)))?; + Some(version.to_string()) + } else if filename.ends_with(".whl") { + // package-1.0.0-py3-none-any.whl + let parts: Vec<_> = filename.split('-').collect(); + if parts.len() >= 2 { + Some(parts[1].to_string()) + } else { + None + } + } else { + None + } +} diff --git a/nora-registry/src/ui/components.rs b/nora-registry/src/ui/components.rs new file mode 100644 index 0000000..75f98f9 --- /dev/null +++ b/nora-registry/src/ui/components.rs @@ -0,0 +1,222 @@ +/// Main layout wrapper with header and sidebar +pub fn layout(title: &str, content: &str, active_page: Option<&str>) -> String { + format!( + r##" + + + + + {} - Nora + + + + + +
+ + {} + + +
+ + {} + + +
+ {} +
+
+
+ +"##, + html_escape(title), + sidebar(active_page), + header(), + content + ) +} + +/// Sidebar navigation component +fn sidebar(active_page: Option<&str>) -> String { + let active = active_page.unwrap_or(""); + + let nav_items = [ + ( + "dashboard", + "/ui/", + "Dashboard", + r#""#, + ), + ("docker", "/ui/docker", "🐳 Docker", ""), + ("maven", "/ui/maven", "☕ Maven", ""), + ("npm", "/ui/npm", "📦 npm", ""), + ("cargo", "/ui/cargo", "🦀 Cargo", ""), + ("pypi", "/ui/pypi", "🐍 PyPI", ""), + ]; + + let nav_html: String = nav_items.iter().map(|(id, href, label, icon_path)| { + let is_active = active == *id; + let active_class = if is_active { + "bg-slate-700 text-white" + } else { + "text-slate-300 hover:bg-slate-700 hover:text-white" + }; + + if icon_path.is_empty() { + // Emoji-based item + format!(r#" + + {} + + "#, href, active_class, label) + } else { + // SVG icon item + format!(r##" + + + {} + + {} + + "##, href, active_class, icon_path, label) + } + }).collect(); + + format!( + r#" +
+ +
+ + Nora +
+ + + + + +
+
+ Nora v0.1.0 +
+
+
+ "#, + nav_html + ) +} + +/// Header component +fn header() -> String { + r##" +
+
+ +
+
+ + + + + + +
+
+ "##.to_string() +} + +/// Stat card for dashboard +pub fn stat_card(name: &str, icon: &str, count: usize, href: &str, unit: &str) -> String { + format!( + r##" + +
+ {} + ACTIVE +
+
{}
+
{}
+
{}
+
+ "##, + href, icon, name, count, unit + ) +} + +/// Format file size in human-readable format +pub fn format_size(bytes: u64) -> String { + const KB: u64 = 1024; + const MB: u64 = KB * 1024; + const GB: u64 = MB * 1024; + + if bytes >= GB { + format!("{:.1} GB", bytes as f64 / GB as f64) + } else if bytes >= MB { + format!("{:.1} MB", bytes as f64 / MB as f64) + } else if bytes >= KB { + format!("{:.1} KB", bytes as f64 / KB as f64) + } else { + format!("{} B", bytes) + } +} + +/// Escape HTML special characters +pub fn html_escape(s: &str) -> String { + s.replace('&', "&") + .replace('<', "<") + .replace('>', ">") + .replace('"', """) + .replace('\'', "'") +} + +/// Format Unix timestamp as relative time +pub fn format_timestamp(ts: u64) -> String { + if ts == 0 { + return "N/A".to_string(); + } + + let now = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_secs()) + .unwrap_or(0); + + if now < ts { + return "just now".to_string(); + } + + let diff = now - ts; + + if diff < 60 { + "just now".to_string() + } else if diff < 3600 { + let mins = diff / 60; + format!("{} min{} ago", mins, if mins == 1 { "" } else { "s" }) + } else if diff < 86400 { + let hours = diff / 3600; + format!("{} hour{} ago", hours, if hours == 1 { "" } else { "s" }) + } else if diff < 604800 { + let days = diff / 86400; + format!("{} day{} ago", days, if days == 1 { "" } else { "s" }) + } else if diff < 2592000 { + let weeks = diff / 604800; + format!("{} week{} ago", weeks, if weeks == 1 { "" } else { "s" }) + } else { + let months = diff / 2592000; + format!("{} month{} ago", months, if months == 1 { "" } else { "s" }) + } +} diff --git a/nora-registry/src/ui/mod.rs b/nora-registry/src/ui/mod.rs new file mode 100644 index 0000000..40d96c1 --- /dev/null +++ b/nora-registry/src/ui/mod.rs @@ -0,0 +1,114 @@ +mod api; +mod components; +mod templates; + +use crate::AppState; +use axum::{ + extract::{Path, State}, + response::{Html, IntoResponse, Redirect}, + routing::get, + Router, +}; +use std::sync::Arc; + +use api::*; +use templates::*; + +pub fn routes() -> Router> { + Router::new() + // UI Pages + .route("/", get(|| async { Redirect::to("/ui/") })) + .route("/ui", get(|| async { Redirect::to("/ui/") })) + .route("/ui/", get(dashboard)) + .route("/ui/docker", get(docker_list)) + .route("/ui/docker/{name}", get(docker_detail)) + .route("/ui/maven", get(maven_list)) + .route("/ui/maven/{*path}", get(maven_detail)) + .route("/ui/npm", get(npm_list)) + .route("/ui/npm/{name}", get(npm_detail)) + .route("/ui/cargo", get(cargo_list)) + .route("/ui/cargo/{name}", get(cargo_detail)) + .route("/ui/pypi", get(pypi_list)) + .route("/ui/pypi/{name}", get(pypi_detail)) + // API endpoints for HTMX + .route("/api/ui/stats", get(api_stats)) + .route("/api/ui/{registry_type}/list", get(api_list)) + .route("/api/ui/{registry_type}/{name}", get(api_detail)) + .route("/api/ui/{registry_type}/search", get(api_search)) +} + +// Dashboard page +async fn dashboard(State(state): State>) -> impl IntoResponse { + let stats = get_registry_stats(&state.storage).await; + Html(render_dashboard(&stats)) +} + +// Docker pages +async fn docker_list(State(state): State>) -> impl IntoResponse { + let repos = get_docker_repos(&state.storage).await; + Html(render_registry_list("docker", "Docker Registry", &repos)) +} + +async fn docker_detail( + State(state): State>, + Path(name): Path, +) -> impl IntoResponse { + let detail = get_docker_detail(&state.storage, &name).await; + Html(render_docker_detail(&name, &detail)) +} + +// Maven pages +async fn maven_list(State(state): State>) -> impl IntoResponse { + let repos = get_maven_repos(&state.storage).await; + Html(render_registry_list("maven", "Maven Repository", &repos)) +} + +async fn maven_detail( + State(state): State>, + Path(path): Path, +) -> impl IntoResponse { + let detail = get_maven_detail(&state.storage, &path).await; + Html(render_maven_detail(&path, &detail)) +} + +// npm pages +async fn npm_list(State(state): State>) -> impl IntoResponse { + let packages = get_npm_packages(&state.storage).await; + Html(render_registry_list("npm", "npm Registry", &packages)) +} + +async fn npm_detail( + State(state): State>, + Path(name): Path, +) -> impl IntoResponse { + let detail = get_npm_detail(&state.storage, &name).await; + Html(render_package_detail("npm", &name, &detail)) +} + +// Cargo pages +async fn cargo_list(State(state): State>) -> impl IntoResponse { + let crates = get_cargo_crates(&state.storage).await; + Html(render_registry_list("cargo", "Cargo Registry", &crates)) +} + +async fn cargo_detail( + State(state): State>, + Path(name): Path, +) -> impl IntoResponse { + let detail = get_cargo_detail(&state.storage, &name).await; + Html(render_package_detail("cargo", &name, &detail)) +} + +// PyPI pages +async fn pypi_list(State(state): State>) -> impl IntoResponse { + let packages = get_pypi_packages(&state.storage).await; + Html(render_registry_list("pypi", "PyPI Repository", &packages)) +} + +async fn pypi_detail( + State(state): State>, + Path(name): Path, +) -> impl IntoResponse { + let detail = get_pypi_detail(&state.storage, &name).await; + Html(render_package_detail("pypi", &name, &detail)) +} diff --git a/nora-registry/src/ui/templates.rs b/nora-registry/src/ui/templates.rs new file mode 100644 index 0000000..e744c26 --- /dev/null +++ b/nora-registry/src/ui/templates.rs @@ -0,0 +1,478 @@ +use super::api::{DockerDetail, MavenDetail, PackageDetail, RegistryStats, RepoInfo}; +use super::components::*; + +/// Renders the main dashboard page +pub fn render_dashboard(stats: &RegistryStats) -> String { + let content = format!( + r##" +
+

Dashboard

+

Overview of all registries

+
+ +
+ {} + {} + {} + {} + {} +
+ + + "##, + stat_card("Docker", "🐳", stats.docker, "/ui/docker", "images"), + stat_card("Maven", "☕", stats.maven, "/ui/maven", "artifacts"), + stat_card("npm", "📦", stats.npm, "/ui/npm", "packages"), + stat_card("Cargo", "🦀", stats.cargo, "/ui/cargo", "crates"), + stat_card("PyPI", "🐍", stats.pypi, "/ui/pypi", "packages"), + ); + + layout("Dashboard", &content, Some("dashboard")) +} + +/// Renders a registry list page (docker, maven, npm, cargo, pypi) +pub fn render_registry_list(registry_type: &str, title: &str, repos: &[RepoInfo]) -> String { + let icon = get_registry_icon(registry_type); + + let table_rows = if repos.is_empty() { + r##" +
📭
+
No repositories found
+
Push your first artifact to see it here
+ "## + .to_string() + } else { + repos + .iter() + .map(|repo| { + let detail_url = + format!("/ui/{}/{}", registry_type, encode_uri_component(&repo.name)); + format!( + r##" + + + {} + + {} + {} + {} + + "##, + detail_url, + detail_url, + html_escape(&repo.name), + repo.versions, + format_size(repo.size), + &repo.updated + ) + }) + .collect::>() + .join("") + }; + + let version_label = match registry_type { + "docker" => "Tags", + "maven" => "Versions", + _ => "Versions", + }; + + let content = format!( + r##" +
+
+ {} +
+

{}

+

{} repositories

+
+
+
+
+ + + + +
+
+
+ +
+ + + + + + + + + + + {} + +
Name{}SizeUpdated
+
+ "##, + icon, + title, + repos.len(), + registry_type, + version_label, + table_rows + ); + + layout(title, &content, Some(registry_type)) +} + +/// Renders Docker image detail page +pub fn render_docker_detail(name: &str, detail: &DockerDetail) -> String { + let tags_rows = if detail.tags.is_empty() { + r##"No tags found"##.to_string() + } else { + detail + .tags + .iter() + .map(|tag| { + format!( + r##" + + + {} + + {} + {} + + "##, + html_escape(&tag.name), + format_size(tag.size), + &tag.created + ) + }) + .collect::>() + .join("") + }; + + let pull_cmd = format!("docker pull 127.0.0.1:4000/{}", name); + + let content = format!( + r##" +
+
+ Docker Registry + / + {} +
+
+ 🐳 +

{}

+
+
+ +
+

Pull Command

+
+ {} + +
+
+ +
+
+

Tags ({} total)

+
+ + + + + + + + + + {} + +
TagSizeCreated
+
+ "##, + html_escape(name), + html_escape(name), + pull_cmd, + pull_cmd, + detail.tags.len(), + tags_rows + ); + + layout(&format!("{} - Docker", name), &content, Some("docker")) +} + +/// Renders package detail page (npm, cargo, pypi) +pub fn render_package_detail(registry_type: &str, name: &str, detail: &PackageDetail) -> String { + let icon = get_registry_icon(registry_type); + let registry_title = get_registry_title(registry_type); + + let versions_rows = if detail.versions.is_empty() { + r##"No versions found"##.to_string() + } else { + detail + .versions + .iter() + .map(|v| { + format!( + r##" + + + {} + + {} + {} + + "##, + html_escape(&v.version), + format_size(v.size), + &v.published + ) + }) + .collect::>() + .join("") + }; + + let install_cmd = match registry_type { + "npm" => format!("npm install {} --registry http://127.0.0.1:4000/npm", name), + "cargo" => format!("cargo add {}", name), + "pypi" => format!( + "pip install {} --index-url http://127.0.0.1:4000/simple", + name + ), + _ => String::new(), + }; + + let content = format!( + r##" +
+
+ {} + / + {} +
+
+ {} +

{}

+
+
+ +
+

Install Command

+
+ {} + +
+
+ +
+
+

Versions ({} total)

+
+ + + + + + + + + + {} + +
VersionSizePublished
+
+ "##, + registry_type, + registry_title, + html_escape(name), + icon, + html_escape(name), + install_cmd, + install_cmd, + detail.versions.len(), + versions_rows + ); + + layout( + &format!("{} - {}", name, registry_title), + &content, + Some(registry_type), + ) +} + +/// Renders Maven artifact detail page +pub fn render_maven_detail(path: &str, detail: &MavenDetail) -> String { + let artifact_rows = if detail.artifacts.is_empty() { + r##"No artifacts found"##.to_string() + } else { + detail.artifacts.iter().map(|a| { + let download_url = format!("/maven2/{}/{}", path, a.filename); + format!(r##" + + + {} + + {} + + "##, download_url, html_escape(&a.filename), format_size(a.size)) + }).collect::>().join("") + }; + + // Extract artifact name from path (last component before version) + let parts: Vec<&str> = path.split('/').collect(); + let artifact_name = if parts.len() >= 2 { + parts[parts.len() - 2] + } else { + path + }; + + let dep_cmd = format!( + r#" + {} + {} + {} +"#, + parts[..parts.len().saturating_sub(2)].join("."), + artifact_name, + parts.last().unwrap_or(&"") + ); + + let content = format!( + r##" +
+
+ Maven Repository + / + {} +
+
+ +

{}

+
+
+ +
+

Maven Dependency

+
{}
+
+ +
+
+

Artifacts ({} files)

+
+ + + + + + + + + {} + +
FilenameSize
+
+ "##, + html_escape(path), + html_escape(path), + html_escape(&dep_cmd), + detail.artifacts.len(), + artifact_rows + ); + + layout(&format!("{} - Maven", path), &content, Some("maven")) +} + +fn get_registry_icon(registry_type: &str) -> &'static str { + match registry_type { + "docker" => "🐳", + "maven" => "☕", + "npm" => "📦", + "cargo" => "🦀", + "pypi" => "🐍", + _ => "📁", + } +} + +fn get_registry_title(registry_type: &str) -> &'static str { + match registry_type { + "docker" => "Docker Registry", + "maven" => "Maven Repository", + "npm" => "npm Registry", + "cargo" => "Cargo Registry", + "pypi" => "PyPI Repository", + _ => "Registry", + } +} + +/// Simple URL encoding for path components +pub fn encode_uri_component(s: &str) -> String { + let mut result = String::new(); + for c in s.chars() { + match c { + 'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' | '.' | '~' => result.push(c), + _ => { + for byte in c.to_string().as_bytes() { + result.push_str(&format!("%{:02X}", byte)); + } + } + } + } + result +} diff --git a/nora-storage/Cargo.toml b/nora-storage/Cargo.toml new file mode 100644 index 0000000..341259a --- /dev/null +++ b/nora-storage/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "nora-storage" +version.workspace = true +edition.workspace = true +license.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true +description = "S3-compatible storage server for NORA" + +[[bin]] +name = "nora-storage" +path = "src/main.rs" + +[dependencies] +tokio.workspace = true +axum.workspace = true +serde.workspace = true +serde_json.workspace = true +tracing.workspace = true +tracing-subscriber.workspace = true +toml = "0.8" +uuid = { version = "1", features = ["v4"] } +sha2 = "0.10" +base64 = "0.22" +httpdate = "1" +chrono = { version = "0.4", features = ["serde"] } +quick-xml = { version = "0.31", features = ["serialize"] } diff --git a/nora-storage/src/config.rs b/nora-storage/src/config.rs new file mode 100644 index 0000000..232cb32 --- /dev/null +++ b/nora-storage/src/config.rs @@ -0,0 +1,44 @@ +use serde::{Deserialize, Serialize}; +use std::fs; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Config { + pub server: ServerConfig, + pub storage: StorageConfig, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServerConfig { + pub host: String, + pub port: u16, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct StorageConfig { + pub data_dir: String, + pub max_body_size: usize, +} + +impl Config { + pub fn load() -> Self { + fs::read_to_string("config.toml") + .ok() + .and_then(|content| toml::from_str(&content).ok()) + .unwrap_or_default() + } +} + +impl Default for Config { + fn default() -> Self { + Self { + server: ServerConfig { + host: String::from("127.0.0.1"), + port: 3000, + }, + storage: StorageConfig { + data_dir: String::from("data"), + max_body_size: 1024 * 1024 * 1024, // 1GB + }, + } + } +} diff --git a/nora-storage/src/main.rs b/nora-storage/src/main.rs new file mode 100644 index 0000000..d8ac6ad --- /dev/null +++ b/nora-storage/src/main.rs @@ -0,0 +1,304 @@ +mod config; + +use axum::extract::DefaultBodyLimit; +use axum::{ + body::Bytes, + extract::{Path, State}, + http::StatusCode, + response::{IntoResponse, Response}, + routing::{delete, get, put}, + Router, +}; +use chrono::Utc; +use config::Config; +use quick_xml::se::to_string as to_xml; +use serde::Serialize; +use std::fs; +use std::sync::Arc; +use tracing::info; + +pub struct AppState { + pub config: Config, +} + +#[derive(Serialize)] +#[serde(rename = "ListAllMyBucketsResult")] +struct ListBucketsResult { + #[serde(rename = "Buckets")] + buckets: Buckets, +} + +#[derive(Serialize)] +struct Buckets { + #[serde(rename = "Bucket")] + bucket: Vec, +} + +#[derive(Serialize)] +struct BucketInfo { + #[serde(rename = "Name")] + name: String, + #[serde(rename = "CreationDate")] + creation_date: String, +} + +#[derive(Serialize)] +#[serde(rename = "ListBucketResult")] +struct ListObjectsResult { + #[serde(rename = "Name")] + name: String, + #[serde(rename = "Contents")] + contents: Vec, +} + +#[derive(Serialize)] +struct ObjectInfo { + #[serde(rename = "Key")] + key: String, + #[serde(rename = "Size")] + size: u64, + #[serde(rename = "LastModified")] + last_modified: String, +} + +#[derive(Serialize)] +#[serde(rename = "Error")] +struct S3Error { + #[serde(rename = "Code")] + code: String, + #[serde(rename = "Message")] + message: String, +} + +fn xml_response(data: T) -> Response { + let xml = format!( + "\n{}", + to_xml(&data).unwrap() + ); + ( + StatusCode::OK, + [(axum::http::header::CONTENT_TYPE, "application/xml")], + xml, + ) + .into_response() +} + +fn error_response(status: StatusCode, code: &str, message: &str) -> Response { + let error = S3Error { + code: code.to_string(), + message: message.to_string(), + }; + let xml = format!( + "\n{}", + to_xml(&error).unwrap() + ); + ( + status, + [(axum::http::header::CONTENT_TYPE, "application/xml")], + xml, + ) + .into_response() +} + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt() + .with_env_filter( + tracing_subscriber::EnvFilter::from_default_env() + .add_directive("nora_storage=info".parse().unwrap()), + ) + .init(); + + let config = Config::load(); + fs::create_dir_all(&config.storage.data_dir).unwrap(); + + let state = Arc::new(AppState { + config: config.clone(), + }); + + let app = Router::new() + .route("/", get(list_buckets)) + .route("/{bucket}", get(list_objects)) + .route("/{bucket}", put(create_bucket)) + .route("/{bucket}", delete(delete_bucket)) + .route("/{bucket}/{*key}", put(put_object)) + .route("/{bucket}/{*key}", get(get_object)) + .route("/{bucket}/{*key}", delete(delete_object)) + .layer(DefaultBodyLimit::max(config.storage.max_body_size)) + .with_state(state); + + let addr = format!("{}:{}", config.server.host, config.server.port); + let listener = tokio::net::TcpListener::bind(&addr).await.unwrap(); + + info!("nora-storage (S3 compatible) running on http://{}", addr); + axum::serve(listener, app).await.unwrap(); +} + +async fn list_buckets(State(state): State>) -> Response { + let data_dir = &state.config.storage.data_dir; + let entries = match fs::read_dir(data_dir) { + Ok(e) => e, + Err(_) => { + return error_response( + StatusCode::INTERNAL_SERVER_ERROR, + "InternalError", + "Failed to read data", + ) + } + }; + + let bucket_list: Vec = entries + .filter_map(|e| e.ok()) + .filter(|e| e.path().is_dir()) + .filter_map(|e| { + let name = e.file_name().into_string().ok()?; + let modified = e.metadata().ok()?.modified().ok()?; + let datetime: chrono::DateTime = modified.into(); + Some(BucketInfo { + name, + creation_date: datetime.format("%Y-%m-%dT%H:%M:%SZ").to_string(), + }) + }) + .collect(); + + xml_response(ListBucketsResult { + buckets: Buckets { + bucket: bucket_list, + }, + }) +} + +async fn list_objects(State(state): State>, Path(bucket): Path) -> Response { + let bucket_path = format!("{}/{}", state.config.storage.data_dir, bucket); + + if !std::path::Path::new(&bucket_path).is_dir() { + return error_response( + StatusCode::NOT_FOUND, + "NoSuchBucket", + "The specified bucket does not exist", + ); + } + + let objects = collect_files(std::path::Path::new(&bucket_path), ""); + xml_response(ListObjectsResult { + name: bucket, + contents: objects, + }) +} + +fn collect_files(dir: &std::path::Path, prefix: &str) -> Vec { + let mut objects = Vec::new(); + if let Ok(entries) = fs::read_dir(dir) { + for entry in entries.filter_map(|e| e.ok()) { + let path = entry.path(); + let name = entry.file_name().into_string().unwrap_or_default(); + let key = if prefix.is_empty() { + name.clone() + } else { + format!("{}/{}", prefix, name) + }; + + if path.is_dir() { + objects.extend(collect_files(&path, &key)); + } else if let Ok(metadata) = entry.metadata() { + let modified: chrono::DateTime = metadata.modified().unwrap().into(); + objects.push(ObjectInfo { + key, + size: metadata.len(), + last_modified: modified.format("%Y-%m-%dT%H:%M:%SZ").to_string(), + }); + } + } + } + objects +} + +async fn create_bucket(State(state): State>, Path(bucket): Path) -> Response { + let bucket_path = format!("{}/{}", state.config.storage.data_dir, bucket); + match fs::create_dir(&bucket_path) { + Ok(_) => (StatusCode::OK, "").into_response(), + Err(_) => error_response( + StatusCode::CONFLICT, + "BucketAlreadyExists", + "Bucket already exists", + ), + } +} + +async fn put_object( + State(state): State>, + Path((bucket, key)): Path<(String, String)>, + body: Bytes, +) -> Response { + let file_path = format!("{}/{}/{}", state.config.storage.data_dir, bucket, key); + + if let Some(parent) = std::path::Path::new(&file_path).parent() { + let _ = fs::create_dir_all(parent); + } + + match fs::write(&file_path, &body) { + Ok(_) => { + println!("PUT {}/{} ({} bytes)", bucket, key, body.len()); + (StatusCode::OK, "").into_response() + } + Err(e) => { + println!("ERROR writing {}/{}: {}", bucket, key, e); + error_response( + StatusCode::INTERNAL_SERVER_ERROR, + "InternalError", + "Failed to write object", + ) + } + } +} + +async fn get_object( + State(state): State>, + Path((bucket, key)): Path<(String, String)>, +) -> Response { + let file_path = format!("{}/{}/{}", state.config.storage.data_dir, bucket, key); + + match fs::read(&file_path) { + Ok(data) => (StatusCode::OK, data).into_response(), + Err(_) => error_response( + StatusCode::NOT_FOUND, + "NoSuchKey", + "The specified key does not exist", + ), + } +} + +async fn delete_object( + State(state): State>, + Path((bucket, key)): Path<(String, String)>, +) -> Response { + let file_path = format!("{}/{}/{}", state.config.storage.data_dir, bucket, key); + + match fs::remove_file(&file_path) { + Ok(_) => { + println!("DELETE {}/{}", bucket, key); + (StatusCode::NO_CONTENT, "").into_response() + } + Err(_) => error_response( + StatusCode::NOT_FOUND, + "NoSuchKey", + "The specified key does not exist", + ), + } +} + +async fn delete_bucket(State(state): State>, Path(bucket): Path) -> Response { + let bucket_path = format!("{}/{}", state.config.storage.data_dir, bucket); + + match fs::remove_dir(&bucket_path) { + Ok(_) => { + println!("DELETE bucket {}", bucket); + (StatusCode::NO_CONTENT, "").into_response() + } + Err(_) => error_response( + StatusCode::CONFLICT, + "BucketNotEmpty", + "The bucket is not empty", + ), + } +}