aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-02-21 10:42:10 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-02-21 10:42:24 -0700
commit3d3b0526657556cb986be202b3143c27dc9b319c (patch)
tree2fe72262bf3e3841bac055546aeef757f7a599c8 /src
parent1b14862d157c6ef8b2fa97b4cfa7fc9ef479a3ff (diff)
downloadconsfigurator-3d3b0526657556cb986be202b3143c27dc9b319c.tar.gz
have PGP data source signal MISSING-DATA-SOURCE
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src')
-rw-r--r--src/data.lisp6
-rw-r--r--src/data/pgp.lisp22
-rw-r--r--src/package.lisp1
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