Innocenty Enikeev пре 8 година
родитељ
комит
34d7ec2a7e
1 измењених фајлова са 15 додато и 12 уклоњено
  1. 15 12
      secrets.lisp

+ 15 - 12
secrets.lisp

@@ -4,22 +4,25 @@
 (defvar *secret-pass-store* nil "pass store dir")
 (defvar *secret-pass-bin* "pass" "pass util binary")
 
-(defun %secret/pass (args &key input output error-output)
-  (ignore-errors
-    (uiop:run-program
-     (format nil "~@[GNUPGHOME=~A ~]~@[PASSWORD_STORE_DIR=~A ~]~A ~A"
-             *secret-ring* *secret-pass-store* *secret-pass-bin*
-             args)
-     :input input :output output :error-output error-output)))
+(defun %secret/pass (cmd path &key input (output :string) error-output)
+  (let ((input-stream (when input (make-string-input-stream input))))
+    (unwind-protect
+         (uiop:run-program
+          (format nil "~@[GNUPGHOME=~A ~]~@[PASSWORD_STORE_DIR=~A ~]~A ~A~@[ ~{~A~^/~}~]"
+                  *secret-ring* *secret-pass-store* *secret-pass-bin*
+                  cmd path)
+          :input input-stream :output output :error-output error-output)
+      (when input-stream
+        (close input-stream)))))
 
 (defun secret/get (path)
-  (%secret/pass (format nil "show ~{~A~^/~}" path)
-                :output :string))
+  (%secret/pass "show" path))
 
 (defun secret/set (path value)
-  (with-input-from-string (input value)
-    (%secret/pass (format nil "insert --force  --multiline ~{~A~^/~}" path)
-                  :input input :output :string)))
+  (%secret/pass "insert --force --multiline" path :input value))
+
+(defun secret/del (path)
+  (%secret/pass "rm --force" path))
 
 (defmacro secret/with ((var path) &body body)
   `(let ((,var (ignore-errors (secret/get ,path))))