(in-package #:chatikbot) (defvar *secret-ring* nil "GPG keyring path") (defvar *secret-pass-store* nil "pass store dir") (defvar *secret-pass-bin* "pass" "pass util binary") (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) (handler-case (let ((*read-eval* nil)) (values (read-from-string (%secret/pass "show" path)))) (error (e) (log:error "~A" e) (values)))) (defun secret/set (path value) (%secret/pass "insert --force --multiline" path :input (prin1-to-string value))) (defun secret/del (path) (%secret/pass "rm --force" path)) (defmacro secret/with ((var path) &body body) `(let ((,var (ignore-errors (secret/get ,path)))) (unwind-protect (progn ,@body) (fill ,var #\Space))))