use proto::AuthToken;
#[derive(Debug, Clone)]
pub struct ClientConfig {
pub client_id: String,
pub token: Option<AuthToken>,
pub auth_proof_key_pem: Option<String>,
pub server_key: Option<String>,
pub tls_enabled: bool,
pub tls_domain_name: Option<String>,
pub tls_ca_certificate_pem: Option<String>,
pub tls_skip_verify: bool,
pub timeout_secs: u64,
pub compression: bool,
pub chunk_size: usize,
pub chunked_transfer: bool,
pub resumable_transfer: bool,
pub pack_transfer: bool,
pub partial_fetch: bool,
}
impl ClientConfig {
pub fn new(client_id: impl Into<String>) -> Self {
Self {
client_id: client_id.into(),
token: None,
auth_proof_key_pem: None,
server_key: None,
tls_enabled: false,
tls_domain_name: None,
tls_ca_certificate_pem: None,
tls_skip_verify: false,
timeout_secs: 30,
compression: true,
chunk_size: 64 * 1024,
chunked_transfer: true,
resumable_transfer: true,
pack_transfer: true,
partial_fetch: true,
}
}
pub fn with_token(mut self, token: AuthToken) -> Self {
self.token = Some(token);
self
}
pub fn with_auth_proof_key_pem(mut self, pem: impl Into<String>) -> Self {
self.auth_proof_key_pem = Some(pem.into());
self
}
pub fn with_server_key(mut self, key: impl Into<String>) -> Self {
self.server_key = Some(key.into());
self
}
pub fn with_tls(mut self, skip_verify: bool) -> Self {
self.tls_enabled = true;
self.tls_skip_verify = skip_verify;
self
}
pub fn with_tls_domain_name(mut self, domain_name: impl Into<String>) -> Self {
self.tls_domain_name = Some(domain_name.into());
self
}
pub fn with_tls_ca_certificate_pem(mut self, pem: impl Into<String>) -> Self {
self.tls_enabled = true;
self.tls_ca_certificate_pem = Some(pem.into());
self
}
pub fn with_timeout(mut self, secs: u64) -> Self {
self.timeout_secs = secs;
self
}
pub fn without_compression(mut self) -> Self {
self.compression = false;
self
}
pub fn with_chunk_size(mut self, size: usize) -> Self {
self.chunk_size = size;
self
}
pub fn with_chunked_transfer(mut self, enabled: bool) -> Self {
self.chunked_transfer = enabled;
self
}
pub fn with_resumable_transfer(mut self, enabled: bool) -> Self {
self.resumable_transfer = enabled;
self
}
pub fn with_pack_transfer(mut self, enabled: bool) -> Self {
self.pack_transfer = enabled;
self
}
pub fn with_partial_fetch(mut self, enabled: bool) -> Self {
self.partial_fetch = enabled;
self
}
}
impl Default for ClientConfig {
fn default() -> Self {
Self::new("heddle-client")
}
}