|
|
@@ -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))))
|