mobc_tonic/
config.rs

1use serde::{Deserialize, Serialize};
2use std::cmp::{max, min};
3
4#[derive(Debug, Serialize, Deserialize, Clone)]
5pub struct ClientConfig {
6    /// URI client connect to
7    pub uri: String,
8    /// domain the cert belongs to
9    pub domain: String,
10    /// CA cert
11    pub ca_cert: String,
12    /// client cert
13    pub client_cert: Option<CertConfig>,
14    /// pool size
15    pub pool_size: u8,
16}
17
18#[derive(Debug, Serialize, Deserialize, Clone)]
19pub struct CertConfig {
20    /// client cert
21    pub cert: String,
22    /// client cert key
23    pub sk: String,
24}
25
26impl ClientConfig {
27    pub fn new(
28        uri: &str,
29        domain: &str,
30        ca_cert: &str,
31        client_cert: Option<CertConfig>,
32        size: u8,
33    ) -> Self {
34        let pool_size = min(16, max(2, size));
35        Self {
36            uri: uri.to_owned(),
37            domain: domain.to_owned(),
38            ca_cert: ca_cert.to_owned(),
39            client_cert,
40            pool_size,
41        }
42    }
43}
44
45impl CertConfig {
46    pub fn new(cert: &str, sk: &str) -> Self {
47        Self {
48            cert: cert.to_owned(),
49            sk: sk.to_owned(),
50        }
51    }
52}