Skip to content

Commit 2f1adce

Browse files
committed
refactor: add validate request layer to escrow
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 7cae066 commit 2f1adce

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ uuid.workspace = true
3939
alloy.workspace = true
4040
tower_governor = "0.4.0"
4141
tower-http = { version = "0.5.2", features = [
42+
"auth",
4243
"cors",
4344
"normalize-path",
4445
"trace",

crates/service/src/service/indexer_service.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ use tokio::net::TcpListener;
3636
use tokio::signal;
3737
use tokio::sync::watch::Receiver;
3838
use tower_governor::{governor::GovernorConfigBuilder, GovernorLayer};
39+
use tower_http::validate_request::ValidateRequestHeaderLayer;
3940
use tower_http::{cors, cors::CorsLayer, normalize_path::NormalizePath, trace::TraceLayer};
41+
use tracing::warn;
4042
use tracing::{error, info, info_span};
4143

4244
use crate::routes::health;
@@ -414,12 +416,21 @@ impl IndexerService {
414416
}
415417

416418
if options.config.service.serve_escrow_subgraph {
417-
info!("Serving escrow subgraph at /escrow");
418-
419-
misc_routes = misc_routes
420-
.route("/escrow", post(static_subgraph_request_handler))
421-
.route_layer(Extension(escrow_subgraph))
422-
.route_layer(static_subgraph_rate_limiter);
419+
if let Some(free_auth_token) = &options.config.service.serve_auth_token {
420+
info!("Serving escrow subgraph at /escrow");
421+
422+
let auth_layer = ValidateRequestHeaderLayer::bearer(free_auth_token);
423+
424+
misc_routes = misc_routes
425+
.route(
426+
"/escrow",
427+
post(static_subgraph_request_handler).route_layer(auth_layer),
428+
)
429+
.route_layer(Extension(escrow_subgraph))
430+
.route_layer(static_subgraph_rate_limiter);
431+
} else {
432+
warn!("`serve_escrow_subgraph` is enabled but no `serve_auth_token` provided. Disabling it.");
433+
}
423434
}
424435

425436
misc_routes = misc_routes.with_state(state.clone());

0 commit comments

Comments
 (0)