Skip to main content

relay_core_runtime/services/
intercept.rs

1use async_trait::async_trait;
2use tokio::sync::oneshot;
3use relay_core_api::modification::FlowModification;
4use relay_core_lib::InterceptionResult;
5use crate::audit::AuditActor;
6use crate::{CoreInterceptSnapshot, CoreState};
7
8#[async_trait]
9pub trait InterceptService: Send + Sync {
10    async fn register_intercept(&self, key: String, tx: oneshot::Sender<InterceptionResult>);
11    async fn resolve_intercept_with_modifications_from(
12        &self,
13        actor: AuditActor,
14        key: String,
15        action: &str,
16        mods: Option<FlowModification>,
17    ) -> Result<(), String>;
18    async fn is_flow_intercepted(&self, flow_id: String) -> bool;
19    async fn intercept_snapshot(&self) -> CoreInterceptSnapshot;
20}
21
22#[async_trait]
23impl InterceptService for CoreState {
24    async fn register_intercept(&self, key: String, tx: oneshot::Sender<InterceptionResult>) {
25        CoreState::register_intercept(self, key, tx).await
26    }
27
28    async fn resolve_intercept_with_modifications_from(
29        &self,
30        actor: AuditActor,
31        key: String,
32        action: &str,
33        mods: Option<FlowModification>,
34    ) -> Result<(), String> {
35        CoreState::resolve_intercept_with_modifications_from(self, actor, key, action, mods).await
36    }
37
38    async fn is_flow_intercepted(&self, flow_id: String) -> bool {
39        CoreState::is_flow_intercepted(self, flow_id).await
40    }
41
42    async fn intercept_snapshot(&self) -> CoreInterceptSnapshot {
43        CoreState::intercept_snapshot(self).await
44    }
45}