Skip to content

Commit 47a0bf3

Browse files
committed
refactor: add inject attestation signer
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 6365178 commit 47a0bf3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

crates/service/src/middleware.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
pub mod auth;
55
mod inject_allocation;
6+
mod inject_attestation_signer;
67
mod inject_context;
78
mod inject_deployment;
89
mod inject_labels;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use alloy::primitives::Address;
5+
use axum::{
6+
extract::{Request, State},
7+
middleware::Next,
8+
response::Response,
9+
};
10+
use indexer_attestation::AttestationSigner;
11+
use std::collections::HashMap;
12+
use tokio::sync::watch;
13+
14+
use super::Allocation;
15+
16+
#[derive(Clone)]
17+
pub struct AttestationState {
18+
pub attestation_signers: watch::Receiver<HashMap<Address, AttestationSigner>>,
19+
}
20+
21+
/// injects the attestation signer to be used in the attestation
22+
///
23+
/// Needs Allocation Extension
24+
pub async fn signer_middleware(
25+
State(state): State<AttestationState>,
26+
mut request: Request,
27+
next: Next,
28+
) -> Response {
29+
if let Some(Allocation(allocation_id)) = request.extensions().get::<Allocation>() {
30+
if let Some(signer) = state.attestation_signers.borrow().get(allocation_id) {
31+
request.extensions_mut().insert(signer.clone());
32+
}
33+
}
34+
35+
next.run(request).await
36+
}

0 commit comments

Comments
 (0)