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