Skip to content

Commit 6365178

Browse files
committed
docs: add documentation to auth middleware
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent fecfc0b commit 6365178

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

crates/service/src/middleware/auth/or.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use axum::http::{Request, Response};
1212
use pin_project::pin_project;
1313
use tower_http::{auth::AsyncAuthorizeRequest, validate_request::ValidateRequest};
1414

15+
/// Extension that allows using a simple .or() function and return an Or struct
1516
pub trait OrExt<T, B, Resp>: Sized {
1617
fn or(self, other: T) -> Or<Self, T, B, Resp>;
1718
}
@@ -32,6 +33,11 @@ where
3233
}
3334
}
3435

36+
/// Or struct capable of implementing a ValidateRequest or an AsyncAuthorizeRequest
37+
///
38+
/// Uses the first parameter to validate the request sync.
39+
/// if it passes the check return the request to pass to the next middleware
40+
/// if it doesn't pass, check the async future returning the result
3541
pub struct Or<T, E, B, Resp>(T, E, PhantomData<fn(B) -> Resp>);
3642

3743
impl<T, E, B, Resp> Clone for Or<T, E, B, Resp>

crates/service/src/middleware/auth/tap.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ use tap_core::{
2121
};
2222
use tower_http::auth::AsyncAuthorizeRequest;
2323

24-
use crate::{error::IndexerServiceError, middleware::metrics::MetricLabels};
24+
use crate::{error::IndexerServiceError, middleware::prometheus_metrics::MetricLabels};
2525

26+
/// Middleware to verify and store TAP receipts
27+
///
28+
/// It also optionally updates a failed receipt metric if Labels are provided
29+
///
30+
/// Requires SignedReceipt, MetricLabels and Arc<Context> extensions
2631
pub fn tap_receipt_authorize<T, B>(
2732
tap_manager: &'static Manager<T>,
2833
failed_receipt_metric: &'static prometheus::CounterVec,
@@ -93,7 +98,7 @@ mod tests {
9398
use crate::{
9499
middleware::{
95100
auth::tap_receipt_authorize,
96-
metrics::{MetricLabelProvider, MetricLabels},
101+
prometheus_metrics::{MetricLabelProvider, MetricLabels},
97102
},
98103
tap::IndexerTapContext,
99104
};

crates/service/src/middleware/inject_context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ use thegraph_core::DeploymentId;
2020

2121
use crate::{error::IndexerServiceError, tap::AgoraQuery};
2222

23+
/// Graphql query body to be decoded and passed to agora context
2324
#[derive(Debug, serde::Deserialize, serde::Serialize)]
2425
struct QueryBody {
2526
query: String,
2627
variables: Option<Box<RawValue>>,
2728
}
2829

30+
/// Injects tap context in the extensions to be used by tap_receipt_authorize
2931
pub async fn context_middleware(
3032
mut request: Request,
3133
next: Next,

0 commit comments

Comments
 (0)