@@ -31,14 +31,14 @@ More advance usage is possible.
31
31
32
32
## Installation
33
33
34
- Via maven and the clojars (http://clojars.org), or
34
+ Via maven and the clojars (http://clojars.org/clj-ssh ), or
35
35
Leiningen (http://github.com/technomancy/leiningen).
36
36
37
37
## License
38
38
39
39
Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)"
40
40
(:use
41
- [clojure.contrib.def :only [defvar ]])
41
+ [clojure.contrib.def :only [defvar defunbound ]])
42
42
(:require
43
43
clj-ssh.keychain
44
44
[clojure.contrib.logging :as logging])
@@ -58,14 +58,26 @@ Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)"
58
58
59
59
60
60
61
- (defvar *ssh-agent* nil " SSH agent used to manage identities." )
61
+ (defunbound *ssh-agent* " SSH agent used to manage identities." )
62
62
(defvar *default-session-options* {} " Default SSH options" )
63
63
64
+
64
65
(defmacro when-feature
65
66
[feature-name & body]
66
- (if (find-var (symbol " clojure.core" (name feature-name)))
67
+ (when (find-var (symbol " clojure.core" (name feature-name)))
67
68
`(do ~@body)))
68
69
70
+ (defmacro when-not-feature
71
+ [feature-name & body]
72
+ (when-not (find-var (symbol " clojure.core" (name feature-name)))
73
+ `(do ~@body)))
74
+
75
+ (when-not-feature
76
+ bound?
77
+ (defn bound?
78
+ [& vars#]
79
+ (every? #(.isBound #^clojure.lang.Var %) vars#)))
80
+
69
81
; ; Enable java logging of jsch when in clojure 1.2
70
82
(when-feature deftype
71
83
(def ssh-log-levels
@@ -152,6 +164,7 @@ Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)"
152
164
(add-identity agent private-key nil )
153
165
(add-identity *ssh-agent* agent private-key)))
154
166
([#^JSch agent private-key #^String passphrase]
167
+ (assert agent)
155
168
(.addIdentity
156
169
agent
157
170
(if (instance? Identity private-key)
@@ -160,6 +173,7 @@ Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)"
160
173
(and passphrase (.getBytes passphrase))))
161
174
([#^JSch agent #^String name #^bytes private-key #^bytes public-key
162
175
#^bytes passphrase]
176
+ (assert agent)
163
177
(.addIdentity
164
178
agent name private-key public-key passphrase)))
165
179
@@ -367,7 +381,7 @@ keys. All other option key pairs will be passed as SSH config options."
367
381
368
382
(defn default-session [host username port password]
369
383
(doto (session-impl
370
- (or *ssh-agent* (create-ssh-agent ))
384
+ (or ( and ( bound? #' *ssh-agent*) *ssh-agent*) (create-ssh-agent ))
371
385
host username port password
372
386
*default-session-options*)
373
387
(.connect )))
0 commit comments