diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org> | 2019-04-26 12:26:33 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org> | 2019-04-26 12:26:33 -0400 |
| commit | 22ab0dd01fd2d389959ce33652f3c9b2fab2b20b (patch) | |
| tree | 34ede26ac831d212f532bd321bdcdbc6f2b04e1f | |
| parent | 33068122ef1300f97787002fc1411413c3fd47f1 (diff) | |
Add functionality for obtaining auth credentials
| -rw-r--r-- | brisket.hy | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -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))) |