momento_protos/
auth.rs

1// This file is @generated by prost-build.
2#[derive(Clone, Copy, PartialEq, ::prost::Message)]
3pub struct LoginRequest {}
4#[derive(Clone, PartialEq, ::prost::Message)]
5pub struct LoginResponse {
6    #[prost(oneof = "login_response::State", tags = "1, 2, 3, 4")]
7    pub state: ::core::option::Option<login_response::State>,
8}
9/// Nested message and enum types in `_LoginResponse`.
10pub mod login_response {
11    /// Terminal state, login success
12    #[derive(Clone, PartialEq, ::prost::Message)]
13    pub struct LoggedIn {
14        #[prost(string, tag = "1")]
15        pub session_token: ::prost::alloc::string::String,
16        /// How many seconds the token was valid for when issued.
17        /// Will vary slightly from reality upon receipt, as
18        /// time has passed since the token was minted.
19        /// You might expect to see this true to within 10
20        /// seconds of client-side timekeeping but as is
21        /// ever the case, there are no guarantees with
22        /// public network timing.
23        #[prost(uint32, tag = "2")]
24        pub valid_for_seconds: u32,
25    }
26    /// Terminal state, login error
27    #[derive(Clone, PartialEq, ::prost::Message)]
28    pub struct Error {
29        #[prost(string, tag = "1")]
30        pub description: ::prost::alloc::string::String,
31    }
32    /// Open a browser to a url, for interactive login
33    #[derive(Clone, PartialEq, ::prost::Message)]
34    pub struct DirectBrowser {
35        #[prost(string, tag = "1")]
36        pub url: ::prost::alloc::string::String,
37    }
38    /// Logging info about the login process
39    #[derive(Clone, PartialEq, ::prost::Message)]
40    pub struct Message {
41        #[prost(string, tag = "1")]
42        pub text: ::prost::alloc::string::String,
43    }
44    #[derive(Clone, PartialEq, ::prost::Oneof)]
45    pub enum State {
46        #[prost(message, tag = "1")]
47        DirectBrowser(DirectBrowser),
48        #[prost(message, tag = "2")]
49        LoggedIn(LoggedIn),
50        #[prost(message, tag = "3")]
51        Message(Message),
52        #[prost(message, tag = "4")]
53        Error(Error),
54    }
55}
56#[derive(Clone, PartialEq, ::prost::Message)]
57pub struct GenerateApiTokenRequest {
58    #[prost(string, tag = "3")]
59    pub auth_token: ::prost::alloc::string::String,
60    #[prost(message, optional, tag = "4")]
61    pub permissions: ::core::option::Option<super::permission_messages::Permissions>,
62    #[prost(string, tag = "5")]
63    pub token_id: ::prost::alloc::string::String,
64    #[prost(string, tag = "6")]
65    pub description: ::prost::alloc::string::String,
66    #[prost(oneof = "generate_api_token_request::Expiry", tags = "1, 2")]
67    pub expiry: ::core::option::Option<generate_api_token_request::Expiry>,
68}
69/// Nested message and enum types in `_GenerateApiTokenRequest`.
70pub mod generate_api_token_request {
71    /// generate a token that will never expire
72    #[derive(Clone, Copy, PartialEq, ::prost::Message)]
73    pub struct Never {}
74    /// generate a token that has an expiry
75    #[derive(Clone, Copy, PartialEq, ::prost::Message)]
76    pub struct Expires {
77        /// how many seconds do you want the api token to be valid for?
78        #[prost(uint32, tag = "1")]
79        pub valid_for_seconds: u32,
80    }
81    #[derive(Clone, Copy, PartialEq, ::prost::Oneof)]
82    pub enum Expiry {
83        #[prost(message, tag = "1")]
84        Never(Never),
85        #[prost(message, tag = "2")]
86        Expires(Expires),
87    }
88}
89#[derive(Clone, PartialEq, ::prost::Message)]
90pub struct GenerateApiTokenResponse {
91    /// the api key used for authentication against Momento backend
92    #[prost(string, tag = "1")]
93    pub api_key: ::prost::alloc::string::String,
94    /// the token that will allow the api token to be refreshed, which will
95    /// give you back a new refresh and api token
96    #[prost(string, tag = "2")]
97    pub refresh_token: ::prost::alloc::string::String,
98    /// the Momento endpoint that this token is allowed to make requests against
99    #[prost(string, tag = "3")]
100    pub endpoint: ::prost::alloc::string::String,
101    /// epoch seconds when the api token expires
102    #[prost(uint64, tag = "4")]
103    pub valid_until: u64,
104}
105#[derive(Clone, PartialEq, ::prost::Message)]
106pub struct RefreshApiTokenRequest {
107    /// the existing api token to be refreshed
108    #[prost(string, tag = "1")]
109    pub api_key: ::prost::alloc::string::String,
110    /// the refresh token that was generated with that api token
111    #[prost(string, tag = "2")]
112    pub refresh_token: ::prost::alloc::string::String,
113}
114#[derive(Clone, PartialEq, ::prost::Message)]
115pub struct RefreshApiTokenResponse {
116    /// the new api key used for authentication against Momento backend
117    #[prost(string, tag = "1")]
118    pub api_key: ::prost::alloc::string::String,
119    /// the token that will allow the api token to be refreshed, which will
120    /// give you back a new refresh and api token
121    #[prost(string, tag = "2")]
122    pub refresh_token: ::prost::alloc::string::String,
123    /// the Momento endpoint that this token is allowed to make requests against
124    #[prost(string, tag = "3")]
125    pub endpoint: ::prost::alloc::string::String,
126    /// epoch seconds when the api token expires
127    #[prost(uint64, tag = "4")]
128    pub valid_until: u64,
129}
130/// Generated client implementations.
131pub mod auth_client {
132    #![allow(
133        unused_variables,
134        dead_code,
135        missing_docs,
136        clippy::wildcard_imports,
137        clippy::let_unit_value,
138    )]
139    use tonic::codegen::*;
140    use tonic::codegen::http::Uri;
141    #[derive(Debug, Clone)]
142    pub struct AuthClient<T> {
143        inner: tonic::client::Grpc<T>,
144    }
145    impl AuthClient<tonic::transport::Channel> {
146        /// Attempt to create a new client by connecting to a given endpoint.
147        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
148        where
149            D: TryInto<tonic::transport::Endpoint>,
150            D::Error: Into<StdError>,
151        {
152            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
153            Ok(Self::new(conn))
154        }
155    }
156    impl<T> AuthClient<T>
157    where
158        T: tonic::client::GrpcService<tonic::body::Body>,
159        T::Error: Into<StdError>,
160        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
161        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
162    {
163        pub fn new(inner: T) -> Self {
164            let inner = tonic::client::Grpc::new(inner);
165            Self { inner }
166        }
167        pub fn with_origin(inner: T, origin: Uri) -> Self {
168            let inner = tonic::client::Grpc::with_origin(inner, origin);
169            Self { inner }
170        }
171        pub fn with_interceptor<F>(
172            inner: T,
173            interceptor: F,
174        ) -> AuthClient<InterceptedService<T, F>>
175        where
176            F: tonic::service::Interceptor,
177            T::ResponseBody: Default,
178            T: tonic::codegen::Service<
179                http::Request<tonic::body::Body>,
180                Response = http::Response<
181                    <T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
182                >,
183            >,
184            <T as tonic::codegen::Service<
185                http::Request<tonic::body::Body>,
186            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
187        {
188            AuthClient::new(InterceptedService::new(inner, interceptor))
189        }
190        /// Compress requests with the given encoding.
191        ///
192        /// This requires the server to support it otherwise it might respond with an
193        /// error.
194        #[must_use]
195        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
196            self.inner = self.inner.send_compressed(encoding);
197            self
198        }
199        /// Enable decompressing responses.
200        #[must_use]
201        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
202            self.inner = self.inner.accept_compressed(encoding);
203            self
204        }
205        /// Limits the maximum size of a decoded message.
206        ///
207        /// Default: `4MB`
208        #[must_use]
209        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
210            self.inner = self.inner.max_decoding_message_size(limit);
211            self
212        }
213        /// Limits the maximum size of an encoded message.
214        ///
215        /// Default: `usize::MAX`
216        #[must_use]
217        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
218            self.inner = self.inner.max_encoding_message_size(limit);
219            self
220        }
221        pub async fn login(
222            &mut self,
223            request: impl tonic::IntoRequest<super::LoginRequest>,
224        ) -> std::result::Result<
225            tonic::Response<tonic::codec::Streaming<super::LoginResponse>>,
226            tonic::Status,
227        > {
228            self.inner
229                .ready()
230                .await
231                .map_err(|e| {
232                    tonic::Status::unknown(
233                        format!("Service was not ready: {}", e.into()),
234                    )
235                })?;
236            let codec = tonic::codec::ProstCodec::default();
237            let path = http::uri::PathAndQuery::from_static("/auth.Auth/Login");
238            let mut req = request.into_request();
239            req.extensions_mut().insert(GrpcMethod::new("auth.Auth", "Login"));
240            self.inner.server_streaming(req, path, codec).await
241        }
242        /// api for initially generating api and refresh tokens
243        pub async fn generate_api_token(
244            &mut self,
245            request: impl tonic::IntoRequest<super::GenerateApiTokenRequest>,
246        ) -> std::result::Result<
247            tonic::Response<super::GenerateApiTokenResponse>,
248            tonic::Status,
249        > {
250            self.inner
251                .ready()
252                .await
253                .map_err(|e| {
254                    tonic::Status::unknown(
255                        format!("Service was not ready: {}", e.into()),
256                    )
257                })?;
258            let codec = tonic::codec::ProstCodec::default();
259            let path = http::uri::PathAndQuery::from_static(
260                "/auth.Auth/GenerateApiToken",
261            );
262            let mut req = request.into_request();
263            req.extensions_mut()
264                .insert(GrpcMethod::new("auth.Auth", "GenerateApiToken"));
265            self.inner.unary(req, path, codec).await
266        }
267        /// api for programmatically refreshing api and refresh tokens
268        pub async fn refresh_api_token(
269            &mut self,
270            request: impl tonic::IntoRequest<super::RefreshApiTokenRequest>,
271        ) -> std::result::Result<
272            tonic::Response<super::RefreshApiTokenResponse>,
273            tonic::Status,
274        > {
275            self.inner
276                .ready()
277                .await
278                .map_err(|e| {
279                    tonic::Status::unknown(
280                        format!("Service was not ready: {}", e.into()),
281                    )
282                })?;
283            let codec = tonic::codec::ProstCodec::default();
284            let path = http::uri::PathAndQuery::from_static(
285                "/auth.Auth/RefreshApiToken",
286            );
287            let mut req = request.into_request();
288            req.extensions_mut().insert(GrpcMethod::new("auth.Auth", "RefreshApiToken"));
289            self.inner.unary(req, path, codec).await
290        }
291    }
292}
293/// Generated server implementations.
294pub mod auth_server {
295    #![allow(
296        unused_variables,
297        dead_code,
298        missing_docs,
299        clippy::wildcard_imports,
300        clippy::let_unit_value,
301    )]
302    use tonic::codegen::*;
303    /// Generated trait containing gRPC methods that should be implemented for use with AuthServer.
304    #[async_trait]
305    pub trait Auth: std::marker::Send + std::marker::Sync + 'static {
306        /// Server streaming response type for the Login method.
307        type LoginStream: tonic::codegen::tokio_stream::Stream<
308                Item = std::result::Result<super::LoginResponse, tonic::Status>,
309            >
310            + std::marker::Send
311            + 'static;
312        async fn login(
313            &self,
314            request: tonic::Request<super::LoginRequest>,
315        ) -> std::result::Result<tonic::Response<Self::LoginStream>, tonic::Status>;
316        /// api for initially generating api and refresh tokens
317        async fn generate_api_token(
318            &self,
319            request: tonic::Request<super::GenerateApiTokenRequest>,
320        ) -> std::result::Result<
321            tonic::Response<super::GenerateApiTokenResponse>,
322            tonic::Status,
323        >;
324        /// api for programmatically refreshing api and refresh tokens
325        async fn refresh_api_token(
326            &self,
327            request: tonic::Request<super::RefreshApiTokenRequest>,
328        ) -> std::result::Result<
329            tonic::Response<super::RefreshApiTokenResponse>,
330            tonic::Status,
331        >;
332    }
333    #[derive(Debug)]
334    pub struct AuthServer<T> {
335        inner: Arc<T>,
336        accept_compression_encodings: EnabledCompressionEncodings,
337        send_compression_encodings: EnabledCompressionEncodings,
338        max_decoding_message_size: Option<usize>,
339        max_encoding_message_size: Option<usize>,
340    }
341    impl<T> AuthServer<T> {
342        pub fn new(inner: T) -> Self {
343            Self::from_arc(Arc::new(inner))
344        }
345        pub fn from_arc(inner: Arc<T>) -> Self {
346            Self {
347                inner,
348                accept_compression_encodings: Default::default(),
349                send_compression_encodings: Default::default(),
350                max_decoding_message_size: None,
351                max_encoding_message_size: None,
352            }
353        }
354        pub fn with_interceptor<F>(
355            inner: T,
356            interceptor: F,
357        ) -> InterceptedService<Self, F>
358        where
359            F: tonic::service::Interceptor,
360        {
361            InterceptedService::new(Self::new(inner), interceptor)
362        }
363        /// Enable decompressing requests with the given encoding.
364        #[must_use]
365        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
366            self.accept_compression_encodings.enable(encoding);
367            self
368        }
369        /// Compress responses with the given encoding, if the client supports it.
370        #[must_use]
371        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
372            self.send_compression_encodings.enable(encoding);
373            self
374        }
375        /// Limits the maximum size of a decoded message.
376        ///
377        /// Default: `4MB`
378        #[must_use]
379        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
380            self.max_decoding_message_size = Some(limit);
381            self
382        }
383        /// Limits the maximum size of an encoded message.
384        ///
385        /// Default: `usize::MAX`
386        #[must_use]
387        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
388            self.max_encoding_message_size = Some(limit);
389            self
390        }
391    }
392    impl<T, B> tonic::codegen::Service<http::Request<B>> for AuthServer<T>
393    where
394        T: Auth,
395        B: Body + std::marker::Send + 'static,
396        B::Error: Into<StdError> + std::marker::Send + 'static,
397    {
398        type Response = http::Response<tonic::body::Body>;
399        type Error = std::convert::Infallible;
400        type Future = BoxFuture<Self::Response, Self::Error>;
401        fn poll_ready(
402            &mut self,
403            _cx: &mut Context<'_>,
404        ) -> Poll<std::result::Result<(), Self::Error>> {
405            Poll::Ready(Ok(()))
406        }
407        fn call(&mut self, req: http::Request<B>) -> Self::Future {
408            match req.uri().path() {
409                "/auth.Auth/Login" => {
410                    #[allow(non_camel_case_types)]
411                    struct LoginSvc<T: Auth>(pub Arc<T>);
412                    impl<
413                        T: Auth,
414                    > tonic::server::ServerStreamingService<super::LoginRequest>
415                    for LoginSvc<T> {
416                        type Response = super::LoginResponse;
417                        type ResponseStream = T::LoginStream;
418                        type Future = BoxFuture<
419                            tonic::Response<Self::ResponseStream>,
420                            tonic::Status,
421                        >;
422                        fn call(
423                            &mut self,
424                            request: tonic::Request<super::LoginRequest>,
425                        ) -> Self::Future {
426                            let inner = Arc::clone(&self.0);
427                            let fut = async move {
428                                <T as Auth>::login(&inner, request).await
429                            };
430                            Box::pin(fut)
431                        }
432                    }
433                    let accept_compression_encodings = self.accept_compression_encodings;
434                    let send_compression_encodings = self.send_compression_encodings;
435                    let max_decoding_message_size = self.max_decoding_message_size;
436                    let max_encoding_message_size = self.max_encoding_message_size;
437                    let inner = self.inner.clone();
438                    let fut = async move {
439                        let method = LoginSvc(inner);
440                        let codec = tonic::codec::ProstCodec::default();
441                        let mut grpc = tonic::server::Grpc::new(codec)
442                            .apply_compression_config(
443                                accept_compression_encodings,
444                                send_compression_encodings,
445                            )
446                            .apply_max_message_size_config(
447                                max_decoding_message_size,
448                                max_encoding_message_size,
449                            );
450                        let res = grpc.server_streaming(method, req).await;
451                        Ok(res)
452                    };
453                    Box::pin(fut)
454                }
455                "/auth.Auth/GenerateApiToken" => {
456                    #[allow(non_camel_case_types)]
457                    struct GenerateApiTokenSvc<T: Auth>(pub Arc<T>);
458                    impl<
459                        T: Auth,
460                    > tonic::server::UnaryService<super::GenerateApiTokenRequest>
461                    for GenerateApiTokenSvc<T> {
462                        type Response = super::GenerateApiTokenResponse;
463                        type Future = BoxFuture<
464                            tonic::Response<Self::Response>,
465                            tonic::Status,
466                        >;
467                        fn call(
468                            &mut self,
469                            request: tonic::Request<super::GenerateApiTokenRequest>,
470                        ) -> Self::Future {
471                            let inner = Arc::clone(&self.0);
472                            let fut = async move {
473                                <T as Auth>::generate_api_token(&inner, request).await
474                            };
475                            Box::pin(fut)
476                        }
477                    }
478                    let accept_compression_encodings = self.accept_compression_encodings;
479                    let send_compression_encodings = self.send_compression_encodings;
480                    let max_decoding_message_size = self.max_decoding_message_size;
481                    let max_encoding_message_size = self.max_encoding_message_size;
482                    let inner = self.inner.clone();
483                    let fut = async move {
484                        let method = GenerateApiTokenSvc(inner);
485                        let codec = tonic::codec::ProstCodec::default();
486                        let mut grpc = tonic::server::Grpc::new(codec)
487                            .apply_compression_config(
488                                accept_compression_encodings,
489                                send_compression_encodings,
490                            )
491                            .apply_max_message_size_config(
492                                max_decoding_message_size,
493                                max_encoding_message_size,
494                            );
495                        let res = grpc.unary(method, req).await;
496                        Ok(res)
497                    };
498                    Box::pin(fut)
499                }
500                "/auth.Auth/RefreshApiToken" => {
501                    #[allow(non_camel_case_types)]
502                    struct RefreshApiTokenSvc<T: Auth>(pub Arc<T>);
503                    impl<
504                        T: Auth,
505                    > tonic::server::UnaryService<super::RefreshApiTokenRequest>
506                    for RefreshApiTokenSvc<T> {
507                        type Response = super::RefreshApiTokenResponse;
508                        type Future = BoxFuture<
509                            tonic::Response<Self::Response>,
510                            tonic::Status,
511                        >;
512                        fn call(
513                            &mut self,
514                            request: tonic::Request<super::RefreshApiTokenRequest>,
515                        ) -> Self::Future {
516                            let inner = Arc::clone(&self.0);
517                            let fut = async move {
518                                <T as Auth>::refresh_api_token(&inner, request).await
519                            };
520                            Box::pin(fut)
521                        }
522                    }
523                    let accept_compression_encodings = self.accept_compression_encodings;
524                    let send_compression_encodings = self.send_compression_encodings;
525                    let max_decoding_message_size = self.max_decoding_message_size;
526                    let max_encoding_message_size = self.max_encoding_message_size;
527                    let inner = self.inner.clone();
528                    let fut = async move {
529                        let method = RefreshApiTokenSvc(inner);
530                        let codec = tonic::codec::ProstCodec::default();
531                        let mut grpc = tonic::server::Grpc::new(codec)
532                            .apply_compression_config(
533                                accept_compression_encodings,
534                                send_compression_encodings,
535                            )
536                            .apply_max_message_size_config(
537                                max_decoding_message_size,
538                                max_encoding_message_size,
539                            );
540                        let res = grpc.unary(method, req).await;
541                        Ok(res)
542                    };
543                    Box::pin(fut)
544                }
545                _ => {
546                    Box::pin(async move {
547                        let mut response = http::Response::new(
548                            tonic::body::Body::default(),
549                        );
550                        let headers = response.headers_mut();
551                        headers
552                            .insert(
553                                tonic::Status::GRPC_STATUS,
554                                (tonic::Code::Unimplemented as i32).into(),
555                            );
556                        headers
557                            .insert(
558                                http::header::CONTENT_TYPE,
559                                tonic::metadata::GRPC_CONTENT_TYPE,
560                            );
561                        Ok(response)
562                    })
563                }
564            }
565        }
566    }
567    impl<T> Clone for AuthServer<T> {
568        fn clone(&self) -> Self {
569            let inner = self.inner.clone();
570            Self {
571                inner,
572                accept_compression_encodings: self.accept_compression_encodings,
573                send_compression_encodings: self.send_compression_encodings,
574                max_decoding_message_size: self.max_decoding_message_size,
575                max_encoding_message_size: self.max_encoding_message_size,
576            }
577        }
578    }
579    /// Generated gRPC service name
580    pub const SERVICE_NAME: &str = "auth.Auth";
581    impl<T> tonic::server::NamedService for AuthServer<T> {
582        const NAME: &'static str = SERVICE_NAME;
583    }
584}