1#[allow(clippy::derive_partial_eq_without_eq)]
3#[derive(Clone, PartialEq, ::prost::Message)]
4pub struct AddKeyRequest {
5 #[prost(string, tag = "1")]
6 pub id: ::prost::alloc::string::String,
7 #[prost(bytes = "vec", tag = "2")]
8 pub value: ::prost::alloc::vec::Vec<u8>,
9 #[prost(uint64, tag = "3")]
11 pub ttl: u64,
12}
13#[allow(clippy::derive_partial_eq_without_eq)]
14#[derive(Clone, PartialEq, ::prost::Message)]
15pub struct GetKeyRequest {
16 #[prost(string, tag = "1")]
17 pub id: ::prost::alloc::string::String,
18 #[prost(uint32, tag = "2")]
20 pub version: u32,
21}
22#[allow(clippy::derive_partial_eq_without_eq)]
23#[derive(Clone, PartialEq, ::prost::Message)]
24pub struct MigrateKeyRequest {
25 #[prost(string, tag = "1")]
26 pub id: ::prost::alloc::string::String,
27}
28#[allow(clippy::derive_partial_eq_without_eq)]
29#[derive(Clone, PartialEq, ::prost::Message)]
30pub struct GenerateKeyRequest {
31 #[prost(uint32, tag = "1")]
33 pub length: u32,
34}
35#[allow(clippy::derive_partial_eq_without_eq)]
36#[derive(Clone, PartialEq, ::prost::Message)]
37pub struct Key {
38 #[prost(string, tag = "1")]
39 pub id: ::prost::alloc::string::String,
40 #[prost(bytes = "vec", tag = "2")]
41 pub value: ::prost::alloc::vec::Vec<u8>,
42 #[prost(uint64, tag = "3")]
43 pub ttl: u64,
44 #[prost(uint64, tag = "4")]
45 pub created_at: u64,
46 #[prost(uint64, tag = "5")]
47 pub expires_at: u64,
48 #[prost(uint32, tag = "6")]
49 pub version: u32,
50 #[prost(enumeration = "KeyStatus", tag = "7")]
51 pub status: i32,
52}
53#[allow(clippy::derive_partial_eq_without_eq)]
54#[derive(Clone, PartialEq, ::prost::Message)]
55pub struct CommandResponse {
56 #[prost(bool, tag = "1")]
57 pub success: bool,
58 #[prost(string, tag = "2")]
59 pub message: ::prost::alloc::string::String,
60}
61#[allow(clippy::derive_partial_eq_without_eq)]
62#[derive(Clone, PartialEq, ::prost::Message)]
63pub struct KeyResponse {
64 #[prost(bool, tag = "1")]
65 pub success: bool,
66 #[prost(string, tag = "2")]
67 pub message: ::prost::alloc::string::String,
68 #[prost(message, optional, tag = "3")]
69 pub key: ::core::option::Option<Key>,
70}
71#[allow(clippy::derive_partial_eq_without_eq)]
72#[derive(Clone, PartialEq, ::prost::Message)]
73pub struct GenerateKeyResponse {
74 #[prost(bool, tag = "1")]
75 pub success: bool,
76 #[prost(string, tag = "2")]
78 pub key: ::prost::alloc::string::String,
79}
80#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
81#[repr(i32)]
82pub enum KeyStatus {
83 Active = 0,
84 NearExpiration = 1,
85 Expired = 2,
86 Invalid = 3,
87}
88impl KeyStatus {
89 pub fn as_str_name(&self) -> &'static str {
94 match self {
95 KeyStatus::Active => "ACTIVE",
96 KeyStatus::NearExpiration => "NEAR_EXPIRATION",
97 KeyStatus::Expired => "EXPIRED",
98 KeyStatus::Invalid => "INVALID",
99 }
100 }
101 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
103 match value {
104 "ACTIVE" => Some(Self::Active),
105 "NEAR_EXPIRATION" => Some(Self::NearExpiration),
106 "EXPIRED" => Some(Self::Expired),
107 "INVALID" => Some(Self::Invalid),
108 _ => None,
109 }
110 }
111}
112pub mod key_store_client {
114 #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
115 use tonic::codegen::*;
116 use tonic::codegen::http::Uri;
117 #[derive(Debug, Clone)]
118 pub struct KeyStoreClient<T> {
119 inner: tonic::client::Grpc<T>,
120 }
121 impl KeyStoreClient<tonic::transport::Channel> {
122 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
124 where
125 D: TryInto<tonic::transport::Endpoint>,
126 D::Error: Into<StdError>,
127 {
128 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
129 Ok(Self::new(conn))
130 }
131 }
132 impl<T> KeyStoreClient<T>
133 where
134 T: tonic::client::GrpcService<tonic::body::BoxBody>,
135 T::Error: Into<StdError>,
136 T::ResponseBody: Body<Data = Bytes> + Send + 'static,
137 <T::ResponseBody as Body>::Error: Into<StdError> + Send,
138 {
139 pub fn new(inner: T) -> Self {
140 let inner = tonic::client::Grpc::new(inner);
141 Self { inner }
142 }
143 pub fn with_origin(inner: T, origin: Uri) -> Self {
144 let inner = tonic::client::Grpc::with_origin(inner, origin);
145 Self { inner }
146 }
147 pub fn with_interceptor<F>(
148 inner: T,
149 interceptor: F,
150 ) -> KeyStoreClient<InterceptedService<T, F>>
151 where
152 F: tonic::service::Interceptor,
153 T::ResponseBody: Default,
154 T: tonic::codegen::Service<
155 http::Request<tonic::body::BoxBody>,
156 Response = http::Response<
157 <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
158 >,
159 >,
160 <T as tonic::codegen::Service<
161 http::Request<tonic::body::BoxBody>,
162 >>::Error: Into<StdError> + Send + Sync,
163 {
164 KeyStoreClient::new(InterceptedService::new(inner, interceptor))
165 }
166 #[must_use]
171 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
172 self.inner = self.inner.send_compressed(encoding);
173 self
174 }
175 #[must_use]
177 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
178 self.inner = self.inner.accept_compressed(encoding);
179 self
180 }
181 #[must_use]
185 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
186 self.inner = self.inner.max_decoding_message_size(limit);
187 self
188 }
189 #[must_use]
193 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
194 self.inner = self.inner.max_encoding_message_size(limit);
195 self
196 }
197 pub async fn add_key(
198 &mut self,
199 request: impl tonic::IntoRequest<super::AddKeyRequest>,
200 ) -> std::result::Result<
201 tonic::Response<super::CommandResponse>,
202 tonic::Status,
203 > {
204 self.inner
205 .ready()
206 .await
207 .map_err(|e| {
208 tonic::Status::new(
209 tonic::Code::Unknown,
210 format!("Service was not ready: {}", e.into()),
211 )
212 })?;
213 let codec = tonic::codec::ProstCodec::default();
214 let path = http::uri::PathAndQuery::from_static("/keystore.KeyStore/AddKey");
215 let mut req = request.into_request();
216 req.extensions_mut().insert(GrpcMethod::new("keystore.KeyStore", "AddKey"));
217 self.inner.unary(req, path, codec).await
218 }
219 pub async fn get_key(
220 &mut self,
221 request: impl tonic::IntoRequest<super::GetKeyRequest>,
222 ) -> std::result::Result<tonic::Response<super::KeyResponse>, tonic::Status> {
223 self.inner
224 .ready()
225 .await
226 .map_err(|e| {
227 tonic::Status::new(
228 tonic::Code::Unknown,
229 format!("Service was not ready: {}", e.into()),
230 )
231 })?;
232 let codec = tonic::codec::ProstCodec::default();
233 let path = http::uri::PathAndQuery::from_static("/keystore.KeyStore/GetKey");
234 let mut req = request.into_request();
235 req.extensions_mut().insert(GrpcMethod::new("keystore.KeyStore", "GetKey"));
236 self.inner.unary(req, path, codec).await
237 }
238 pub async fn migrate_key(
239 &mut self,
240 request: impl tonic::IntoRequest<super::MigrateKeyRequest>,
241 ) -> std::result::Result<
242 tonic::Response<super::CommandResponse>,
243 tonic::Status,
244 > {
245 self.inner
246 .ready()
247 .await
248 .map_err(|e| {
249 tonic::Status::new(
250 tonic::Code::Unknown,
251 format!("Service was not ready: {}", e.into()),
252 )
253 })?;
254 let codec = tonic::codec::ProstCodec::default();
255 let path = http::uri::PathAndQuery::from_static(
256 "/keystore.KeyStore/MigrateKey",
257 );
258 let mut req = request.into_request();
259 req.extensions_mut()
260 .insert(GrpcMethod::new("keystore.KeyStore", "MigrateKey"));
261 self.inner.unary(req, path, codec).await
262 }
263 pub async fn generate_key(
264 &mut self,
265 request: impl tonic::IntoRequest<super::GenerateKeyRequest>,
266 ) -> std::result::Result<
267 tonic::Response<super::GenerateKeyResponse>,
268 tonic::Status,
269 > {
270 self.inner
271 .ready()
272 .await
273 .map_err(|e| {
274 tonic::Status::new(
275 tonic::Code::Unknown,
276 format!("Service was not ready: {}", e.into()),
277 )
278 })?;
279 let codec = tonic::codec::ProstCodec::default();
280 let path = http::uri::PathAndQuery::from_static(
281 "/keystore.KeyStore/GenerateKey",
282 );
283 let mut req = request.into_request();
284 req.extensions_mut()
285 .insert(GrpcMethod::new("keystore.KeyStore", "GenerateKey"));
286 self.inner.unary(req, path, codec).await
287 }
288 }
289}
290pub mod key_store_server {
292 #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
293 use tonic::codegen::*;
294 #[async_trait]
296 pub trait KeyStore: Send + Sync + 'static {
297 async fn add_key(
298 &self,
299 request: tonic::Request<super::AddKeyRequest>,
300 ) -> std::result::Result<tonic::Response<super::CommandResponse>, tonic::Status>;
301 async fn get_key(
302 &self,
303 request: tonic::Request<super::GetKeyRequest>,
304 ) -> std::result::Result<tonic::Response<super::KeyResponse>, tonic::Status>;
305 async fn migrate_key(
306 &self,
307 request: tonic::Request<super::MigrateKeyRequest>,
308 ) -> std::result::Result<tonic::Response<super::CommandResponse>, tonic::Status>;
309 async fn generate_key(
310 &self,
311 request: tonic::Request<super::GenerateKeyRequest>,
312 ) -> std::result::Result<
313 tonic::Response<super::GenerateKeyResponse>,
314 tonic::Status,
315 >;
316 }
317 #[derive(Debug)]
318 pub struct KeyStoreServer<T: KeyStore> {
319 inner: _Inner<T>,
320 accept_compression_encodings: EnabledCompressionEncodings,
321 send_compression_encodings: EnabledCompressionEncodings,
322 max_decoding_message_size: Option<usize>,
323 max_encoding_message_size: Option<usize>,
324 }
325 struct _Inner<T>(Arc<T>);
326 impl<T: KeyStore> KeyStoreServer<T> {
327 pub fn new(inner: T) -> Self {
328 Self::from_arc(Arc::new(inner))
329 }
330 pub fn from_arc(inner: Arc<T>) -> Self {
331 let inner = _Inner(inner);
332 Self {
333 inner,
334 accept_compression_encodings: Default::default(),
335 send_compression_encodings: Default::default(),
336 max_decoding_message_size: None,
337 max_encoding_message_size: None,
338 }
339 }
340 pub fn with_interceptor<F>(
341 inner: T,
342 interceptor: F,
343 ) -> InterceptedService<Self, F>
344 where
345 F: tonic::service::Interceptor,
346 {
347 InterceptedService::new(Self::new(inner), interceptor)
348 }
349 #[must_use]
351 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
352 self.accept_compression_encodings.enable(encoding);
353 self
354 }
355 #[must_use]
357 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
358 self.send_compression_encodings.enable(encoding);
359 self
360 }
361 #[must_use]
365 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
366 self.max_decoding_message_size = Some(limit);
367 self
368 }
369 #[must_use]
373 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
374 self.max_encoding_message_size = Some(limit);
375 self
376 }
377 }
378 impl<T, B> tonic::codegen::Service<http::Request<B>> for KeyStoreServer<T>
379 where
380 T: KeyStore,
381 B: Body + Send + 'static,
382 B::Error: Into<StdError> + Send + 'static,
383 {
384 type Response = http::Response<tonic::body::BoxBody>;
385 type Error = std::convert::Infallible;
386 type Future = BoxFuture<Self::Response, Self::Error>;
387 fn poll_ready(
388 &mut self,
389 _cx: &mut Context<'_>,
390 ) -> Poll<std::result::Result<(), Self::Error>> {
391 Poll::Ready(Ok(()))
392 }
393 fn call(&mut self, req: http::Request<B>) -> Self::Future {
394 let inner = self.inner.clone();
395 match req.uri().path() {
396 "/keystore.KeyStore/AddKey" => {
397 #[allow(non_camel_case_types)]
398 struct AddKeySvc<T: KeyStore>(pub Arc<T>);
399 impl<T: KeyStore> tonic::server::UnaryService<super::AddKeyRequest>
400 for AddKeySvc<T> {
401 type Response = super::CommandResponse;
402 type Future = BoxFuture<
403 tonic::Response<Self::Response>,
404 tonic::Status,
405 >;
406 fn call(
407 &mut self,
408 request: tonic::Request<super::AddKeyRequest>,
409 ) -> Self::Future {
410 let inner = Arc::clone(&self.0);
411 let fut = async move {
412 <T as KeyStore>::add_key(&inner, request).await
413 };
414 Box::pin(fut)
415 }
416 }
417 let accept_compression_encodings = self.accept_compression_encodings;
418 let send_compression_encodings = self.send_compression_encodings;
419 let max_decoding_message_size = self.max_decoding_message_size;
420 let max_encoding_message_size = self.max_encoding_message_size;
421 let inner = self.inner.clone();
422 let fut = async move {
423 let inner = inner.0;
424 let method = AddKeySvc(inner);
425 let codec = tonic::codec::ProstCodec::default();
426 let mut grpc = tonic::server::Grpc::new(codec)
427 .apply_compression_config(
428 accept_compression_encodings,
429 send_compression_encodings,
430 )
431 .apply_max_message_size_config(
432 max_decoding_message_size,
433 max_encoding_message_size,
434 );
435 let res = grpc.unary(method, req).await;
436 Ok(res)
437 };
438 Box::pin(fut)
439 }
440 "/keystore.KeyStore/GetKey" => {
441 #[allow(non_camel_case_types)]
442 struct GetKeySvc<T: KeyStore>(pub Arc<T>);
443 impl<T: KeyStore> tonic::server::UnaryService<super::GetKeyRequest>
444 for GetKeySvc<T> {
445 type Response = super::KeyResponse;
446 type Future = BoxFuture<
447 tonic::Response<Self::Response>,
448 tonic::Status,
449 >;
450 fn call(
451 &mut self,
452 request: tonic::Request<super::GetKeyRequest>,
453 ) -> Self::Future {
454 let inner = Arc::clone(&self.0);
455 let fut = async move {
456 <T as KeyStore>::get_key(&inner, request).await
457 };
458 Box::pin(fut)
459 }
460 }
461 let accept_compression_encodings = self.accept_compression_encodings;
462 let send_compression_encodings = self.send_compression_encodings;
463 let max_decoding_message_size = self.max_decoding_message_size;
464 let max_encoding_message_size = self.max_encoding_message_size;
465 let inner = self.inner.clone();
466 let fut = async move {
467 let inner = inner.0;
468 let method = GetKeySvc(inner);
469 let codec = tonic::codec::ProstCodec::default();
470 let mut grpc = tonic::server::Grpc::new(codec)
471 .apply_compression_config(
472 accept_compression_encodings,
473 send_compression_encodings,
474 )
475 .apply_max_message_size_config(
476 max_decoding_message_size,
477 max_encoding_message_size,
478 );
479 let res = grpc.unary(method, req).await;
480 Ok(res)
481 };
482 Box::pin(fut)
483 }
484 "/keystore.KeyStore/MigrateKey" => {
485 #[allow(non_camel_case_types)]
486 struct MigrateKeySvc<T: KeyStore>(pub Arc<T>);
487 impl<
488 T: KeyStore,
489 > tonic::server::UnaryService<super::MigrateKeyRequest>
490 for MigrateKeySvc<T> {
491 type Response = super::CommandResponse;
492 type Future = BoxFuture<
493 tonic::Response<Self::Response>,
494 tonic::Status,
495 >;
496 fn call(
497 &mut self,
498 request: tonic::Request<super::MigrateKeyRequest>,
499 ) -> Self::Future {
500 let inner = Arc::clone(&self.0);
501 let fut = async move {
502 <T as KeyStore>::migrate_key(&inner, request).await
503 };
504 Box::pin(fut)
505 }
506 }
507 let accept_compression_encodings = self.accept_compression_encodings;
508 let send_compression_encodings = self.send_compression_encodings;
509 let max_decoding_message_size = self.max_decoding_message_size;
510 let max_encoding_message_size = self.max_encoding_message_size;
511 let inner = self.inner.clone();
512 let fut = async move {
513 let inner = inner.0;
514 let method = MigrateKeySvc(inner);
515 let codec = tonic::codec::ProstCodec::default();
516 let mut grpc = tonic::server::Grpc::new(codec)
517 .apply_compression_config(
518 accept_compression_encodings,
519 send_compression_encodings,
520 )
521 .apply_max_message_size_config(
522 max_decoding_message_size,
523 max_encoding_message_size,
524 );
525 let res = grpc.unary(method, req).await;
526 Ok(res)
527 };
528 Box::pin(fut)
529 }
530 "/keystore.KeyStore/GenerateKey" => {
531 #[allow(non_camel_case_types)]
532 struct GenerateKeySvc<T: KeyStore>(pub Arc<T>);
533 impl<
534 T: KeyStore,
535 > tonic::server::UnaryService<super::GenerateKeyRequest>
536 for GenerateKeySvc<T> {
537 type Response = super::GenerateKeyResponse;
538 type Future = BoxFuture<
539 tonic::Response<Self::Response>,
540 tonic::Status,
541 >;
542 fn call(
543 &mut self,
544 request: tonic::Request<super::GenerateKeyRequest>,
545 ) -> Self::Future {
546 let inner = Arc::clone(&self.0);
547 let fut = async move {
548 <T as KeyStore>::generate_key(&inner, request).await
549 };
550 Box::pin(fut)
551 }
552 }
553 let accept_compression_encodings = self.accept_compression_encodings;
554 let send_compression_encodings = self.send_compression_encodings;
555 let max_decoding_message_size = self.max_decoding_message_size;
556 let max_encoding_message_size = self.max_encoding_message_size;
557 let inner = self.inner.clone();
558 let fut = async move {
559 let inner = inner.0;
560 let method = GenerateKeySvc(inner);
561 let codec = tonic::codec::ProstCodec::default();
562 let mut grpc = tonic::server::Grpc::new(codec)
563 .apply_compression_config(
564 accept_compression_encodings,
565 send_compression_encodings,
566 )
567 .apply_max_message_size_config(
568 max_decoding_message_size,
569 max_encoding_message_size,
570 );
571 let res = grpc.unary(method, req).await;
572 Ok(res)
573 };
574 Box::pin(fut)
575 }
576 _ => {
577 Box::pin(async move {
578 Ok(
579 http::Response::builder()
580 .status(200)
581 .header("grpc-status", "12")
582 .header("content-type", "application/grpc")
583 .body(empty_body())
584 .unwrap(),
585 )
586 })
587 }
588 }
589 }
590 }
591 impl<T: KeyStore> Clone for KeyStoreServer<T> {
592 fn clone(&self) -> Self {
593 let inner = self.inner.clone();
594 Self {
595 inner,
596 accept_compression_encodings: self.accept_compression_encodings,
597 send_compression_encodings: self.send_compression_encodings,
598 max_decoding_message_size: self.max_decoding_message_size,
599 max_encoding_message_size: self.max_encoding_message_size,
600 }
601 }
602 }
603 impl<T: KeyStore> Clone for _Inner<T> {
604 fn clone(&self) -> Self {
605 Self(Arc::clone(&self.0))
606 }
607 }
608 impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
609 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
610 write!(f, "{:?}", self.0)
611 }
612 }
613 impl<T: KeyStore> tonic::server::NamedService for KeyStoreServer<T> {
614 const NAME: &'static str = "keystore.KeyStore";
615 }
616}