feat(api-gateway): add API gateway and request router contract - #318
Open
BrayanMQ wants to merge 6 commits into
Open
feat(api-gateway): add API gateway and request router contract#318BrayanMQ wants to merge 6 commits into
BrayanMQ wants to merge 6 commits into
Conversation
A prior merge left two conflicting closing brackets in the members array, leaving contracts/collateral_lending outside the array and breaking cargo metadata/build for the whole workspace.
New workspace member for the central API gateway module (issue MindFlowInteractive#291).
…th checks, circuit breaker, and request transformation Provides the core logic for the central API gateway: a route table resolving path+method to backend services, JWT/OAuth-style token authentication, a fixed-window rate limiter, structured request logging, a CORS origin allow-list, service health tracking, a Closed/Open/HalfOpen circuit breaker, and path-rewrite/header transformation for outgoing requests. process_request() orchestrates all of these into a single gateway pipeline. Closes MindFlowInteractive#291
Adds integration-level tests through process_request for expired tokens, invalid scope, CORS-allowed origins, rate-limit window reset, and circuit breaker recovery through the HalfOpen state, plus unit tests for the previously untested RouteTable::is_empty and the no-match branch of RequestContext::apply_rewrite. Also resolves two clippy lints (manual_find, len_without_is_empty).
|
@BrayanMQ Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds the central API gateway module described in #291: a Soroban smart-contract library that models request routing, JWT/OAuth-style authentication, rate limiting, request/response logging, CORS handling, health checks, a circuit breaker, and request transformation for the Quest Service ecosystem.
This follows the same pattern established by the
backend_coremodule (#305/#312): pure, testable logic types built onsoroban-sdk, since this repo has no standalone HTTP server — the gateway concepts are modeled as contract-compatible types and pipeline logic that a real contract entrypoint would compose.Time-dependent operations (token expiry, rate-limit windows, circuit breaker timers) take the current ledger timestamp as an explicit
now: u64parameter instead of readingenv.ledger()internally, so a caller readsenv.ledger().timestamp()once and passes it down. This also keeps the module fully unit-testable without thetestutilsfeature, which is currently broken in this workspace due to an unrelateded25519-dalek/rand_coreversion conflict.Changes
contracts/api_gateway(api-gateway) registered as a workspace member:RouteTable/Route: path + method → backend service resolution, with arequires_authflagAuthToken/AuthMiddleware: bearer-token validation (missing / expired / wrong scope / authorized)RateLimitState: fixed-window rate limiter with automatic window resetRequestLogEntry/LogLevel: structured request logs with status-derived severityCorsPolicy: origin allow-list with wildcard (*) supportHealthCheckResult/HealthStatus: per-service health trackingCircuitBreaker/CircuitState: Closed → Open → HalfOpen → Closed state machineTransformRule/RequestContext: path rewriting and header injectionprocess_request: orchestrates all of the above into a single gateway pipeline (CORS → circuit breaker → rate limit → routing → auth)HalfOpen)Cargo.toml: a prior merge left the workspacemembersarray with two conflicting closing brackets, leavingcontracts/collateral_lendingoutside the array and breakingcargo metadata/cargo buildfor the entire workspace. Repaired as part of registering the new crate.Closes
Closes #291
Evidence/Media (screenshots/videos)
This is a backend Rust/Soroban library with no UI, so evidence is test/lint/build output rather than screenshots.
Test run (
cargo test -p api-gateway --lib):Lint (
cargo clippy -p api-gateway --lib --tests): clean, no warnings.Build (
cargo build -p api-gateway --release): succeeds.Workspace sanity (
cargo metadata --no-deps): now resolves cleanly for the entire workspace (previously broken by the pre-existingCargo.tomlbug fixed in this PR).Notes
cargo-tarpaulin/cargo-llvm-cov) is available in this environment (tarpaulin has limited Windows support), so the "100% coverage" acceptance criterion was verified manually by mapping every public function and branch to at least one test, rather than via a generated coverage report. Happy to re-run with tarpaulin in CI if that's preferred.#![no_std]Soroban contract library with no HTTP layer — there's no literal "JWT" to decode. This mirrors how the existingbackend_coremodule (response formatting/compression) models HTTP-adjacent concepts within the constraints of a smart-contract environment.Cargo.tomlfix is a pre-existing bug unrelated to API Gateway and Request Router #291, but it blockedcargo build/cargo testfor the whole workspace, so it had to be fixed to register and test the new crate.