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/// Generated client implementations.
23pub mod agent_client {
24    #![allow(
25        unused_variables,
26        dead_code,
27        missing_docs,
28        clippy::wildcard_imports,
29        clippy::let_unit_value,
30    )]
31    use tonic::codegen::*;
32    use tonic::codegen::http::Uri;
33    /// declare agent api
34    #[derive(Debug, Clone)]
35    pub struct AgentClient<T> {
36        inner: tonic::client::Grpc<T>,
37    }
38    impl AgentClient<tonic::transport::Channel> {
39        /// Attempt to create a new client by connecting to a given endpoint.
40        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
41        where
42            D: TryInto<tonic::transport::Endpoint>,
43            D::Error: Into<StdError>,
44        {
45            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
46            Ok(Self::new(conn))
47        }
48    }
49    impl<T> AgentClient<T>
50    where
51        T: tonic::client::GrpcService<tonic::body::Body>,
52        T::Error: Into<StdError>,
53        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
54        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
55    {
56        pub fn new(inner: T) -> Self {
57            let inner = tonic::client::Grpc::new(inner);
58            Self { inner }
59        }
60        pub fn with_origin(inner: T, origin: Uri) -> Self {
61            let inner = tonic::client::Grpc::with_origin(inner, origin);
62            Self { inner }
63        }
64        pub fn with_interceptor<F>(
65            inner: T,
66            interceptor: F,
67        ) -> AgentClient<InterceptedService<T, F>>
68        where
69            F: tonic::service::Interceptor,
70            T::ResponseBody: Default,
71            T: tonic::codegen::Service<
72                http::Request<tonic::body::Body>,
73                Response = http::Response<
74                    <T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
75                >,
76            >,
77            <T as tonic::codegen::Service<
78                http::Request<tonic::body::Body>,
79            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
80        {
81            AgentClient::new(InterceptedService::new(inner, interceptor))
82        }
83        /// Compress requests with the given encoding.
84        ///
85        /// This requires the server to support it otherwise it might respond with an
86        /// error.
87        #[must_use]
88        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
89            self.inner = self.inner.send_compressed(encoding);
90            self
91        }
92        /// Enable decompressing responses.
93        #[must_use]
94        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
95            self.inner = self.inner.accept_compressed(encoding);
96            self
97        }
98        /// Limits the maximum size of a decoded message.
99        ///
100        /// Default: `4MB`
101        #[must_use]
102        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
103            self.inner = self.inner.max_decoding_message_size(limit);
104            self
105        }
106        /// Limits the maximum size of an encoded message.
107        ///
108        /// Default: `usize::MAX`
109        #[must_use]
110        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
111            self.inner = self.inner.max_encoding_message_size(limit);
112            self
113        }
114        /// active connections endpoint
115        pub async fn active_connections(
116            &mut self,
117            request: impl tonic::IntoRequest<super::RequestActiveConnections>,
118        ) -> std::result::Result<
119            tonic::Response<super::ActiveConnectionResponse>,
120            tonic::Status,
121        > {
122            self.inner
123                .ready()
124                .await
125                .map_err(|e| {
126                    tonic::Status::unknown(
127                        format!("Service was not ready: {}", e.into()),
128                    )
129                })?;
130            let codec = tonic_prost::ProstCodec::default();
131            let path = http::uri::PathAndQuery::from_static(
132                "/agent.Agent/ActiveConnections",
133            );
134            let mut req = request.into_request();
135            req.extensions_mut()
136                .insert(GrpcMethod::new("agent.Agent", "ActiveConnections"));
137            self.inner.unary(req, path, codec).await
138        }
139    }
140}
141/// Generated server implementations.
142pub mod agent_server {
143    #![allow(
144        unused_variables,
145        dead_code,
146        missing_docs,
147        clippy::wildcard_imports,
148        clippy::let_unit_value,
149    )]
150    use tonic::codegen::*;
151    /// Generated trait containing gRPC methods that should be implemented for use with AgentServer.
152    #[async_trait]
153    pub trait Agent: std::marker::Send + std::marker::Sync + 'static {
154        /// active connections endpoint
155        async fn active_connections(
156            &self,
157            request: tonic::Request<super::RequestActiveConnections>,
158        ) -> std::result::Result<
159            tonic::Response<super::ActiveConnectionResponse>,
160            tonic::Status,
161        >;
162    }
163    /// declare agent api
164    #[derive(Debug)]
165    pub struct AgentServer<T> {
166        inner: Arc<T>,
167        accept_compression_encodings: EnabledCompressionEncodings,
168        send_compression_encodings: EnabledCompressionEncodings,
169        max_decoding_message_size: Option<usize>,
170        max_encoding_message_size: Option<usize>,
171    }
172    impl<T> AgentServer<T> {
173        pub fn new(inner: T) -> Self {
174            Self::from_arc(Arc::new(inner))
175        }
176        pub fn from_arc(inner: Arc<T>) -> Self {
177            Self {
178                inner,
179                accept_compression_encodings: Default::default(),
180                send_compression_encodings: Default::default(),
181                max_decoding_message_size: None,
182                max_encoding_message_size: None,
183            }
184        }
185        pub fn with_interceptor<F>(
186            inner: T,
187            interceptor: F,
188        ) -> InterceptedService<Self, F>
189        where
190            F: tonic::service::Interceptor,
191        {
192            InterceptedService::new(Self::new(inner), interceptor)
193        }
194        /// Enable decompressing requests with the given encoding.
195        #[must_use]
196        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
197            self.accept_compression_encodings.enable(encoding);
198            self
199        }
200        /// Compress responses with the given encoding, if the client supports it.
201        #[must_use]
202        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
203            self.send_compression_encodings.enable(encoding);
204            self
205        }
206        /// Limits the maximum size of a decoded message.
207        ///
208        /// Default: `4MB`
209        #[must_use]
210        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
211            self.max_decoding_message_size = Some(limit);
212            self
213        }
214        /// Limits the maximum size of an encoded message.
215        ///
216        /// Default: `usize::MAX`
217        #[must_use]
218        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
219            self.max_encoding_message_size = Some(limit);
220            self
221        }
222    }
223    impl<T, B> tonic::codegen::Service<http::Request<B>> for AgentServer<T>
224    where
225        T: Agent,
226        B: Body + std::marker::Send + 'static,
227        B::Error: Into<StdError> + std::marker::Send + 'static,
228    {
229        type Response = http::Response<tonic::body::Body>;
230        type Error = std::convert::Infallible;
231        type Future = BoxFuture<Self::Response, Self::Error>;
232        fn poll_ready(
233            &mut self,
234            _cx: &mut Context<'_>,
235        ) -> Poll<std::result::Result<(), Self::Error>> {
236            Poll::Ready(Ok(()))
237        }
238        fn call(&mut self, req: http::Request<B>) -> Self::Future {
239            match req.uri().path() {
240                "/agent.Agent/ActiveConnections" => {
241                    #[allow(non_camel_case_types)]
242                    struct ActiveConnectionsSvc<T: Agent>(pub Arc<T>);
243                    impl<
244                        T: Agent,
245                    > tonic::server::UnaryService<super::RequestActiveConnections>
246                    for ActiveConnectionsSvc<T> {
247                        type Response = super::ActiveConnectionResponse;
248                        type Future = BoxFuture<
249                            tonic::Response<Self::Response>,
250                            tonic::Status,
251                        >;
252                        fn call(
253                            &mut self,
254                            request: tonic::Request<super::RequestActiveConnections>,
255                        ) -> Self::Future {
256                            let inner = Arc::clone(&self.0);
257                            let fut = async move {
258                                <T as Agent>::active_connections(&inner, request).await
259                            };
260                            Box::pin(fut)
261                        }
262                    }
263                    let accept_compression_encodings = self.accept_compression_encodings;
264                    let send_compression_encodings = self.send_compression_encodings;
265                    let max_decoding_message_size = self.max_decoding_message_size;
266                    let max_encoding_message_size = self.max_encoding_message_size;
267                    let inner = self.inner.clone();
268                    let fut = async move {
269                        let method = ActiveConnectionsSvc(inner);
270                        let codec = tonic_prost::ProstCodec::default();
271                        let mut grpc = tonic::server::Grpc::new(codec)
272                            .apply_compression_config(
273                                accept_compression_encodings,
274                                send_compression_encodings,
275                            )
276                            .apply_max_message_size_config(
277                                max_decoding_message_size,
278                                max_encoding_message_size,
279                            );
280                        let res = grpc.unary(method, req).await;
281                        Ok(res)
282                    };
283                    Box::pin(fut)
284                }
285                _ => {
286                    Box::pin(async move {
287                        let mut response = http::Response::new(
288                            tonic::body::Body::default(),
289                        );
290                        let headers = response.headers_mut();
291                        headers
292                            .insert(
293                                tonic::Status::GRPC_STATUS,
294                                (tonic::Code::Unimplemented as i32).into(),
295                            );
296                        headers
297                            .insert(
298                                http::header::CONTENT_TYPE,
299                                tonic::metadata::GRPC_CONTENT_TYPE,
300                            );
301                        Ok(response)
302                    })
303                }
304            }
305        }
306    }
307    impl<T> Clone for AgentServer<T> {
308        fn clone(&self) -> Self {
309            let inner = self.inner.clone();
310            Self {
311                inner,
312                accept_compression_encodings: self.accept_compression_encodings,
313                send_compression_encodings: self.send_compression_encodings,
314                max_decoding_message_size: self.max_decoding_message_size,
315                max_encoding_message_size: self.max_encoding_message_size,
316            }
317        }
318    }
319    /// Generated gRPC service name
320    pub const SERVICE_NAME: &str = "agent.Agent";
321    impl<T> tonic::server::NamedService for AgentServer<T> {
322        const NAME: &'static str = SERVICE_NAME;
323    }
324}