|
3 | 3 | (:require
|
4 | 4 | [clojure.tools.logging :as logging])
|
5 | 5 | (:import
|
6 |
| - com.jcraft.jsch.JSch |
7 |
| - [com.jcraft.jsch.agentproxy |
8 |
| - AgentProxyException Connector RemoteIdentityRepository] |
9 |
| - [com.jcraft.jsch.agentproxy.connector |
10 |
| - PageantConnector SSHAgentConnector] |
11 |
| - com.jcraft.jsch.agentproxy.usocket.JNAUSocketFactory)) |
| 6 | + [com.jcraft.jsch |
| 7 | + JSch AgentProxyException AgentIdentityRepository |
| 8 | + PageantConnector SSHAgentConnector JUnixSocketFactory])) |
12 | 9 |
|
13 | 10 | (defn sock-agent-connector
|
14 | 11 | []
|
15 |
| - (when (SSHAgentConnector/isConnectorAvailable) |
16 |
| - (try |
17 |
| - (let [usf (JNAUSocketFactory.)] |
18 |
| - (SSHAgentConnector. usf)) |
19 |
| - (catch AgentProxyException e |
20 |
| - (logging/warnf |
21 |
| - e "Failed to load JNA connector, although SSH_AUTH_SOCK is set"))))) |
| 12 | + (try |
| 13 | + (let [con (SSHAgentConnector.)] |
| 14 | + (when (.isAvailable con) |
| 15 | + con)) |
| 16 | + (catch AgentProxyException e |
| 17 | + (logging/warnf |
| 18 | + e "Failed to load JNA connector, although SSH_AUTH_SOCK is set")))) |
22 | 19 |
|
23 | 20 | (defn pageant-connector
|
24 | 21 | []
|
25 |
| - (when (PageantConnector/isConnectorAvailable) |
26 |
| - (try |
27 |
| - (PageantConnector.) |
28 |
| - (catch AgentProxyException e |
29 |
| - (logging/warn |
30 |
| - e "Failed to load Pageant connector, although running on windows"))))) |
| 22 | + (try |
| 23 | + (let [con (PageantConnector.)] |
| 24 | + (when (.isAvailable con) |
| 25 | + con)) |
| 26 | + (catch AgentProxyException e |
| 27 | + (logging/warn |
| 28 | + e "Failed to load Pageant connector, although running on windows")))) |
31 | 29 |
|
32 | 30 | (defn connect
|
33 | 31 | "Connect the specified jsch object to the system ssh-agent."
|
34 | 32 | [^JSch jsch]
|
35 | 33 | (when-let [connector (or (sock-agent-connector) (pageant-connector))]
|
36 | 34 | (doto jsch
|
37 | 35 | ;(.setConfig "PreferredAuthentications" "publickey")
|
38 |
| - (.setIdentityRepository (RemoteIdentityRepository. connector))))) |
| 36 | + (.setIdentityRepository (AgentIdentityRepository. connector))))) |
0 commit comments