From 9282dcd1bc18f9cbf925916fac0d536217d24569 Mon Sep 17 00:00:00 2001 From: Phillip LeBlanc Date: Fri, 20 Sep 2024 12:05:34 +0900 Subject: [PATCH] Use native roots --- core/src/client/mod.rs | 4 ++++ core/src/session.rs | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/src/client/mod.rs b/core/src/client/mod.rs index 0903564..7065634 100644 --- a/core/src/client/mod.rs +++ b/core/src/client/mod.rs @@ -70,6 +70,10 @@ impl ChannelBuilder { format!("http://{}:{}", self.host, self.port) } + pub fn use_ssl(&self) -> bool { + self.use_ssl + } + pub fn token(&self) -> Option { self.token.to_owned() } diff --git a/core/src/session.rs b/core/src/session.rs index 812ae9b..ec88933 100644 --- a/core/src/session.rs +++ b/core/src/session.rs @@ -19,7 +19,7 @@ use arrow::record_batch::RecordBatch; use parking_lot::RwLock; #[cfg(not(feature = "wasm"))] -use tonic::transport::{Channel, Endpoint}; +use tonic::transport::{Channel, ClientTlsConfig, Endpoint}; #[cfg(feature = "wasm")] use tonic_web_wasm_client::Client; @@ -81,10 +81,15 @@ impl SparkSessionBuilder { #[cfg(not(feature = "wasm"))] async fn create_client(&self) -> Result { - let channel = Endpoint::from_shared(self.channel_builder.endpoint()) - .expect("Failed to create endpoint") - .connect() - .await?; + let mut endpoint = Endpoint::from_shared(self.channel_builder.endpoint()) + .expect("Failed to create endpoint"); + + #[cfg(feature = "tls")] + if self.channel_builder.use_ssl() { + endpoint = endpoint.tls_config(ClientTlsConfig::new().with_native_roots())?; + } + + let channel = endpoint.connect().await?; let service_client = SparkConnectServiceClient::with_interceptor( channel,