Skip to content

Commit fcb1f17

Browse files
committed
refactor: remove auth check inside route
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 524c9a3 commit fcb1f17

File tree

1 file changed

+2
-28
lines changed

1 file changed

+2
-28
lines changed

crates/service/src/routes/static_subgraph.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use axum::{body::Bytes, http::HeaderMap, response::IntoResponse, Extension, Json};
4+
use axum::{body::Bytes, response::IntoResponse, Extension, Json};
55
use reqwest::StatusCode;
66
use serde_json::json;
77
use tracing::warn;
@@ -11,24 +11,8 @@ use indexer_common::SubgraphClient;
1111
#[autometrics::autometrics]
1212
pub async fn static_subgraph_request_handler(
1313
Extension(subgraph_client): Extension<&'static SubgraphClient>,
14-
Extension(required_auth_token): Extension<Option<String>>,
15-
headers: HeaderMap,
1614
body: Bytes,
1715
) -> Result<impl IntoResponse, StaticSubgraphError> {
18-
if let Some(required_auth_token) = required_auth_token {
19-
let authorization = headers
20-
.get("authorization")
21-
.map(|value| value.to_str())
22-
.transpose()
23-
.map_err(|_| StaticSubgraphError::Unauthorized)?
24-
.ok_or_else(|| StaticSubgraphError::Unauthorized)?
25-
.trim_start_matches("Bearer ");
26-
27-
if authorization != required_auth_token {
28-
return Err(StaticSubgraphError::Unauthorized);
29-
}
30-
}
31-
3216
let response = subgraph_client.query_raw(body).await?;
3317

3418
Ok((
@@ -42,9 +26,6 @@ pub async fn static_subgraph_request_handler(
4226

4327
#[derive(Debug, thiserror::Error)]
4428
pub enum StaticSubgraphError {
45-
#[error("No valid receipt or free query auth token provided")]
46-
Unauthorized,
47-
4829
#[error("Failed to query subgraph: {0}")]
4930
FailedToQuery(#[from] anyhow::Error),
5031

@@ -54,16 +35,9 @@ pub enum StaticSubgraphError {
5435

5536
impl IntoResponse for StaticSubgraphError {
5637
fn into_response(self) -> axum::response::Response {
57-
let status = match self {
58-
StaticSubgraphError::Unauthorized => StatusCode::UNAUTHORIZED,
59-
StaticSubgraphError::FailedToQuery(_) | StaticSubgraphError::FailedToParse(_) => {
60-
StatusCode::INTERNAL_SERVER_ERROR
61-
}
62-
};
63-
6438
tracing::error!(%self, "StaticSubgraphError occoured.");
6539
(
66-
status,
40+
StatusCode::INTERNAL_SERVER_ERROR,
6741
Json(json! {{
6842
"message": self.to_string(),
6943
}}),

0 commit comments

Comments
 (0)