Skip to content
Snippets Groups Projects
Unverified Commit 5845dbbe authored by Bryan Maass's avatar Bryan Maass Committed by GitHub
Browse files

make sure we pass :port when creating ssh tunnels (#21775)


* make sure we pass :port when creating ssh tunnels

- if it is not there, use the default port

* pass a default :port every time we incorporate-ssh-tunnel-details

* Update src/metabase/driver/sql_jdbc/connection.clj

remove unused port destructuring

Co-authored-by: default avatarBraden Shepherdson <Braden.Shepherdson@gmail.com>

Co-authored-by: default avatarBraden Shepherdson <Braden.Shepherdson@gmail.com>
parent 20a85afd
Branches
Tags
No related merge requests found
......@@ -96,12 +96,21 @@
{:datasource (DataSources/pooledDataSource datasource (connection-pool/map->properties pool-properties))}
(connection-pool/connection-pool-spec spec pool-properties)))
(defn ^:private default-ssh-tunnel-target-port [driver]
(when-let [port-info (some
#(when (= "port" (:name %)) %)
(driver/connection-properties driver))]
(or (:default port-info)
(:placeholder port-info))))
(defn- create-pool!
"Create a new C3P0 `ComboPooledDataSource` for connecting to the given `database`."
[{:keys [id details], driver :engine, :as database}]
{:pre [(map? database)]}
(log/debug (u/format-color 'cyan (trs "Creating new connection pool for {0} database {1} ..." driver id)))
(let [details-with-tunnel (driver/incorporate-ssh-tunnel-details driver details) ;; If the tunnel is disabled this returned unchanged
(let [details-with-tunnel (driver/incorporate-ssh-tunnel-details ;; If the tunnel is disabled this returned unchanged
driver
(update details :port #(or % (default-ssh-tunnel-target-port driver))))
spec (connection-details->spec driver details-with-tunnel)
properties (data-warehouse-connection-pool-properties driver database)]
(merge
......@@ -244,7 +253,9 @@
"Return an appropriate JDBC connection spec to test whether a set of connection details is valid (i.e., implementing
`can-connect?`)."
[driver details]
(let [details-with-tunnel (driver/incorporate-ssh-tunnel-details driver details)]
(let [details-with-tunnel (driver/incorporate-ssh-tunnel-details
driver
(update details :port #(or % (default-ssh-tunnel-target-port driver))))]
(connection-details->spec driver details-with-tunnel)))
(defn can-connect-with-spec?
......
......@@ -52,7 +52,11 @@
;; actually if we are going to `throw-exceptions` we'll rethrow the original but attempt to humanize the message
;; first
(catch Throwable e
(throw (Exception. (str (driver/humanize-connection-error-message driver (.getMessage e))) e))))
(throw (if-let [message (some->> (.getMessage e)
(driver/humanize-connection-error-message driver)
str)]
(Exception. message e)
e))))
(try
(can-connect-with-details? driver details-map :throw-exceptions)
(catch Throwable e
......
......@@ -50,6 +50,7 @@
callers responsibility to call `close-tunnel` on the returned connection object."
[{:keys [^String tunnel-host ^Integer tunnel-port ^String tunnel-user tunnel-pass tunnel-private-key
tunnel-private-key-passphrase host port]}]
{:pre [(integer? port)]}
(let [^ConnectFuture conn-future (.connect client tunnel-user tunnel-host tunnel-port)
^SessionHolder conn-status (.verify conn-future default-ssh-timeout)
hb-sec (public-settings/ssh-heartbeat-interval-sec)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment