secrets.lisp 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. (in-package #:chatikbot)
  2. (defvar *secret-ring* nil "GPG keyring path")
  3. (defvar *secret-pass-store* nil "pass store dir")
  4. (defvar *secret-pass-bin* "pass" "pass util binary")
  5. (defun %secret/pass (cmd path &key input (output :string) error-output)
  6. (let ((input-stream (when input (make-string-input-stream input))))
  7. (unwind-protect
  8. (uiop:run-program
  9. (format nil "~@[GNUPGHOME=~A ~]~@[PASSWORD_STORE_DIR=~A ~]~A ~A~@[ ~{~A~^/~}~]"
  10. *secret-ring* *secret-pass-store* *secret-pass-bin*
  11. cmd path)
  12. :input input-stream :output output :error-output error-output)
  13. (when input-stream
  14. (close input-stream)))))
  15. (defun secret/get (path)
  16. (%secret/pass "show" path))
  17. (defun secret/set (path value)
  18. (%secret/pass "insert --force --multiline" path :input value))
  19. (defun secret/del (path)
  20. (%secret/pass "rm --force" path))
  21. (defmacro secret/with ((var path) &body body)
  22. `(let ((,var (ignore-errors (secret/get ,path))))
  23. (unwind-protect
  24. (progn ,@body)
  25. (fill ,var #\Space))))