in Sources/SparkConnect/SparkConnectClient.swift [41:80]
init(remote: String) {
self.url = URL(string: remote)!
self.host = url.host() ?? "localhost"
self.port = self.url.port ?? 15002
var token: String? = nil
let processInfo = ProcessInfo.processInfo
#if os(macOS) || os(Linux)
var userName = processInfo.environment["SPARK_USER"] ?? processInfo.userName
#else
var userName = processInfo.environment["SPARK_USER"] ?? ""
#endif
for param in self.url.path.split(separator: ";").dropFirst().filter({ !$0.isEmpty }) {
let kv = param.split(separator: "=")
switch String(kv[0]).lowercased() {
case URIParams.PARAM_USER_AGENT:
clientType = String(kv[1])
case URIParams.PARAM_TOKEN:
token = String(kv[1])
case URIParams.PARAM_USER_ID:
userName = String(kv[1])
case URIParams.PARAM_USE_SSL:
if String(kv[1]).lowercased() == "true" {
self.useTLS = true
}
default:
// Print warning and ignore
print("Unknown parameter: \(param)")
}
}
self.token = token ?? ProcessInfo.processInfo.environment["SPARK_CONNECT_AUTHENTICATE_TOKEN"]
if let token = self.token {
self.intercepters.append(BearerTokenInterceptor(token: token))
}
if self.useTLS {
self.transportSecurity = .tls
} else {
self.transportSecurity = .plaintext
}
self.userContext = userName.toUserContext
}