summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--brisket.hy23
1 files changed, 21 insertions, 2 deletions
diff --git a/brisket.hy b/brisket.hy
index 7e14926..11d0e59 100644
--- a/brisket.hy
+++ b/brisket.hy
@@ -64,12 +64,31 @@ The lookup order is:
(get (get config "Server") "Host"))))
(defn get-user-info [host]
+ "Decode *auth-source* and return the line containing HOST."
(let [process (Popen ["gpg" "-q" "-d" *auth-source*] :stdout PIPE)
- output (first (.communicate process))]
- (for [line output]
+ output (.decode (first (.communicate process)))]
+ (for [line (.split output "\n")]
(when (.startswith line (.format "machine {}" host))
(return line)))))
+(defn get-username [host]
+ "Return the username for HOST as specified by *auth-source*."
+ (let [info (get-user-info host)
+ start-index (.find info "login")]
+ (unless (= -1 start-index)
+ (let [sliced (.split (.join "" (drop start-index info)))]
+ (if (> (len sliced) 1)
+ (.strip (nth sliced 1) "\""))))))
+
+(defn get-password [host]
+ "Return the password for HOST as specified by *auth-source*."
+ (let [info (get-user-info host)
+ start-index (.find info "password")]
+ (unless (= -1 start-index)
+ (let [sliced (.split (.join "" (drop start-index info)))]
+ (if (> (len sliced) 1)
+ (.strip (nth sliced 1) "\""))))))
+
(defn err [&rest args]
"Displays ARGS to stdout."
(.write stderr (+ (first args) "\n") #* (rest args)))