use std::{fs, path::Path};
use tonic::transport::{Certificate, ClientTlsConfig};
#[derive(Debug, Clone)]
pub struct DriverOptions {
is_tls_enabled: bool,
tls_config: Option<ClientTlsConfig>,
}
impl DriverOptions {
pub fn new(is_tls_enabled: bool, tls_root_ca: Option<&Path>) -> crate::Result<Self> {
let tls_config = Some(if let Some(tls_root_ca) = tls_root_ca {
ClientTlsConfig::new().ca_certificate(Certificate::from_pem(fs::read_to_string(tls_root_ca)?))
} else {
ClientTlsConfig::new().with_native_roots()
});
Ok(Self { is_tls_enabled, tls_config })
}
pub fn is_tls_enabled(&self) -> bool {
self.is_tls_enabled
}
pub fn tls_config(&self) -> &Option<ClientTlsConfig> {
&self.tls_config
}
}