From 3d3b0526657556cb986be202b3143c27dc9b319c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 21 Feb 2021 10:42:10 -0700 Subject: have PGP data source signal MISSING-DATA-SOURCE Signed-off-by: Sean Whitton --- src/data.lisp | 6 ++++++ src/data/pgp.lisp | 22 ++++++++++++++-------- src/package.lisp | 1 + 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/data.lisp b/src/data.lisp index 2fb7021..decc208 100644 --- a/src/data.lisp +++ b/src/data.lisp @@ -88,6 +88,12 @@ Signals a condition MISSING-DATA-SOURCE when unable to access the data source all new Lisp images started up by Consfigurator, since prerequisite data sources are not expected to be available outside of the root Lisp.")) +(define-condition missing-data-source (error) + ((text :initarg :text :reader missing-data-source-text)) + (:report (lambda (condition stream) + (format stream "Missing data source: ~A" + (missing-data-source-text condition))))) + (defvar *data-sources* nil "Known sources of prerequisite data.") (defvar *data-source-registrations* nil diff --git a/src/data/pgp.lisp b/src/data/pgp.lisp index 22cfed2..cff64ac 100644 --- a/src/data/pgp.lisp +++ b/src/data/pgp.lisp @@ -23,11 +23,14 @@ ;; user to call at the REPL to add pieces of data, see what's there, etc. (a ;; prerequisite data source which was some sort of external file-generating or ;; secrets storage database might not provide any functions for the REPL). +;; +;; You will need to touch(1) the file you wish to use before trying to +;; register it. (defmethod register-data-source ((type (eql :pgp)) &key location) (unless (file-exists-p location) - (with-open-file (s location :direction :output) - (print "" s))) + (error 'missing-data-source + :text (format nil "Could not open ~A" location))) (let ((mod (file-write-date location)) (cache (read-store location))) (labels ((update-cache () @@ -43,12 +46,15 @@ (cons #'check #'extract)))) (defun read-store (location) - (unless (file-exists-p location) - (error "~A does not exist!" location)) - (read-from-string - (run-program - (escape-sh-command (list "gpg" "--decrypt" (unix-namestring location))) - :output :string))) + (handler-case + (read-from-string + (run-program + (escape-sh-command (list "gpg" "--decrypt" (unix-namestring location))) + :output :string)) + (subprocess-error (error) + (error 'missing-data-source + :text (format nil "While attempt to decrypt, gpg exited with ~A" + (uiop:subprocess-error-code error)))))) (defun put-store (location data) (run-program (list "gpg" "--encrypt") diff --git a/src/package.lisp b/src/package.lisp index 4bcc42d..e43f251 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -107,6 +107,7 @@ #:data-string #:file-data #:data-file + #:missing-data-source #:try-register-data-source #:register-data-source -- cgit v1.2.3