use std::path::PathBuf;
use std::time::Duration;
use serde_derive::Deserialize;
use serde_derive::Serialize;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
pub struct Config {
pub ca_path: Option<PathBuf>,
pub cert_path: Option<PathBuf>,
pub key_path: Option<PathBuf>,
pub timeout: Duration,
pub grpc_max_decoding_message_size: usize,
pub keyspace: Option<String>,
}
const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(2);
const DEFAULT_GRPC_MAX_DECODING_MESSAGE_SIZE: usize = 4 * 1024 * 1024;
impl Default for Config {
fn default() -> Self {
Config {
ca_path: None,
cert_path: None,
key_path: None,
timeout: DEFAULT_REQUEST_TIMEOUT,
grpc_max_decoding_message_size: DEFAULT_GRPC_MAX_DECODING_MESSAGE_SIZE,
keyspace: None,
}
}
}
impl Config {
#[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
}
#[must_use]
pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}
#[must_use]
pub fn with_grpc_max_decoding_message_size(mut self, size: usize) -> Self {
self.grpc_max_decoding_message_size = size;
self
}
#[must_use]
pub fn with_default_keyspace(self) -> Self {
self.with_keyspace("DEFAULT")
}
#[must_use]
pub fn with_keyspace(mut self, keyspace: &str) -> Self {
self.keyspace = Some(keyspace.to_owned());
self
}
}