-
-
Notifications
You must be signed in to change notification settings - Fork 277
fix: connection URL parsing, SSH key resolution, and export compatibility #902
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
Changes from all commits
5f67ac5
c057efa
53c51a6
9d26dad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ struct ConnectionURLFormatter { | |
|
|
||
| let ssh = connection.resolvedSSHConfig | ||
| if ssh.enabled { | ||
| return formatSSH(connection, sshConfig: ssh, scheme: scheme, password: password) | ||
| return formatSSH(connection, sshConfig: ssh, scheme: scheme, password: password, sshPassword: sshPassword) | ||
| } | ||
|
|
||
| return formatStandard(connection, scheme: scheme, password: password) | ||
|
|
@@ -56,12 +56,17 @@ struct ConnectionURLFormatter { | |
| _ connection: DatabaseConnection, | ||
| sshConfig ssh: SSHConfiguration, | ||
| scheme: String, | ||
| password: String? | ||
| password: String?, | ||
| sshPassword: String? | ||
| ) -> String { | ||
| var result = "\(scheme)+ssh://" | ||
|
|
||
| if !ssh.username.isEmpty { | ||
| result += "\(percentEncodeUserinfo(ssh.username))@" | ||
| result += percentEncodeUserinfo(ssh.username) | ||
| if let sshPassword, !sshPassword.isEmpty { | ||
| result += ":\(percentEncodeUserinfo(sshPassword))" | ||
| } | ||
| result += "@" | ||
| } | ||
| result += ssh.host | ||
| if ssh.port != 22 { | ||
|
|
@@ -83,9 +88,12 @@ struct ConnectionURLFormatter { | |
| result += ":\(connection.port)" | ||
| } | ||
|
|
||
| let sshPathComponent = connection.type == .oracle | ||
| var sshPathComponent = connection.type == .oracle | ||
| ? (connection.oracleServiceName ?? connection.database) | ||
| : connection.database | ||
| if connection.type == .redis, let redisDb = connection.redisDatabase, redisDb > 0 { | ||
| sshPathComponent = String(redisDb) | ||
| } | ||
| result += "/\(sshPathComponent)" | ||
|
|
||
| let query = buildQueryString(connection, sshConfig: ssh) | ||
|
|
@@ -111,14 +119,22 @@ struct ConnectionURLFormatter { | |
| result += "@" | ||
| } | ||
|
|
||
| result += connection.host | ||
| if connection.port != connection.type.defaultPort { | ||
| result += ":\(connection.port)" | ||
| if connection.type.pluginTypeId == "MongoDB", | ||
| let mongoHosts = connection.additionalFields["mongoHosts"], !mongoHosts.isEmpty { | ||
| result += mongoHosts | ||
| } else { | ||
| result += connection.host | ||
| if connection.port != connection.type.defaultPort { | ||
| result += ":\(connection.port)" | ||
| } | ||
| } | ||
|
|
||
| let pathComponent = connection.type == .oracle | ||
| var pathComponent = connection.type == .oracle | ||
| ? (connection.oracleServiceName ?? connection.database) | ||
| : connection.database | ||
| if connection.type == .redis, let redisDb = connection.redisDatabase, redisDb > 0 { | ||
| pathComponent = String(redisDb) | ||
| } | ||
| result += "/\(pathComponent)" | ||
|
|
||
| let query = buildQueryString(connection) | ||
|
|
@@ -178,6 +194,19 @@ struct ConnectionURLFormatter { | |
| params.append("env=\(encoded)") | ||
| } | ||
|
|
||
| if let authSource = connection.mongoAuthSource, !authSource.isEmpty { | ||
| params.append("authSource=\(percentEncodeQueryValue(authSource))") | ||
| } | ||
| if let authMech = connection.mongoAuthMechanism, !authMech.isEmpty { | ||
| params.append("authMechanism=\(percentEncodeQueryValue(authMech))") | ||
| } | ||
| if let replicaSet = connection.mongoReplicaSet, !replicaSet.isEmpty { | ||
| params.append("replicaSet=\(percentEncodeQueryValue(replicaSet))") | ||
| } | ||
| if connection.mongoUseSrv { | ||
| params.append("mongoUseSrv=true") | ||
|
Comment on lines
+206
to
+207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The formatter now emits Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| return params.joined(separator: "&") | ||
| } | ||
|
|
||
|
|
@@ -210,4 +239,11 @@ struct ConnectionURLFormatter { | |
| allowed.remove(charactersIn: ":@") | ||
| return value.addingPercentEncoding(withAllowedCharacters: allowed) ?? value | ||
| } | ||
|
|
||
| private static func percentEncodeQueryValue(_ value: String) -> String { | ||
| value.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)? | ||
| .replacingOccurrences(of: "&", with: "%26") | ||
| .replacingOccurrences(of: "=", with: "%3D") | ||
| ?? value | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When exporting SSH Redis connections, this now writes the selected Redis DB index into the path, but
ConnectionURLParser.parseSSHURLstill hard-codesredisDatabase: niland does not map that path back toParsedConnectionURL.redisDatabase. In practice, copying a Redis-over-SSH URL with DB > 0 and re-opening/importing it reconnects to DB 0 (the connection layer falls back to 0 whenredisDatabaseis nil), so users can run commands against the wrong logical Redis database.Useful? React with 👍 / 👎.