cli_shared/
client_config.rs1use wire::AuthToken;
5
6#[derive(Debug, Clone)]
8pub struct ClientConfig {
9 pub client_id: String,
11 pub token: Option<AuthToken>,
13 pub auth_proof_key_pem: Option<String>,
15 pub server_key: Option<String>,
18 pub tls_enabled: bool,
20 pub tls_domain_name: Option<String>,
22 pub tls_ca_certificate_pem: Option<String>,
24 pub tls_skip_verify: bool,
26 pub timeout_secs: u64,
28 pub compression: bool,
30 pub chunk_size: usize,
32 pub chunked_transfer: bool,
34 pub resumable_transfer: bool,
36 pub pack_transfer: bool,
38 pub partial_fetch: bool,
40}
41
42impl ClientConfig {
43 pub fn new(client_id: impl Into<String>) -> Self {
45 Self {
46 client_id: client_id.into(),
47 token: None,
48 auth_proof_key_pem: None,
49 server_key: None,
50 tls_enabled: false,
51 tls_domain_name: None,
52 tls_ca_certificate_pem: None,
53 tls_skip_verify: false,
54 timeout_secs: 30,
55 compression: true,
56 chunk_size: 64 * 1024,
57 chunked_transfer: true,
58 resumable_transfer: true,
59 pack_transfer: true,
60 partial_fetch: true,
61 }
62 }
63
64 pub fn with_token(mut self, token: AuthToken) -> Self {
66 self.token = Some(token);
67 self
68 }
69
70 pub fn with_auth_proof_key_pem(mut self, pem: impl Into<String>) -> Self {
72 self.auth_proof_key_pem = Some(pem.into());
73 self
74 }
75
76 pub fn with_server_key(mut self, key: impl Into<String>) -> Self {
78 self.server_key = Some(key.into());
79 self
80 }
81
82 pub fn with_tls(mut self, skip_verify: bool) -> Self {
84 self.tls_enabled = true;
85 self.tls_skip_verify = skip_verify;
86 self
87 }
88
89 pub fn with_tls_domain_name(mut self, domain_name: impl Into<String>) -> Self {
90 self.tls_domain_name = Some(domain_name.into());
91 self
92 }
93
94 pub fn with_tls_ca_certificate_pem(mut self, pem: impl Into<String>) -> Self {
95 self.tls_enabled = true;
96 self.tls_ca_certificate_pem = Some(pem.into());
97 self
98 }
99
100 pub fn with_timeout(mut self, secs: u64) -> Self {
102 self.timeout_secs = secs;
103 self
104 }
105
106 pub fn without_compression(mut self) -> Self {
108 self.compression = false;
109 self
110 }
111
112 pub fn with_chunk_size(mut self, size: usize) -> Self {
114 self.chunk_size = size;
115 self
116 }
117
118 pub fn with_chunked_transfer(mut self, enabled: bool) -> Self {
120 self.chunked_transfer = enabled;
121 self
122 }
123
124 pub fn with_resumable_transfer(mut self, enabled: bool) -> Self {
126 self.resumable_transfer = enabled;
127 self
128 }
129
130 pub fn with_pack_transfer(mut self, enabled: bool) -> Self {
132 self.pack_transfer = enabled;
133 self
134 }
135
136 pub fn with_partial_fetch(mut self, enabled: bool) -> Self {
138 self.partial_fetch = enabled;
139 self
140 }
141}
142
143impl Default for ClientConfig {
144 fn default() -> Self {
145 Self::new("heddle-client")
146 }
147}