-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathconfig.rs
More file actions
96 lines (89 loc) · 3.19 KB
/
config.rs
File metadata and controls
96 lines (89 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
use std::path::PathBuf;
use std::time::Duration;
use serde_derive::Deserialize;
use serde_derive::Serialize;
/// The configuration for either a [`RawClient`](crate::RawClient) or a
/// [`TransactionClient`](crate::TransactionClient).
///
/// See also [`TransactionOptions`](crate::TransactionOptions) which provides more ways to configure
/// requests.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
#[serde(rename_all = "kebab-case")]
pub struct Config {
pub ca_path: Option<PathBuf>,
pub cert_path: Option<PathBuf>,
pub key_path: Option<PathBuf>,
pub timeout: Duration,
pub tcp_keepalive: Option<Duration>,
pub keep_alive_timeout: Duration,
pub dns_server_addr: Option<String>,
pub dns_search_domain: Vec<String>,
}
const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(2);
const DEFAULT_TCP_KEEPALIVE: Duration = Duration::from_secs(10);
const DEFAULT_KEEP_ALIVE_TIMEOUT: Duration = Duration::from_secs(3);
impl Default for Config {
fn default() -> Self {
Config {
ca_path: None,
cert_path: None,
key_path: None,
timeout: DEFAULT_REQUEST_TIMEOUT,
tcp_keepalive: Some(DEFAULT_TCP_KEEPALIVE),
keep_alive_timeout: DEFAULT_KEEP_ALIVE_TIMEOUT,
dns_server_addr: None,
dns_search_domain: vec![],
}
}
}
impl Config {
/// Set the certificate authority, certificate, and key locations for clients.
///
/// By default, this client will use an insecure connection over instead of one protected by
/// Transport Layer Security (TLS). Your deployment may have chosen to rely on security measures
/// such as a private network, or a VPN layer to provide secure transmission.
///
/// To use a TLS secured connection, use the `with_security` function to set the required
/// parameters.
///
/// TiKV does not currently offer encrypted storage (or encryption-at-rest).
///
/// # Examples
/// ```rust
/// # use tikv_client::Config;
/// let config = Config::default().with_security("root.ca", "internal.cert", "internal.key");
/// ```
#[must_use]
pub fn with_security(
mut self,
ca_path: impl Into<PathBuf>,
cert_path: impl Into<PathBuf>,
key_path: impl Into<PathBuf>,
) -> Self {
self.ca_path = Some(ca_path.into());
self.cert_path = Some(cert_path.into());
self.key_path = Some(key_path.into());
self
}
/// Set the timeout for clients.
///
/// The timeout is used for all requests when using or connecting to a TiKV cluster (including
/// PD nodes). If the request does not complete within timeout, the request is cancelled and
/// an error returned to the user.
///
/// The default timeout is two seconds.
///
/// # Examples
/// ```rust
/// # use tikv_client::Config;
/// # use std::time::Duration;
/// let config = Config::default().with_timeout(Duration::from_secs(10));
/// ```
#[must_use]
pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}
}