-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add serving /network and /escrow subgraphs back in
- Loading branch information
Showing
5 changed files
with
126 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023-, GraphOps and Semiotic Labs. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use axum::{body::Bytes, http::HeaderMap, response::IntoResponse, Extension}; | ||
use tracing::warn; | ||
|
||
use crate::subgraph_client::SubgraphClient; | ||
|
||
use super::{indexer_service::IndexerServiceError, IndexerServiceImpl}; | ||
|
||
#[autometrics::autometrics] | ||
pub async fn static_subgraph_request_handler<I>( | ||
Extension(subgraph_client): Extension<&'static SubgraphClient>, | ||
Extension(required_auth_token): Extension<Option<String>>, | ||
headers: HeaderMap, | ||
body: Bytes, | ||
) -> Result<impl IntoResponse, IndexerServiceError<I::Error>> | ||
where | ||
I: IndexerServiceImpl + Sync + Send + 'static, | ||
{ | ||
if let Some(required_auth_token) = required_auth_token { | ||
let authorization = headers | ||
.get("authorization") | ||
.map(|value| value.to_str()) | ||
.transpose() | ||
.map_err(|_| IndexerServiceError::Unauthorized)? | ||
.ok_or_else(|| IndexerServiceError::Unauthorized)? | ||
.trim_start_matches("Bearer "); | ||
|
||
if authorization != required_auth_token { | ||
return Err(IndexerServiceError::Unauthorized); | ||
} | ||
} | ||
|
||
let response = subgraph_client | ||
.query_raw(body) | ||
.await | ||
.map_err(|e| IndexerServiceError::FailedToQueryStaticSubgraph(e))?; | ||
|
||
Ok(( | ||
response.status(), | ||
response.headers().to_owned(), | ||
response | ||
.text() | ||
.await | ||
.map_err(|e| { | ||
warn!("Failed to read response body: {}", e); | ||
e | ||
}) | ||
.map_err(|e| IndexerServiceError::FailedToQueryStaticSubgraph(e.into()))?, | ||
)) | ||
} |
This file contains 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