diff --git a/.github/workflows/rust-ci.yaml b/.github/workflows/rust-ci.yaml new file mode 100644 index 000000000..c408100a8 --- /dev/null +++ b/.github/workflows/rust-ci.yaml @@ -0,0 +1,101 @@ +name: "Rust CI/CD Pipeline" + +on: + push: + pull_request: + types: [opened, reopened] + +env: + RUST_BACKTRACE: 1 + +jobs: + format: + name: "[RUST] Format Check" + runs-on: ubuntu-latest + steps: + - name: "Checkout code" + uses: actions/checkout@v7 + + - name: "Install Rust toolchain" + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - name: "Check formatting" + run: cargo fmt --all -- --check + + lint: + name: "[RUST] Lint Check" + runs-on: ubuntu-latest + steps: + - name: "Checkout code" + uses: actions/checkout@v7 + + - name: "Install Rust toolchain" + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + + - name: "Cache cargo registry" + uses: actions/cache@v6 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: "Run clippy" + run: cargo clippy --all-targets --all-features + + build: + name: "[RUST] Build" + needs: [lint, format] + runs-on: ubuntu-latest + steps: + - name: "Checkout code" + uses: actions/checkout@v7 + + - name: "Install Rust toolchain" + uses: dtolnay/rust-toolchain@stable + + - name: "Cache cargo registry" + uses: actions/cache@v6 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: "Build workspace" + run: cargo build --verbose --all-features + + test: + name: "[RUST] Test" + needs: [build] + runs-on: ubuntu-latest + steps: + - name: "Checkout code" + uses: actions/checkout@v7 + + - name: "Install Rust toolchain" + uses: dtolnay/rust-toolchain@stable + + - name: "Cache cargo registry" + uses: actions/cache@v6 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-report-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: "Test workspace" + run: cargo test diff --git a/.gitignore b/.gitignore index c95bcedcf..010661c2c 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,5 @@ ## ################ config/sagittarius.yml +gateway/target +target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 000000000..47fe9a39c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1362 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" + +[[package]] +name = "arraydeque" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" + +[[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.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "axum" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90" +dependencies = [ + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "sync_wrapper", + "tower", + "tower-layer", + "tower-service", +] + +[[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", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" +dependencies = [ + "serde_core", +] + +[[package]] +name = "bytes" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "num-traits", +] + +[[package]] +name = "config" +version = "0.15.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b85f248a4de22d204ceabc6299d89d2c70fbd7f09fea53c06c852369652d8139" +dependencies = [ + "async-trait", + "convert_case", + "json5", + "pathdiff", + "ron", + "rust-ini", + "serde-untagged", + "serde_core", + "serde_json", + "toml", + "winnow", + "yaml-rust2", +] + +[[package]] +name = "const-random" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom 0.2.17", + "once_cell", + "tiny-keccak", +] + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "dlv-list" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" +dependencies = [ + "const-random", +] + +[[package]] +name = "either" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "erased-serde" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2add8a07dd6a8d93ff627029c51de145e12686fbc36ecb298ac22e74cf02dec" +dependencies = [ + "serde", + "serde_core", + "typeid", +] + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" + +[[package]] +name = "fixedbitset" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "gateway" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "config", + "log", + "serde", + "tokio", + "tonic", + "tucana", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + +[[package]] +name = "h2" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cb093c84e8bd9b188d4c4a8cb6579fc016968d14c99882163cd3ff402a4f155" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash 0.1.5", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "foldhash 0.2.0", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "hashlink" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824e001ac4f3012dd16a264bec811403a67ca9deb6c102fc5049b32c4574b35f" +dependencies = [ + "hashbrown 0.16.1", +] + +[[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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425" +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.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55281c53a1894c864990125767da440a4e630446785086f52523b20033b74498" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-timeout" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" +dependencies = [ + "hyper", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "libc", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", +] + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "json5" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" +dependencies = [ + "pest", + "pest_derive", + "serde", +] + +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "log" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02bd0af71c67b473010cbbc60715ee815645a4dc942899111f494b4b737d6fda" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "multimap" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "ordered-multimap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" +dependencies = [ + "dlv-list", + "hashbrown 0.14.5", +] + +[[package]] +name = "pathdiff" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" + +[[package]] +name = "pbjson" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8edd1efdd8ab23ba9cb9ace3d9987a72663d5d7c9f74fa00b51d6213645cf6c" +dependencies = [ + "base64", + "serde", +] + +[[package]] +name = "pbjson-build" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ed4d5c6ae95e08ac768883c8401cf0e8deb4e6e1d6a4e1fd3d2ec4f0ec63200" +dependencies = [ + "heck", + "itertools", + "prost", + "prost-types", +] + +[[package]] +name = "pbjson-types" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a14e2757d877c0f607a82ce1b8560e224370f159d66c5d52eb55ea187ef0350e" +dependencies = [ + "bytes", + "chrono", + "pbjson", + "pbjson-build", + "prost", + "prost-build", + "serde", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pest" +version = "2.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47627dd7305c6a2d6c8c6bcd24c5a4c17dbbf425f4f9c5313e724b38fc9782e9" +dependencies = [ + "memchr", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b4254325ecad416ab689e27ba51da03ba01a9632bc6e108f5fe7c3c4ad29d58" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c4c0e91ead7a8f7acecbca6f003fc2e8282b1dbe2dd9c9d2f16aba42995e0a7" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9744bc48116fee06334924bb5f2bad41eed5e89bd26e29b0b799f9a3f82c210" +dependencies = [ + "pest", +] + +[[package]] +name = "petgraph" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8701b58ea97060d5e5b155d383a69952a60943f0e6dfe30b04c287beb0b27455" +dependencies = [ + "fixedbitset", + "hashbrown 0.15.5", + "indexmap", +] + +[[package]] +name = "pin-project" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528ac67416ff8646872a3c02cad9cc4ee5dc9f9540c9b10771855c95cb2e5ae1" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03da047801ff44bb6a4d407d4860c05fd70bb81714e6b2f3812603d5b145b042" +dependencies = [ + "heck", + "itertools", + "log", + "multimap", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "pulldown-cmark", + "pulldown-cmark-to-cmark", + "regex", + "syn", + "tempfile", +] + +[[package]] +name = "prost-derive" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b570b25f7617e43d59005d0990ccb79e950a423952cea19671b7a876da390adf" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-types" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f94967dc7688f3054c7fac87473ffae4cc4c3904800e2d9f5b857246d8963b0a" +dependencies = [ + "prost", +] + +[[package]] +name = "pulldown-cmark" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9f068eba8e7071c5f9511831b44f32c740d5adf574e990f946ddb53db2f314e" +dependencies = [ + "bitflags", + "memchr", + "unicase", +] + +[[package]] +name = "pulldown-cmark-to-cmark" +version = "22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50793def1b900256624a709439404384204a5dc3a6ec580281bfaac35e882e90" +dependencies = [ + "pulldown-cmark", +] + +[[package]] +name = "quote" +version = "1.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "regex" +version = "1.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "ron" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81116b9531d61eabc41aeb228e4b6b2435bcca3233b98cf3b3077d4e6e9debb3" +dependencies = [ + "bitflags", + "once_cell", + "serde", + "serde_derive", + "typeid", + "unicode-ident", +] + +[[package]] +name = "rust-ini" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "796e8d2b6696392a43bea58116b667fb4c29727dc5abd27d6acf338bb4f688c7" +dependencies = [ + "cfg-if", + "ordered-multimap", +] + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[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-untagged" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9faf48a4a2d2693be24c6289dbe26552776eb7737074e6722891fadbe6c5058" +dependencies = [ + "erased-serde", + "serde", + "serde_core", + "typeid", +] + +[[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.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" +dependencies = [ + "serde_core", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" + +[[package]] +name = "socket2" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52d1cfed4120b4d927bf7c0f86d2087a4a7d6027c906d9f9d525a80573b9be51" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.3", + "once_cell", + "rustix", + "windows-sys", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tokio" +version = "1.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-stream" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee" +dependencies = [ + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" +dependencies = [ + "winnow", +] + +[[package]] +name = "tonic" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac2a5518c70fa84342385732db33fb3f44bc4cc748936eb5833d2df34d6445ef" +dependencies = [ + "async-trait", + "axum", + "base64", + "bytes", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-timeout", + "hyper-util", + "percent-encoding", + "pin-project", + "socket2", + "sync_wrapper", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tonic-build" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f61875ac5293cf72e6c8cf0158086428c82c37229e98c840878f1706b0322" +dependencies = [ + "prettyplease", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tonic-prost" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50849f68853be452acf590cde0b146665b8d507b3b8af17261df47e02c209ea0" +dependencies = [ + "bytes", + "prost", + "tonic", +] + +[[package]] +name = "tonic-prost-build" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "654e5643eff75d7f8c99197ce1440ed19a3474eada74c12bbac488b2cafdae27" +dependencies = [ + "prettyplease", + "proc-macro2", + "prost-build", + "prost-types", + "quote", + "syn", + "tempfile", + "tonic-build", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "indexmap", + "pin-project-lite", + "slab", + "sync_wrapper", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "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", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tucana" +version = "0.0.0" +dependencies = [ + "pbjson", + "pbjson-build", + "pbjson-types", + "prost", + "prost-build", + "prost-types", + "serde", + "serde_json", + "tonic", + "tonic-build", + "tonic-prost", + "tonic-prost-build", +] + +[[package]] +name = "typeid" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" + +[[package]] +name = "ucd-trie" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" + +[[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.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-segmentation" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" + +[[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 = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[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 = "winnow" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1" +dependencies = [ + "memchr", +] + +[[package]] +name = "yaml-rust2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "631a50d867fafb7093e709d75aaee9e0e0d5deb934021fcea25ac2fe09edc51e" +dependencies = [ + "arraydeque", + "encoding_rs", + "hashlink", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 000000000..7f3f2c968 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,17 @@ +[workspace] +members = ["gateway"] +resolver = "3" + +[workspace.package] +version = "0.1.0" +edition = "2024" + +[workspace.dependencies] +anyhow = "1.0.100" +async-trait = "0.1.89" +config = "0.15.25" +log = "0.4.33" +serde = { version = "1.0.228", features = ["derive"] } +tokio = { version = "1.52.3", features = ["macros", "rt-multi-thread", "sync"] } +tonic = "0.14.6" +tucana = { path = "../tucana/build/rust", features = ["sagittarius_gateway", "sagittarius_rails"] } diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml new file mode 100644 index 000000000..5b81a7600 --- /dev/null +++ b/gateway/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "gateway" +version.workspace = true +edition.workspace = true + +[dependencies] +anyhow = { workspace = true } +async-trait = { workspace = true } +config = { workspace = true } +log = { workspace = true } +serde = { workspace = true } +tokio = { workspace = true } +tonic = { workspace = true } +tucana = { workspace = true } diff --git a/gateway/gateway.yml b/gateway/gateway.yml new file mode 100644 index 000000000..c700d33be --- /dev/null +++ b/gateway/gateway.yml @@ -0,0 +1,6 @@ +backend: + url: "grpc://127.0.0.1:50051" + +grpc: + port: 50051 + host: "127.0.0.1" diff --git a/gateway/src/client/execution_service_client.rs b/gateway/src/client/execution_service_client.rs new file mode 100644 index 000000000..8bb343b6a --- /dev/null +++ b/gateway/src/client/execution_service_client.rs @@ -0,0 +1,29 @@ +use tonic::codegen::StdError; +use tonic::transport::{Channel, Endpoint}; +use tucana::sagittarius_rails::execution_service_client::ExecutionServiceClient; +use tucana::sagittarius_rails::{ExecutionRequest, ExecutionResponse}; + +#[derive(Clone)] +pub struct SagittariusRailsExecutionServiceClient { + inner: ExecutionServiceClient, +} + +impl SagittariusRailsExecutionServiceClient { + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + Ok(Self { + inner: ExecutionServiceClient::connect(dst).await?, + }) + } + + pub async fn update( + &self, + request: ExecutionRequest, + ) -> Result, tonic::Status> { + log::debug!("Proxying a execution response."); + self.inner.clone().update(request).await + } +} diff --git a/gateway/src/client/flow_service_client.rs b/gateway/src/client/flow_service_client.rs new file mode 100644 index 000000000..3ede82269 --- /dev/null +++ b/gateway/src/client/flow_service_client.rs @@ -0,0 +1,29 @@ +use tonic::codegen::StdError; +use tonic::transport::{Channel, Endpoint}; +use tucana::sagittarius_rails::flow_service_client::FlowServiceClient; +use tucana::sagittarius_rails::{FlowLogonRequest, FlowResponse}; + +#[derive(Clone)] +pub struct SagittariusRailsFlowServiceClient { + inner: FlowServiceClient, +} + +impl SagittariusRailsFlowServiceClient { + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + Ok(Self { + inner: FlowServiceClient::connect(dst).await?, + }) + } + + pub async fn update( + &self, + request: FlowLogonRequest, + ) -> Result, tonic::Status> { + log::debug!("Proxying a execution flow logon request."); + self.inner.clone().update(request).await + } +} diff --git a/gateway/src/client/mod.rs b/gateway/src/client/mod.rs new file mode 100644 index 000000000..33186043f --- /dev/null +++ b/gateway/src/client/mod.rs @@ -0,0 +1,7 @@ +#![allow(dead_code)] + +pub mod execution_service_client; +pub mod flow_service_client; +pub mod module_service_client; +pub mod runtime_status_service_client; +pub mod token_service_client; diff --git a/gateway/src/client/module_service_client.rs b/gateway/src/client/module_service_client.rs new file mode 100644 index 000000000..0c1a4d7ea --- /dev/null +++ b/gateway/src/client/module_service_client.rs @@ -0,0 +1,28 @@ +use tonic::codegen::StdError; +use tonic::transport::{Channel, Endpoint}; +use tucana::sagittarius_rails::module_service_client::ModuleServiceClient; +use tucana::sagittarius_rails::{ModuleUpdateRequest, ModuleUpdateResponse}; + +pub struct SagittariusRailsModuleServiceClient { + inner: ModuleServiceClient, +} + +impl SagittariusRailsModuleServiceClient { + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + Ok(Self { + inner: ModuleServiceClient::connect(dst).await?, + }) + } + + pub async fn update( + &mut self, + request: ModuleUpdateRequest, + ) -> Result, tonic::Status> { + log::debug!("Proxying a module update request."); + self.inner.update(request).await + } +} diff --git a/gateway/src/client/runtime_status_service_client.rs b/gateway/src/client/runtime_status_service_client.rs new file mode 100644 index 000000000..8e7acfa81 --- /dev/null +++ b/gateway/src/client/runtime_status_service_client.rs @@ -0,0 +1,28 @@ +use tonic::codegen::StdError; +use tonic::transport::{Channel, Endpoint}; +use tucana::sagittarius_rails::runtime_status_service_client::RuntimeStatusServiceClient; +use tucana::sagittarius_rails::{RuntimeStatusUpdateRequest, RuntimeStatusUpdateResponse}; + +pub struct SagittariusRailsRuntimeStatusServiceClient { + inner: RuntimeStatusServiceClient, +} + +impl SagittariusRailsRuntimeStatusServiceClient { + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + Ok(Self { + inner: RuntimeStatusServiceClient::connect(dst).await?, + }) + } + + pub async fn update( + &mut self, + request: RuntimeStatusUpdateRequest, + ) -> Result, tonic::Status> { + log::debug!("Proxying a status update request."); + self.inner.update(request).await + } +} diff --git a/gateway/src/client/token_service_client.rs b/gateway/src/client/token_service_client.rs new file mode 100644 index 000000000..d7a0cbb37 --- /dev/null +++ b/gateway/src/client/token_service_client.rs @@ -0,0 +1,52 @@ +use tonic::codegen::StdError; +use tonic::transport::{Channel, Endpoint}; +use tucana::sagittarius_rails::token_service_client::TokenServiceClient; +use tucana::sagittarius_rails::token_verify_response::Data; +use tucana::sagittarius_rails::{TokenVerifyRequest, TokenVerifyResponse}; + +pub enum RuntimeVerificationStatus { + Verified { runtime_id: i64 }, + Unverified, +} + +pub struct SagittariusRailsTokenServiceClient { + inner: TokenServiceClient, +} + +impl SagittariusRailsTokenServiceClient { + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + Ok(Self { + inner: TokenServiceClient::connect(dst).await?, + }) + } + + async fn update( + &mut self, + request: TokenVerifyRequest, + ) -> Result, tonic::Status> { + self.inner.update(request).await + } + + pub async fn validate_token(&mut self, token: String) -> RuntimeVerificationStatus { + let response = self.update(TokenVerifyRequest { token }).await; + + let status_response = match response { + Ok(res) => res, + Err(_) => return RuntimeVerificationStatus::Unverified, + }; + + match status_response.into_inner().data { + Some(status) => match status { + Data::Verified(verified_runtime) => RuntimeVerificationStatus::Verified { + runtime_id: verified_runtime.runtime_id, + }, + Data::Unverified(_) => RuntimeVerificationStatus::Unverified, + }, + None => RuntimeVerificationStatus::Unverified, + } + } +} diff --git a/gateway/src/config/mod.rs b/gateway/src/config/mod.rs new file mode 100644 index 000000000..70d8bdb36 --- /dev/null +++ b/gateway/src/config/mod.rs @@ -0,0 +1,74 @@ +#![allow(dead_code)] + +use std::path::Path; + +use config::{Config as ConfigLoader, ConfigError, File}; +use serde::{Deserialize, Serialize}; + +const CONFIG_FILE: &str = "gateway"; + +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(default)] +#[derive(Default)] +pub struct Config { + pub backend: Backend, + pub grpc: Grpc, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(default)] +pub struct Backend { + pub url: String, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(default)] +pub struct Grpc { + port: u16, + host: String, +} + +impl Default for Grpc { + fn default() -> Self { + Self { + port: 50051, + host: String::from("127.0.0.1"), + } + } +} + +impl Default for Backend { + fn default() -> Self { + Self { + url: String::from("http://localhost:50051"), + } + } +} + + +impl Config { + pub fn new() -> Self { + Self::try_new() + .unwrap_or_else(|error| panic!("failed to load Aquila configuration: {error}")) + } + + pub fn try_new() -> Result { + Self::try_from_optional_path(None) + } + + pub fn try_from_path(path: impl AsRef) -> Result { + Self::try_from_optional_path(Some(path.as_ref())) + } + + fn try_from_optional_path(path: Option<&Path>) -> Result { + let mut builder = + ConfigLoader::builder().add_source(ConfigLoader::try_from(&Self::default())?); + + builder = match path { + Some(path) => builder.add_source(File::from(path).required(true)), + None => builder.add_source(File::with_name(CONFIG_FILE).required(false)), + }; + + builder.build()?.try_deserialize() + } +} diff --git a/gateway/src/main.rs b/gateway/src/main.rs new file mode 100644 index 000000000..042aa3392 --- /dev/null +++ b/gateway/src/main.rs @@ -0,0 +1,31 @@ +use tonic::transport::Channel; + +use crate::client::execution_service_client::SagittariusRailsExecutionServiceClient; +use crate::client::flow_service_client::SagittariusRailsFlowServiceClient; +use crate::client::module_service_client::SagittariusRailsModuleServiceClient; +use crate::client::runtime_status_service_client::SagittariusRailsRuntimeStatusServiceClient; +use crate::client::token_service_client::SagittariusRailsTokenServiceClient; +use crate::config::Config; + +mod client; +mod config; +mod server; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let config = Config::default(); + + let url = config.backend.url.clone(); + let channel = Channel::from_shared(url)?; + + let _rails_execution_client = + SagittariusRailsExecutionServiceClient::connect(channel.clone()).await?; + let _rails_flow_client = SagittariusRailsFlowServiceClient::connect(channel.clone()).await?; + let _rails_module_client = + SagittariusRailsModuleServiceClient::connect(channel.clone()).await?; + let _rails_status_client = + SagittariusRailsRuntimeStatusServiceClient::connect(channel.clone()).await?; + let _rails_token_client = SagittariusRailsTokenServiceClient::connect(channel.clone()).await?; + + Ok(()) +} diff --git a/gateway/src/server/execution_service_server.rs b/gateway/src/server/execution_service_server.rs new file mode 100644 index 000000000..308979c5f --- /dev/null +++ b/gateway/src/server/execution_service_server.rs @@ -0,0 +1,190 @@ +#![allow(dead_code)] + +use crate::client::execution_service_client::SagittariusRailsExecutionServiceClient; +use std::pin::Pin; +use std::sync::Arc; +use tokio::sync::{Mutex, OwnedMutexGuard, mpsc}; +use tonic::codegen::tokio_stream::Stream; +use tonic::codegen::tokio_stream::wrappers::ReceiverStream; +use tonic::metadata::MetadataMap; +use tonic::{Extensions, Response, Status}; +use tucana::sagittarius_gateway::execution_logon_request::Data; +use tucana::sagittarius_gateway::execution_service_server::ExecutionService; +use tucana::sagittarius_gateway::{ + ExecutionLogonRequest, ExecutionLogonResponse, ExecutionPushRequest, ExecutionPushResponse, + TestExecutionRequest, +}; +use tucana::sagittarius_rails::ExecutionRequest; + +const EXECUTION_QUEUE_CAPACITY: usize = 1024; + +pub struct SagittariusExecutionService { + client: SagittariusRailsExecutionServiceClient, + // Push is unary while Aquila is connected through a long-lived stream, so the + // service needs a queue between those two different RPC shapes. + stream_tx: mpsc::Sender, + // There is one shared queue of work for Aquila. Keeping the receiver guarded + // here makes that single-consumer assumption explicit at the service boundary. + stream_rx: Arc>>, +} + +type ExecutionUpdateStream = + Pin> + Send + 'static>>; + +type ExecutionResponseSender = mpsc::Sender>; + +impl SagittariusExecutionService { + pub fn new(client: SagittariusRailsExecutionServiceClient) -> Self { + let (stream_tx, stream_rx) = mpsc::channel(EXECUTION_QUEUE_CAPACITY); + + Self { + client, + stream_tx, + stream_rx: Arc::new(Mutex::new(stream_rx)), + } + } + + async fn run_update_stream( + client: SagittariusRailsExecutionServiceClient, + mut incoming_stream: tonic::Streaming, + mut outgoing_requests: OwnedMutexGuard>, + outgoing_stream: ExecutionResponseSender, + ) { + loop { + // Aquila's Update RPC is bidirectional, so its read and write sides + // belong in the same lifecycle loop. If either side closes, the whole + // stream should stop instead of leaving a detached half alive. + tokio::select! { + incoming_message = incoming_stream.message() => { + match incoming_message { + Ok(Some(message)) => Self::handle_aquila_message(client.clone(), message), + Ok(None) => { + log::info!("Aquila execution stream closed."); + break; + } + Err(err) => { + log::error!("Failed to receive execution update from Aquila: {}", err); + break; + } + } + } + outgoing_request = outgoing_requests.recv() => { + match outgoing_request { + Some(request) => { + if Self::send_to_aquila_stream(&outgoing_stream, request).await.is_err() { + log::info!("Aquila execution response stream closed."); + break; + } + } + None => { + log::info!("Execution request queue closed."); + break; + } + } + } + } + } + } + + fn handle_aquila_message( + client: SagittariusRailsExecutionServiceClient, + message: ExecutionLogonRequest, + ) { + match message.data { + Some(Data::Response(response)) => { + // Rails is a separate unary RPC. It is spawned from here so slow + // Rails calls do not hold up Aquila's stream reader. + tokio::spawn(async move { + let rails_request = ExecutionRequest { + response: Some(response), + }; + + if let Err(err) = client.update(rails_request).await { + log::error!("Failed to proxy execution response to Rails: {}", err); + } + }); + } + Some(Data::Logon(_)) => { + log::info!("Aquila execution stream connected."); + } + None => { + log::warn!("Received empty execution update from Aquila."); + } + } + } + + async fn send_to_aquila_stream( + outgoing_stream: &ExecutionResponseSender, + request: TestExecutionRequest, + ) -> Result<(), mpsc::error::SendError>> { + outgoing_stream + .send(Ok(ExecutionLogonResponse { + request: Some(request), + })) + .await + } + + fn empty_push_response() -> tonic::Response { + Response::from_parts( + MetadataMap::new(), + ExecutionPushResponse {}, + Extensions::new(), + ) + } + + fn extract_test_execution( + request: tonic::Request, + ) -> Option { + request.into_inner().request + } +} + +#[tonic::async_trait] +impl ExecutionService for SagittariusExecutionService { + type UpdateStream = ExecutionUpdateStream; + + // Aquila owns the long-lived stream, so this method is where the bridge + // between Aquila stream traffic and queued Sagittarius pushes is started. + async fn update( + &self, + request: tonic::Request>, + ) -> Result, tonic::Status> { + let client = self.client.clone(); + let incoming_stream = request.into_inner(); + // A second Aquila stream would compete for the same work queue and make + // delivery semantics unclear, so reject it at connection time. + let outgoing_requests = Arc::clone(&self.stream_rx) + .try_lock_owned() + .map_err(|_| Status::already_exists("Aquila execution stream is already connected"))?; + let (response_tx, response_rx) = mpsc::channel(EXECUTION_QUEUE_CAPACITY); + + tokio::spawn(Self::run_update_stream( + client, + incoming_stream, + outgoing_requests, + response_tx, + )); + + Ok(Response::new(Box::pin(ReceiverStream::new(response_rx)))) + } + + // Sagittarius only needs an acknowledgment that the request was accepted into + // the bridge. Actual delivery happens asynchronously through Aquila's stream. + async fn push( + &self, + request: tonic::Request, + ) -> Result, tonic::Status> { + let Some(test_execution) = Self::extract_test_execution(request) else { + return Ok(Self::empty_push_response()); + }; + + if let Err(err) = self.stream_tx.send(test_execution).await { + let error = format!("{:?}", err); + log::error!("{}", &error); + return Err(Status::internal(error)); + } + + log::info!("Received test execution request, will proxy request to Aquila."); + Ok(Self::empty_push_response()) + } +} diff --git a/gateway/src/server/flow_service_server.rs b/gateway/src/server/flow_service_server.rs new file mode 100644 index 000000000..9ecf06675 --- /dev/null +++ b/gateway/src/server/flow_service_server.rs @@ -0,0 +1,169 @@ +#![allow(dead_code)] + +use crate::client::flow_service_client::SagittariusRailsFlowServiceClient; +use std::pin::Pin; +use std::sync::Arc; + +use tokio::sync::{Mutex, OwnedMutexGuard, mpsc}; +use tonic::codegen::tokio_stream::Stream; +use tonic::codegen::tokio_stream::wrappers::ReceiverStream; +use tonic::metadata::MetadataMap; +use tonic::{Extensions, Response, Status}; +use tucana::sagittarius_gateway::flow_response as gateway_flow_response; +use tucana::sagittarius_gateway::flow_service_server::FlowService; +use tucana::sagittarius_gateway::{ + FlowLogonRequest, FlowPushRequest, FlowPushResponse, FlowResponse, +}; +use tucana::sagittarius_rails::flow_response as rails_flow_response; +use tucana::sagittarius_rails::{ + FlowLogonRequest as RailsFlowLogonRequest, FlowResponse as RailsFlowResponse, +}; + +const FLOW_QUEUE_CAPACITY: usize = 1024; + +pub struct SagittariusFlowService { + client: SagittariusRailsFlowServiceClient, + // Push is unary while Aquila receives updates through a long-lived stream, so + // the service needs a queue between those two different RPC shapes. + stream_tx: mpsc::Sender, + // There is one shared queue of flow updates for Aquila. Keeping the receiver + // guarded here makes that single-consumer assumption explicit at the boundary. + stream_rx: Arc>>, +} + +type FlowUpdateStream = + Pin> + Send + 'static>>; + +type FlowResponseSender = mpsc::Sender>; + +impl SagittariusFlowService { + pub fn new(client: SagittariusRailsFlowServiceClient) -> Self { + let (stream_tx, stream_rx) = mpsc::channel(FLOW_QUEUE_CAPACITY); + + Self { + client, + stream_tx, + stream_rx: Arc::new(Mutex::new(stream_rx)), + } + } + + async fn run_update_stream( + client: SagittariusRailsFlowServiceClient, + mut queued_updates: OwnedMutexGuard>, + outgoing_stream: FlowResponseSender, + ) { + if Self::send_initial_flow_state(client, &outgoing_stream) + .await + .is_err() + { + return; + } + + while let Some(flow_response) = queued_updates.recv().await { + if Self::send_to_aquila_stream(&outgoing_stream, flow_response) + .await + .is_err() + { + log::info!("Aquila flow stream closed."); + return; + } + } + + log::info!("Flow update queue closed."); + } + + async fn send_initial_flow_state( + client: SagittariusRailsFlowServiceClient, + outgoing_stream: &FlowResponseSender, + ) -> Result<(), ()> { + let rails_response = match client.update(RailsFlowLogonRequest {}).await { + Ok(response) => response.into_inner(), + Err(err) => { + log::error!("Failed to fetch initial flow state from Rails: {}", err); + let _ = outgoing_stream.send(Err(err)).await; + return Err(()); + } + }; + + Self::send_to_aquila_stream(outgoing_stream, Self::from_rails_response(rails_response)) + .await + .map_err(|_| { + log::info!("Aquila flow stream closed before initial state could be sent."); + }) + } + + async fn send_to_aquila_stream( + outgoing_stream: &FlowResponseSender, + response: FlowResponse, + ) -> Result<(), mpsc::error::SendError>> { + outgoing_stream.send(Ok(response)).await + } + + fn from_rails_response(response: RailsFlowResponse) -> FlowResponse { + FlowResponse { + data: response.data.map(|data| match data { + rails_flow_response::Data::UpdatedFlow(flow) => { + gateway_flow_response::Data::UpdatedFlow(flow) + } + rails_flow_response::Data::DeletedFlowId(flow_id) => { + gateway_flow_response::Data::DeletedFlowId(flow_id) + } + rails_flow_response::Data::Flows(flows) => { + gateway_flow_response::Data::Flows(flows) + } + }), + } + } + + fn empty_push_response() -> tonic::Response { + Response::from_parts(MetadataMap::new(), FlowPushResponse {}, Extensions::new()) + } + + fn extract_flow_response(request: tonic::Request) -> Option { + request.into_inner().response + } +} + +#[tonic::async_trait] +impl FlowService for SagittariusFlowService { + type UpdateStream = FlowUpdateStream; + + // Aquila owns the long-lived flow stream, so this method starts the bridge + // between Rails' initial state and later queued Sagittarius pushes. + async fn update( + &self, + _request: tonic::Request, + ) -> Result, tonic::Status> { + let client = self.client.clone(); + // A second Aquila stream would compete for the same flow updates and make + // delivery semantics unclear, so reject it at connection time. + let queued_updates = Arc::clone(&self.stream_rx) + .try_lock_owned() + .map_err(|_| Status::already_exists("Aquila flow stream is already connected"))?; + let (response_tx, response_rx) = mpsc::channel(FLOW_QUEUE_CAPACITY); + + tokio::spawn(Self::run_update_stream(client, queued_updates, response_tx)); + + Ok(Response::new(Box::pin(ReceiverStream::new(response_rx)))) + } + + // Sagittarius only needs an acknowledgment that the flow update was accepted + // into the bridge. Actual delivery happens through Aquila's stream. + async fn push( + &self, + request: tonic::Request, + ) -> Result, tonic::Status> { + let Some(flow_response) = Self::extract_flow_response(request) else { + return Ok(Self::empty_push_response()); + }; + + if let Err(err) = self.stream_tx.send(flow_response).await { + let error = format!("{:?}", err); + log::error!("{}", &error); + return Err(Status::internal(error)); + } + + log::info!("Received flow update request, will proxy request to Aquila."); + Ok(Self::empty_push_response()) + } +} diff --git a/gateway/src/server/mod.rs b/gateway/src/server/mod.rs new file mode 100644 index 000000000..27f86244e --- /dev/null +++ b/gateway/src/server/mod.rs @@ -0,0 +1,4 @@ +pub mod execution_service_server; +pub mod flow_service_server; +pub mod module_service_server; +pub mod runtime_status_service_server; diff --git a/gateway/src/server/module_service_server.rs b/gateway/src/server/module_service_server.rs new file mode 100644 index 000000000..ab8ca8a9a --- /dev/null +++ b/gateway/src/server/module_service_server.rs @@ -0,0 +1,31 @@ +#![allow(dead_code)] + +use std::pin::Pin; + +use tonic::codegen::tokio_stream::Stream; +use tucana::sagittarius_gateway::module_service_server::ModuleService; +use tucana::sagittarius_gateway::{ModuleUpdateRequest, ModuleUpdateResponse}; + +pub struct SagittariusModuleService {} + +type ModuleConfigurationsStream = + Pin> + Send + 'static>>; + +#[tonic::async_trait] +impl ModuleService for SagittariusModuleService { + async fn update( + &self, + _request: tonic::Request, + ) -> Result, tonic::Status> { + todo!() + } + + type ConfigurationsStream = ModuleConfigurationsStream; + + async fn configurations( + &self, + _request: tonic::Request, + ) -> Result, tonic::Status> { + todo!() + } +} diff --git a/gateway/src/server/runtime_status_service_server.rs b/gateway/src/server/runtime_status_service_server.rs new file mode 100644 index 000000000..6b39c87f9 --- /dev/null +++ b/gateway/src/server/runtime_status_service_server.rs @@ -0,0 +1,44 @@ +#![allow(dead_code)] + +use std::sync::Arc; +use tokio::sync::Mutex; +use tucana::sagittarius_gateway::runtime_status_service_server::RuntimeStatusService; +use tucana::sagittarius_gateway::{RuntimeStatusUpdateRequest, RuntimeStatusUpdateResponse}; + +use crate::client::runtime_status_service_client::SagittariusRailsRuntimeStatusServiceClient; + +pub struct SagittariusRuntimeStatusService { + client: Arc>, +} + +#[tonic::async_trait] +impl RuntimeStatusService for SagittariusRuntimeStatusService { + async fn update( + &self, + request: tonic::Request, + ) -> Result, tonic::Status> { + let status_request = convert_status_update_request(request); + + let response = { + let mut client_lock = self.client.lock().await; + client_lock.update(status_request).await + }?; + + let status_response = response.into_inner(); + + Ok(tonic::Response::new(RuntimeStatusUpdateResponse { + success: status_response.success, + error: status_response.error, + })) + } +} + +fn convert_status_update_request( + request: tonic::Request, +) -> tucana::sagittarius_rails::RuntimeStatusUpdateRequest { + let status_request = request.into_inner(); + + tucana::sagittarius_rails::RuntimeStatusUpdateRequest { + status: status_request.status, + } +}