Skip to main content

aura_agent/runtime/effects/
guard.rs

1use super::AuraEffectSystem;
2use async_trait::async_trait;
3use aura_core::types::scope::{AuthorizationOp, ResourceScope};
4use aura_core::AuthorityId;
5use aura_protocol::effects::{AuthorizationEffects, LeakageEffects};
6
7// AuthorizationEffects implementation delegating to the handler
8#[async_trait]
9impl AuthorizationEffects for AuraEffectSystem {
10    async fn verify_capability(
11        &self,
12        capabilities: &aura_core::Cap,
13        operation: AuthorizationOp,
14        scope: &ResourceScope,
15    ) -> Result<bool, aura_core::effects::AuthorizationError> {
16        self.authorization_handler
17            .verify_capability(capabilities, operation, scope)
18            .await
19    }
20
21    async fn delegate_capabilities(
22        &self,
23        source_capabilities: &aura_core::Cap,
24        requested_capabilities: &aura_core::Cap,
25        target_authority: &AuthorityId,
26    ) -> Result<aura_core::Cap, aura_core::effects::AuthorizationError> {
27        self.authorization_handler
28            .delegate_capabilities(
29                source_capabilities,
30                requested_capabilities,
31                target_authority,
32            )
33            .await
34    }
35}
36
37// LeakageEffects implementation delegating to the handler
38#[async_trait]
39impl LeakageEffects for AuraEffectSystem {
40    async fn record_leakage(
41        &self,
42        event: aura_core::effects::LeakageEvent,
43    ) -> aura_core::Result<()> {
44        self.leakage_handler.record_leakage(event).await
45    }
46
47    async fn get_leakage_budget(
48        &self,
49        context_id: aura_core::types::identifiers::ContextId,
50    ) -> aura_core::Result<aura_core::effects::LeakageBudget> {
51        self.leakage_handler.get_leakage_budget(context_id).await
52    }
53
54    async fn check_leakage_budget(
55        &self,
56        context_id: aura_core::types::identifiers::ContextId,
57        observer: aura_core::effects::ObserverClass,
58        amount: u64,
59    ) -> aura_core::Result<bool> {
60        self.leakage_handler
61            .check_leakage_budget(context_id, observer, amount)
62            .await
63    }
64
65    async fn get_leakage_history(
66        &self,
67        context_id: aura_core::types::identifiers::ContextId,
68        since_timestamp: Option<&aura_core::time::PhysicalTime>,
69    ) -> aura_core::Result<Vec<aura_core::effects::LeakageEvent>> {
70        self.leakage_handler
71            .get_leakage_history(context_id, since_timestamp)
72            .await
73    }
74}