Skip to content

Commit bbc1b6e

Browse files
committed
[SPARK-51529] Support TLS connections
### What changes were proposed in this pull request? This PR aims to support TLS connections between `Spark Connect Client for Swift` and `Spark Connect Server`. ### Why are the changes needed? For feature parity. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Manual review. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #82 from dongjoon-hyun/SPARK-51529. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent faae9a3 commit bbc1b6e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Sources/SparkConnect/SparkConnectClient.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public actor SparkConnectClient {
2828
let host: String
2929
let port: Int
3030
let token: String?
31+
var useTLS: Bool = false
32+
let transportSecurity: HTTP2ClientTransport.Posix.TransportSecurity
3133
var intercepters: [ClientInterceptor] = []
3234
let userContext: UserContext
3335
var sessionID: String? = nil
@@ -56,6 +58,10 @@ public actor SparkConnectClient {
5658
token = String(kv[1])
5759
case URIParams.PARAM_USER_ID:
5860
userName = String(kv[1])
61+
case URIParams.PARAM_USE_SSL:
62+
if String(kv[1]).lowercased() == "true" {
63+
self.useTLS = true
64+
}
5965
default:
6066
// Print warning and ignore
6167
print("Unknown parameter: \(param)")
@@ -65,6 +71,11 @@ public actor SparkConnectClient {
6571
if let token = self.token {
6672
self.intercepters.append(BearerTokenInterceptor(token: token))
6773
}
74+
if self.useTLS {
75+
self.transportSecurity = .tls
76+
} else {
77+
self.transportSecurity = .plaintext
78+
}
6879
self.userContext = userName.toUserContext
6980
}
7081

@@ -99,7 +110,7 @@ public actor SparkConnectClient {
99110
try await withGRPCClient(
100111
transport: .http2NIOPosix(
101112
target: .dns(host: self.host, port: self.port),
102-
transportSecurity: .plaintext
113+
transportSecurity: self.transportSecurity
103114
),
104115
interceptors: self.intercepters
105116
) { client in

0 commit comments

Comments
 (0)