Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native certificate roots for TLS connections #7

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
self.token.to_owned()
}
Expand Down
15 changes: 10 additions & 5 deletions core/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,10 +81,15 @@ impl SparkSessionBuilder {

#[cfg(not(feature = "wasm"))]
async fn create_client(&self) -> Result<SparkSession, SparkError> {
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,
Expand Down