Skip to content

Instantly share code, notes, and snippets.

@hugoduncan
Created June 1, 2011 18:23
Show Gist options
  • Save hugoduncan/1002932 to your computer and use it in GitHub Desktop.
Save hugoduncan/1002932 to your computer and use it in GitHub Desktop.
record-public-key
(defn record-public-key
"Record a public key"
[session user & {:keys [filename type parameter-path]
:or {type "rsa"} :as options}]
(let [filename (or filename (ssh-default-filenames type))
path (str (user-ssh-dir user) filename ".pub")]
(->
session
(remote-file/with-remote-file
(action/as-clj-action
(fn [session local-path]
(let [pub-key (slurp local-path)]
(if-not (string/blank? pub-key)
(if parameter-path
(parameter/update-for-service
session parameter-path
(fn [keys] (conj (or keys #{}) pub-key)))
(parameter/assoc-for-target
session [:user (keyword user) (keyword filename)] pub-key))
session)))
[session])
path))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment