brainos_grpcadapter/
state.rs1use std::sync::Arc;
6
7use tonic::Request;
8
9use crate::auth::resolve_principal_from_metadata;
10
11pub struct MemoryServiceImpl {
13 pub(crate) processor: Arc<signal::SignalProcessor>,
14 pub(crate) api_keys: Arc<Vec<brain::ApiKeyConfig>>,
15}
16
17impl MemoryServiceImpl {
18 pub fn new(processor: Arc<signal::SignalProcessor>) -> Self {
19 let api_keys = Arc::new(processor.config().access.api_keys.clone());
20 Self {
21 processor,
22 api_keys,
23 }
24 }
25
26 pub(crate) async fn resolve_principal<T>(
29 &self,
30 req: &Request<T>,
31 ) -> Option<identity::Principal> {
32 resolve_principal_from_metadata(req, &self.api_keys, self.processor.as_ref()).await
33 }
34}
35
36pub struct AgentServiceImpl {
38 pub(crate) processor: Arc<signal::SignalProcessor>,
39 pub(crate) api_keys: Arc<Vec<brain::ApiKeyConfig>>,
40}
41
42impl AgentServiceImpl {
43 pub fn new(processor: Arc<signal::SignalProcessor>) -> Self {
44 let api_keys = Arc::new(processor.config().access.api_keys.clone());
45 Self {
46 processor,
47 api_keys,
48 }
49 }
50
51 pub(crate) async fn resolve_principal<T>(
52 &self,
53 req: &Request<T>,
54 ) -> Option<identity::Principal> {
55 resolve_principal_from_metadata(req, &self.api_keys, self.processor.as_ref()).await
56 }
57}