agent_api/
agent.rs

1// This file is @generated by prost-build.
2#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
3pub struct RequestActiveConnections {
4    #[prost(string, optional, tag = "2")]
5    pub pod_ip: ::core::option::Option<::prost::alloc::string::String>,
6}
7/// TODO: the complete Response will be able to return all the context below
8///
9/// * "Event Id: {} Protocol: {:?} SRC: {}:{} -> DST: {}:{}",
10/// * event_id, proto, src, src_port, dst, dst_port
11#[derive(Clone, PartialEq, ::prost::Message)]
12pub struct ActiveConnectionResponse {
13    #[prost(string, tag = "1")]
14    pub status: ::prost::alloc::string::String,
15    /// for simplicity right now we only return event_id and src
16    #[prost(map = "string, string", tag = "2")]
17    pub events: ::std::collections::HashMap<
18        ::prost::alloc::string::String,
19        ::prost::alloc::string::String,
20    >,
21}
22#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
23pub struct AddIpToBlocklistRequest {
24    #[prost(string, optional, tag = "1")]
25    pub ip: ::core::option::Option<::prost::alloc::string::String>,
26}
27#[derive(Clone, PartialEq, ::prost::Message)]
28pub struct BlocklistResponse {
29    #[prost(string, tag = "1")]
30    pub status: ::prost::alloc::string::String,
31    #[prost(map = "string, string", tag = "2")]
32    pub events: ::std::collections::HashMap<
33        ::prost::alloc::string::String,
34        ::prost::alloc::string::String,
35    >,
36}
37/// Generated client implementations.
38pub mod agent_client {
39    #![allow(
40        unused_variables,
41        dead_code,
42        missing_docs,
43        clippy::wildcard_imports,
44        clippy::let_unit_value,
45    )]
46    use tonic::codegen::*;
47    use tonic::codegen::http::Uri;
48    /// declare agent api
49    #[derive(Debug, Clone)]
50    pub struct AgentClient<T> {
51        inner: tonic::client::Grpc<T>,
52    }
53    impl AgentClient<tonic::transport::Channel> {
54        /// Attempt to create a new client by connecting to a given endpoint.
55        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
56        where
57            D: TryInto<tonic::transport::Endpoint>,
58            D::Error: Into<StdError>,
59        {
60            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
61            Ok(Self::new(conn))
62        }
63    }
64    impl<T> AgentClient<T>
65    where
66        T: tonic::client::GrpcService<tonic::body::Body>,
67        T::Error: Into<StdError>,
68        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
69        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
70    {
71        pub fn new(inner: T) -> Self {
72            let inner = tonic::client::Grpc::new(inner);
73            Self { inner }
74        }
75        pub fn with_origin(inner: T, origin: Uri) -> Self {
76            let inner = tonic::client::Grpc::with_origin(inner, origin);
77            Self { inner }
78        }
79        pub fn with_interceptor<F>(
80            inner: T,
81            interceptor: F,
82        ) -> AgentClient<InterceptedService<T, F>>
83        where
84            F: tonic::service::Interceptor,
85            T::ResponseBody: Default,
86            T: tonic::codegen::Service<
87                http::Request<tonic::body::Body>,
88                Response = http::Response<
89                    <T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
90                >,
91            >,
92            <T as tonic::codegen::Service<
93                http::Request<tonic::body::Body>,
94            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
95        {
96            AgentClient::new(InterceptedService::new(inner, interceptor))
97        }
98        /// Compress requests with the given encoding.
99        ///
100        /// This requires the server to support it otherwise it might respond with an
101        /// error.
102        #[must_use]
103        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
104            self.inner = self.inner.send_compressed(encoding);
105            self
106        }
107        /// Enable decompressing responses.
108        #[must_use]
109        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
110            self.inner = self.inner.accept_compressed(encoding);
111            self
112        }
113        /// Limits the maximum size of a decoded message.
114        ///
115        /// Default: `4MB`
116        #[must_use]
117        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
118            self.inner = self.inner.max_decoding_message_size(limit);
119            self
120        }
121        /// Limits the maximum size of an encoded message.
122        ///
123        /// Default: `usize::MAX`
124        #[must_use]
125        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
126            self.inner = self.inner.max_encoding_message_size(limit);
127            self
128        }
129        /// active connections endpoint
130        pub async fn active_connections(
131            &mut self,
132            request: impl tonic::IntoRequest<super::RequestActiveConnections>,
133        ) -> std::result::Result<
134            tonic::Response<super::ActiveConnectionResponse>,
135            tonic::Status,
136        > {
137            self.inner
138                .ready()
139                .await
140                .map_err(|e| {
141                    tonic::Status::unknown(
142                        format!("Service was not ready: {}", e.into()),
143                    )
144                })?;
145            let codec = tonic_prost::ProstCodec::default();
146            let path = http::uri::PathAndQuery::from_static(
147                "/agent.Agent/ActiveConnections",
148            );
149            let mut req = request.into_request();
150            req.extensions_mut()
151                .insert(GrpcMethod::new("agent.Agent", "ActiveConnections"));
152            self.inner.unary(req, path, codec).await
153        }
154        /// create blocklist endpoint
155        pub async fn add_ip_to_blocklist(
156            &mut self,
157            request: impl tonic::IntoRequest<super::AddIpToBlocklistRequest>,
158        ) -> std::result::Result<
159            tonic::Response<super::BlocklistResponse>,
160            tonic::Status,
161        > {
162            self.inner
163                .ready()
164                .await
165                .map_err(|e| {
166                    tonic::Status::unknown(
167                        format!("Service was not ready: {}", e.into()),
168                    )
169                })?;
170            let codec = tonic_prost::ProstCodec::default();
171            let path = http::uri::PathAndQuery::from_static(
172                "/agent.Agent/AddIpToBlocklist",
173            );
174            let mut req = request.into_request();
175            req.extensions_mut()
176                .insert(GrpcMethod::new("agent.Agent", "AddIpToBlocklist"));
177            self.inner.unary(req, path, codec).await
178        }
179        pub async fn check_blocklist(
180            &mut self,
181            request: impl tonic::IntoRequest<()>,
182        ) -> std::result::Result<
183            tonic::Response<super::BlocklistResponse>,
184            tonic::Status,
185        > {
186            self.inner
187                .ready()
188                .await
189                .map_err(|e| {
190                    tonic::Status::unknown(
191                        format!("Service was not ready: {}", e.into()),
192                    )
193                })?;
194            let codec = tonic_prost::ProstCodec::default();
195            let path = http::uri::PathAndQuery::from_static(
196                "/agent.Agent/CheckBlocklist",
197            );
198            let mut req = request.into_request();
199            req.extensions_mut()
200                .insert(GrpcMethod::new("agent.Agent", "CheckBlocklist"));
201            self.inner.unary(req, path, codec).await
202        }
203    }
204}
205/// Generated server implementations.
206pub mod agent_server {
207    #![allow(
208        unused_variables,
209        dead_code,
210        missing_docs,
211        clippy::wildcard_imports,
212        clippy::let_unit_value,
213    )]
214    use tonic::codegen::*;
215    /// Generated trait containing gRPC methods that should be implemented for use with AgentServer.
216    #[async_trait]
217    pub trait Agent: std::marker::Send + std::marker::Sync + 'static {
218        /// active connections endpoint
219        async fn active_connections(
220            &self,
221            request: tonic::Request<super::RequestActiveConnections>,
222        ) -> std::result::Result<
223            tonic::Response<super::ActiveConnectionResponse>,
224            tonic::Status,
225        >;
226        /// create blocklist endpoint
227        async fn add_ip_to_blocklist(
228            &self,
229            request: tonic::Request<super::AddIpToBlocklistRequest>,
230        ) -> std::result::Result<
231            tonic::Response<super::BlocklistResponse>,
232            tonic::Status,
233        >;
234        async fn check_blocklist(
235            &self,
236            request: tonic::Request<()>,
237        ) -> std::result::Result<
238            tonic::Response<super::BlocklistResponse>,
239            tonic::Status,
240        >;
241    }
242    /// declare agent api
243    #[derive(Debug)]
244    pub struct AgentServer<T> {
245        inner: Arc<T>,
246        accept_compression_encodings: EnabledCompressionEncodings,
247        send_compression_encodings: EnabledCompressionEncodings,
248        max_decoding_message_size: Option<usize>,
249        max_encoding_message_size: Option<usize>,
250    }
251    impl<T> AgentServer<T> {
252        pub fn new(inner: T) -> Self {
253            Self::from_arc(Arc::new(inner))
254        }
255        pub fn from_arc(inner: Arc<T>) -> Self {
256            Self {
257                inner,
258                accept_compression_encodings: Default::default(),
259                send_compression_encodings: Default::default(),
260                max_decoding_message_size: None,
261                max_encoding_message_size: None,
262            }
263        }
264        pub fn with_interceptor<F>(
265            inner: T,
266            interceptor: F,
267        ) -> InterceptedService<Self, F>
268        where
269            F: tonic::service::Interceptor,
270        {
271            InterceptedService::new(Self::new(inner), interceptor)
272        }
273        /// Enable decompressing requests with the given encoding.
274        #[must_use]
275        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
276            self.accept_compression_encodings.enable(encoding);
277            self
278        }
279        /// Compress responses with the given encoding, if the client supports it.
280        #[must_use]
281        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
282            self.send_compression_encodings.enable(encoding);
283            self
284        }
285        /// Limits the maximum size of a decoded message.
286        ///
287        /// Default: `4MB`
288        #[must_use]
289        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
290            self.max_decoding_message_size = Some(limit);
291            self
292        }
293        /// Limits the maximum size of an encoded message.
294        ///
295        /// Default: `usize::MAX`
296        #[must_use]
297        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
298            self.max_encoding_message_size = Some(limit);
299            self
300        }
301    }
302    impl<T, B> tonic::codegen::Service<http::Request<B>> for AgentServer<T>
303    where
304        T: Agent,
305        B: Body + std::marker::Send + 'static,
306        B::Error: Into<StdError> + std::marker::Send + 'static,
307    {
308        type Response = http::Response<tonic::body::Body>;
309        type Error = std::convert::Infallible;
310        type Future = BoxFuture<Self::Response, Self::Error>;
311        fn poll_ready(
312            &mut self,
313            _cx: &mut Context<'_>,
314        ) -> Poll<std::result::Result<(), Self::Error>> {
315            Poll::Ready(Ok(()))
316        }
317        fn call(&mut self, req: http::Request<B>) -> Self::Future {
318            match req.uri().path() {
319                "/agent.Agent/ActiveConnections" => {
320                    #[allow(non_camel_case_types)]
321                    struct ActiveConnectionsSvc<T: Agent>(pub Arc<T>);
322                    impl<
323                        T: Agent,
324                    > tonic::server::UnaryService<super::RequestActiveConnections>
325                    for ActiveConnectionsSvc<T> {
326                        type Response = super::ActiveConnectionResponse;
327                        type Future = BoxFuture<
328                            tonic::Response<Self::Response>,
329                            tonic::Status,
330                        >;
331                        fn call(
332                            &mut self,
333                            request: tonic::Request<super::RequestActiveConnections>,
334                        ) -> Self::Future {
335                            let inner = Arc::clone(&self.0);
336                            let fut = async move {
337                                <T as Agent>::active_connections(&inner, request).await
338                            };
339                            Box::pin(fut)
340                        }
341                    }
342                    let accept_compression_encodings = self.accept_compression_encodings;
343                    let send_compression_encodings = self.send_compression_encodings;
344                    let max_decoding_message_size = self.max_decoding_message_size;
345                    let max_encoding_message_size = self.max_encoding_message_size;
346                    let inner = self.inner.clone();
347                    let fut = async move {
348                        let method = ActiveConnectionsSvc(inner);
349                        let codec = tonic_prost::ProstCodec::default();
350                        let mut grpc = tonic::server::Grpc::new(codec)
351                            .apply_compression_config(
352                                accept_compression_encodings,
353                                send_compression_encodings,
354                            )
355                            .apply_max_message_size_config(
356                                max_decoding_message_size,
357                                max_encoding_message_size,
358                            );
359                        let res = grpc.unary(method, req).await;
360                        Ok(res)
361                    };
362                    Box::pin(fut)
363                }
364                "/agent.Agent/AddIpToBlocklist" => {
365                    #[allow(non_camel_case_types)]
366                    struct AddIpToBlocklistSvc<T: Agent>(pub Arc<T>);
367                    impl<
368                        T: Agent,
369                    > tonic::server::UnaryService<super::AddIpToBlocklistRequest>
370                    for AddIpToBlocklistSvc<T> {
371                        type Response = super::BlocklistResponse;
372                        type Future = BoxFuture<
373                            tonic::Response<Self::Response>,
374                            tonic::Status,
375                        >;
376                        fn call(
377                            &mut self,
378                            request: tonic::Request<super::AddIpToBlocklistRequest>,
379                        ) -> Self::Future {
380                            let inner = Arc::clone(&self.0);
381                            let fut = async move {
382                                <T as Agent>::add_ip_to_blocklist(&inner, request).await
383                            };
384                            Box::pin(fut)
385                        }
386                    }
387                    let accept_compression_encodings = self.accept_compression_encodings;
388                    let send_compression_encodings = self.send_compression_encodings;
389                    let max_decoding_message_size = self.max_decoding_message_size;
390                    let max_encoding_message_size = self.max_encoding_message_size;
391                    let inner = self.inner.clone();
392                    let fut = async move {
393                        let method = AddIpToBlocklistSvc(inner);
394                        let codec = tonic_prost::ProstCodec::default();
395                        let mut grpc = tonic::server::Grpc::new(codec)
396                            .apply_compression_config(
397                                accept_compression_encodings,
398                                send_compression_encodings,
399                            )
400                            .apply_max_message_size_config(
401                                max_decoding_message_size,
402                                max_encoding_message_size,
403                            );
404                        let res = grpc.unary(method, req).await;
405                        Ok(res)
406                    };
407                    Box::pin(fut)
408                }
409                "/agent.Agent/CheckBlocklist" => {
410                    #[allow(non_camel_case_types)]
411                    struct CheckBlocklistSvc<T: Agent>(pub Arc<T>);
412                    impl<T: Agent> tonic::server::UnaryService<()>
413                    for CheckBlocklistSvc<T> {
414                        type Response = super::BlocklistResponse;
415                        type Future = BoxFuture<
416                            tonic::Response<Self::Response>,
417                            tonic::Status,
418                        >;
419                        fn call(&mut self, request: tonic::Request<()>) -> Self::Future {
420                            let inner = Arc::clone(&self.0);
421                            let fut = async move {
422                                <T as Agent>::check_blocklist(&inner, request).await
423                            };
424                            Box::pin(fut)
425                        }
426                    }
427                    let accept_compression_encodings = self.accept_compression_encodings;
428                    let send_compression_encodings = self.send_compression_encodings;
429                    let max_decoding_message_size = self.max_decoding_message_size;
430                    let max_encoding_message_size = self.max_encoding_message_size;
431                    let inner = self.inner.clone();
432                    let fut = async move {
433                        let method = CheckBlocklistSvc(inner);
434                        let codec = tonic_prost::ProstCodec::default();
435                        let mut grpc = tonic::server::Grpc::new(codec)
436                            .apply_compression_config(
437                                accept_compression_encodings,
438                                send_compression_encodings,
439                            )
440                            .apply_max_message_size_config(
441                                max_decoding_message_size,
442                                max_encoding_message_size,
443                            );
444                        let res = grpc.unary(method, req).await;
445                        Ok(res)
446                    };
447                    Box::pin(fut)
448                }
449                _ => {
450                    Box::pin(async move {
451                        let mut response = http::Response::new(
452                            tonic::body::Body::default(),
453                        );
454                        let headers = response.headers_mut();
455                        headers
456                            .insert(
457                                tonic::Status::GRPC_STATUS,
458                                (tonic::Code::Unimplemented as i32).into(),
459                            );
460                        headers
461                            .insert(
462                                http::header::CONTENT_TYPE,
463                                tonic::metadata::GRPC_CONTENT_TYPE,
464                            );
465                        Ok(response)
466                    })
467                }
468            }
469        }
470    }
471    impl<T> Clone for AgentServer<T> {
472        fn clone(&self) -> Self {
473            let inner = self.inner.clone();
474            Self {
475                inner,
476                accept_compression_encodings: self.accept_compression_encodings,
477                send_compression_encodings: self.send_compression_encodings,
478                max_decoding_message_size: self.max_decoding_message_size,
479                max_encoding_message_size: self.max_encoding_message_size,
480            }
481        }
482    }
483    /// Generated gRPC service name
484    pub const SERVICE_NAME: &str = "agent.Agent";
485    impl<T> tonic::server::NamedService for AgentServer<T> {
486        const NAME: &'static str = SERVICE_NAME;
487    }
488}