Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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: 2 additions & 2 deletions apple/Plugins/ClickHouseDriverPlugin/ClickHousePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ nonisolated struct ClickHouseError: Error, PluginDriverError {

static let notConnected = ClickHouseError(message: String(localized: "Not connected to database"))
static let verifyCaNeedsCertificate = ClickHouseError(message: String(localized: """
Verify CA needs a CA certificate. On the connection's Network tab, choose the CA certificate that signed \
Verify CA needs a CA certificate. In the connection's SSL/TLS settings, choose the CA certificate that signed \
the server's certificate, or set SSL Mode to Verify Identity.
"""))
static let clientCertificateNeedsKey = ClickHouseError(message: String(localized: """
A client certificate needs its client key. On the connection's Network tab, choose the client key, or \
A client certificate needs its client key. In the connection's SSL/TLS settings, choose the client key, or \
clear the client certificate.
"""))

Expand Down
2 changes: 1 addition & 1 deletion apple/Plugins/EtcdDriverPlugin/EtcdServerTrust.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal enum EtcdTLSConfigurationError: Error, LocalizedError, Equatable {
switch self {
case .verifyCANeedsCertificate:
return String(localized: """
Verify CA needs a CA certificate. In the etcd section of the Options tab, choose the CA Certificate \
Verify CA needs a CA certificate. In the etcd section of the connection's Advanced settings, choose the CA Certificate \
that signed the server's certificate, or set TLS Mode to Verify Identity.
""")
case .unreadableCACertificate(let path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct QdrantTLS: @unchecked Sendable {
let anchor = try anchorCertificate(at: ssl.caCertificatePath, for: verification)
if verification == .caOnly, anchor == nil {
throw QdrantError.configuration(String(localized: """
Verify CA needs a CA certificate. On the connection's Network tab, choose the CA certificate \
Verify CA needs a CA certificate. In the connection's SSL/TLS settings, choose the CA certificate \
that signed the server's certificate, or set SSL Mode to Verify Identity.
"""))
}
Expand Down Expand Up @@ -57,7 +57,7 @@ struct QdrantTLS: @unchecked Sendable {
guard ssl.isEnabled, !certificatePath.isEmpty else { return nil }
guard !keyPath.isEmpty else {
throw QdrantError.configuration(String(localized: """
A client certificate needs its client key. On the connection's Network tab, choose the \
A client certificate needs its client key. In the connection's SSL/TLS settings, choose the \
client key, or clear the client certificate.
"""))
}
Expand Down
14 changes: 7 additions & 7 deletions apple/Plugins/TableProPluginKit/SSLHandshakeError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,24 @@ public enum SSLHandshakeError: Error, LocalizedError, Sendable {
public var recoverySuggestion: String? {
switch self {
case .serverRejectedPlaintext:
return String(localized: "On the connection's Network tab, set SSL Mode to Verify Identity, or to Required to skip the certificate check.")
return String(localized: "In the connection's SSL/TLS settings, set SSL Mode to Verify Identity, or to Required to skip the certificate check.")
case .serverRequiresPlaintext:
return String(localized: "On the connection's Network tab, set SSL Mode to Disabled.")
return String(localized: "In the connection's SSL/TLS settings, set SSL Mode to Disabled.")
case .untrustedCertificate:
return String(localized: """
On the connection's Network tab, choose the server's CA certificate under Verify Identity \
In the connection's SSL/TLS settings, choose the server's CA certificate under Verify Identity \
or Verify CA. Required (skip verify) also connects, but does not check the certificate.
""")
case .hostnameMismatch:
return String(localized: "Change Host to a name the certificate covers.")
case .clientCertRequired:
return String(localized: "Choose the client certificate and key on the connection's Network tab.")
return String(localized: "Choose the client certificate and key in the connection's SSL/TLS settings.")
case .clientKeyPassphraseRequired:
return String(localized: "Enter the Key Passphrase on the connection's Network tab.")
return String(localized: "Enter the Key Passphrase in the connection's SSL/TLS settings.")
case .clientKeyPassphraseIncorrect:
return String(localized: "Correct the Key Passphrase on the connection's Network tab.")
return String(localized: "Correct the Key Passphrase in the connection's SSL/TLS settings.")
case .clientKeyInvalid:
return String(localized: "Check that the Client Key path points to a valid PEM private key.")
return String(localized: "In the connection's SSL/TLS settings, check that the Key under Client Certificates is a valid PEM private key.")
case .cipherMismatch:
return String(localized: "Update the server's TLS configuration or use a newer database server version that supports modern ciphers.")
case .unknown:
Expand Down
4 changes: 2 additions & 2 deletions apple/Plugins/TrinoDriverPlugin/TrinoSSLMapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum TrinoSSLMapping {
if mode == .caOnly, anchor == nil {
throw TrinoError.invalidConfiguration(String(
localized: """
Verify CA needs a CA certificate. On the connection's Network tab, choose the CA certificate \
Verify CA needs a CA certificate. In the connection's SSL/TLS settings, choose the CA certificate \
that signed the server's certificate, or set SSL Mode to Verify Identity.
"""
))
Expand Down Expand Up @@ -53,7 +53,7 @@ enum TrinoSSLMapping {
guard !keyPath.isEmpty else {
throw TrinoError.invalidConfiguration(String(
localized: """
A client certificate needs its client key. On the connection's Network tab, choose the \
A client certificate needs its client key. In the connection's SSL/TLS settings, choose the \
client key, or clear the client certificate.
"""
))
Expand Down
6 changes: 4 additions & 2 deletions apple/TablePro/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

NSWindow.allowsAutomaticWindowTabbing = true
WindowOpener.shared.setWelcomePresenter { WelcomeWindowController.present() }
WindowOpener.shared.setConnectionFormPresenter { ConnectionFormWindowController.present($0) }
WindowOpener.shared.setConnectionFormPresenter { ConnectionEditorWindowController.present($0, facet: $1) }
WindowOpener.shared.setIntegrationsActivityPresenter { IntegrationsActivityWindowController.present() }
WindowOpener.shared.setSettingsPresenter { SettingsWindowController.present($0) }
KeyRepeatFilter.shared.install()
Expand Down Expand Up @@ -178,7 +178,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
guard let plan = QuitApproval.approve() else {
// The connection editors first: their Cancel keeps the app open before anything else is asked or stopped.
guard ConnectionEditorWindowController.prepareToTerminate(), let plan = QuitApproval.approve() else {
AppRelauncher.shared.terminationWasCancelled()
return .terminateCancel
}
Expand All @@ -203,6 +204,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func applicationWillTerminate(_ notification: Notification) {
ConnectionEditorWindowController.closeAllForTermination()
SessionRecoveryTracker.saveOnQuit()
// Synchronously: an actor hop at terminate may never run, which lost a killed session's last turn.
AgentSessionRegistry.shared.persistSynchronouslyForTermination()
Expand Down
6 changes: 5 additions & 1 deletion apple/TablePro/Core/Database/DatabaseManager+Queries.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ extension DatabaseManager {
preparedConfiguration: preparedConfiguration
)
let succeeded = try await driver.testConnection()
result = ConnectionTestResult(succeeded: succeeded, warning: driver.connectionWarning)
result = ConnectionTestResult(
succeeded: succeeded,
warning: driver.connectionWarning,
serverVersion: driver.serverVersion
)
} catch {
let reportedError = await Self.preferredTunnelFailure(replacing: error) {
await self.attributedTunnelFailure(for: connection)
Expand Down
8 changes: 4 additions & 4 deletions apple/TablePro/Core/Plugins/DatabaseType+Registry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ extension DatabaseType {
switch rawValue {
case "PostgreSQL", "Redshift", "CockroachDB":
return String(localized: """
Preferred tries TLS first, falls back to plain. Matches psql and DataGrip defaults. \
Required by AWS RDS, Cloud SQL, Heroku, Supabase, Neon.
Preferred tries TLS first and connects without it when the server offers none. \
Use Required for AWS RDS, Cloud SQL, Heroku, Supabase and Neon.
""")
case "KingbaseES", "StarRocks":
return String(localized: "Preferred tries TLS first, falls back to plain.")
case _ where pluginTypeId == "MySQL":
return String(localized: """
Preferred performs a 2-pass connect: tries TLS first, falls back to plain only on \
SSL handshake errors. Required by Cloud SQL and Azure MySQL.
Preferred tries TLS first and connects without it when the TLS handshake fails. \
Use Required for Cloud SQL and Azure Database for MySQL, which refuse an unencrypted connection.
""")
case "SQL Server":
return String(localized: "Preferred requests TLS; the server decides. Required by SQL Server 2022 and Azure SQL Database.")
Expand Down
10 changes: 7 additions & 3 deletions apple/TablePro/Core/Plugins/PluginDriverAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ final class PluginDriverAdapter: DatabaseDriver, SchemaSwitchable, DatabaseRepor
var connectAttempt: ConnectAttempt?
var connectionMayBeOpen = false
var disconnectInProgress = false
/// Read from the driver when its connect is adopted, so it outlives the `disconnect()` Test Connection
/// makes before anyone asks for it.
// Read from the driver when its connect is adopted, so both outlive the `disconnect()` Test Connection makes
// before anyone asks: a driver forgets its server's version when it disconnects.
var connectionWarning: String?
var signInServerVersion: String?
// Only a yes is kept, so the driver's own code is not asked again on every read.
var buildsBrowseQueries = false
}
Expand All @@ -54,7 +55,7 @@ final class PluginDriverAdapter: DatabaseDriver, SchemaSwitchable, DatabaseRepor
pluginDriver.hasLostConnection || credentialLease?.hasEnded == true
}

var serverVersion: String? { pluginDriver.serverVersion }
var serverVersion: String? { pluginDriver.serverVersion ?? state.withLock { $0.signInServerVersion } }
var connectionWarning: String? { state.withLock { $0.connectionWarning } }
var sessionLexicalState: PluginSessionLexicalState? { pluginDriver.sessionLexicalState }
var parameterStyle: ParameterStyle { pluginDriver.parameterStyle }
Expand Down Expand Up @@ -164,6 +165,7 @@ final class PluginDriverAdapter: DatabaseDriver, SchemaSwitchable, DatabaseRepor
let generation = state.nextConnectGeneration
state.status = .connecting
state.connectionWarning = nil
state.signInServerVersion = nil
state.connectAttempt = ConnectAttempt(generation: generation, gate: gate, deadline: connectionDeadline.instant)
return generation
}
Expand Down Expand Up @@ -355,6 +357,7 @@ final class PluginDriverAdapter: DatabaseDriver, SchemaSwitchable, DatabaseRepor
error: Error?
) {
let warning = succeeded ? pluginDriver.connectionWarning : nil
let version = succeeded ? pluginDriver.serverVersion : nil
let shouldDisconnect = state.withLock { state in
guard let attempt = state.connectAttempt, attempt.generation == generation else {
return false
Expand All @@ -365,6 +368,7 @@ final class PluginDriverAdapter: DatabaseDriver, SchemaSwitchable, DatabaseRepor
state.connectionMayBeOpen = true
state.status = .connected
state.connectionWarning = warning
state.signInServerVersion = version
return false
}
if let error, adopted {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ internal enum ConnectionRecoveryPerformer {
case .openPluginSettings(let pluginId):
opener.openSettings(revealingPlugin: pluginId)
case .editConnection:
opener.openConnectionForm(editing: connection.id)
// A connect refused over its own settings (an SSL mode the driver lacks, an extension) shows as an issue there.
opener.openConnectionForm(editing: connection.id, facet: .firstIssue)
case .openLocalNetworkSettings:
guard let url = localNetworkSettingsURL else { return }
NSWorkspace.shared.open(url)
Expand Down
39 changes: 30 additions & 9 deletions apple/TablePro/Core/Services/Infrastructure/FileOpenPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import AppKit

/// The panel behind File > Open File…, offering everything TablePro can open rather than SQL alone.
// The panel behind File > Open File…, offering everything TablePro can open rather than SQL alone.
@MainActor
internal enum FileOpenPanel {
internal static func present() async -> [URL]? {
Expand All @@ -14,7 +14,7 @@ internal enum FileOpenPanel {
panel.canChooseDirectories = false
panel.message = String(localized: "Select files to open")

let filter = PanelEnableFilter(isEnabled: isOpenable)
let filter = PanelEnableFilter(isEnabled: isOpenable, validate: validate)
panel.delegate = filter
let response = await panel.begin()
withExtendedLifetime(filter) {}
Expand All @@ -23,14 +23,35 @@ internal enum FileOpenPanel {
return panel.urls
}

/// A plain folder stays enabled so the panel can be navigated. A package is a file as far as
/// the user is concerned, and `.tableplugin` is one, so it is classified like any other.
///
/// The name is asked first and settles most of a folder without touching its contents.
private static func isOpenable(_ url: URL) -> Bool {
let values = try? url.resourceValues(forKeys: [.isDirectoryKey, .isPackageKey])
// A plain folder stays enabled so the panel can be navigated; a package such as `.tableplugin` is classified
// like a file. The name settles most of a folder, and a file whose name says nothing is left for `validate`.
internal static func isOpenable(_ url: URL) -> Bool {
let values = try? url.resourceValues(forKeys: [.isDirectoryKey, .isPackageKey, .fileResourceTypeKey])
if values?.isDirectory == true, values?.isPackage != true { return true }
if case .some(.success) = URLClassifier.classifyByName(url) { return true }
return PanelEnableFilter.isQuickToRead(url) && DatabaseFileClassifier.classify(url) != nil
return values?.fileResourceType == .regular && PanelFileName.leavesKindOpen(url)
}

// A file whose bytes are not on this Mac yet is let through; opening it decides, as a drop or a Finder open does.
internal static func validate(_ url: URL) throws {
if case .some(.success) = URLClassifier.classifyByName(url) { return }
if DatabaseFileClassifier.classify(url, access: .withoutWaiting) != nil { return }
guard DatabaseFileClassifier.isReadableWithoutWaiting(url) else { return }
throw FileOpenPanelError.unsupported(fileName: url.lastPathComponent)
}
}

private enum FileOpenPanelError: LocalizedError {
case unsupported(fileName: String)

var errorDescription: String? {
switch self {
case .unsupported(let fileName):
return String(format: String(localized: "TablePro can’t open “%@”."), fileName)
}
}

var recoverySuggestion: String? {
String(localized: "TablePro opens database files, SQL files, data files, connection shares and plugins.")
}
}
Loading
Loading