[PATCH consfigurator] GPG: handle missing file separately to subprocess errors
Russell Sim
rsl at simopolis.xyz
Tue Oct 4 22:00:40 BST 2022
When the gpg data source is missing explicitly signal a
MISSING-DATA-SOURCE condition before calling subpocesses. This makes
the API more consistent with the other data sources.
Signed-off-by: Russell Sim <rsl at simopolis.xyz>
---
src/data/util.lisp | 7 +++----
tests/data/pgp.lisp | 6 ++++++
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/data/util.lisp b/src/data/util.lisp
index aa0451f..ef6cb2c 100644
--- a/src/data/util.lisp
+++ b/src/data/util.lisp
@@ -57,8 +57,7 @@ as a string."
(defun gpg-file-as-string (location)
"Decrypt the contents of a gpg encrypted file at LOCATION, return as a
string."
- (handler-case
+ (if (file-exists-p location)
(gpg (list "--decrypt" (unix-namestring location)))
- (subprocess-error (error)
- (missing-data-source "While attempt to decrypt ~A, gpg exited with ~A"
- location (uiop:subprocess-error-code error)))))
+ (missing-data-source "File not found while attempting to decrypt ~A"
+ location)))
diff --git a/tests/data/pgp.lisp b/tests/data/pgp.lisp
index 21ba60c..a1308bd 100644
--- a/tests/data/pgp.lisp
+++ b/tests/data/pgp.lisp
@@ -19,3 +19,9 @@
(deftest data.pgp.3
(get-data-string "host.example.com" "/etc/foo.conf")
"secret file content")
+
+(deftest data.pgp.4
+ (handler-case (data.pgp:get-data "/tmp/does-not-exist" "_secrets" "test")
+ (missing-data-source (error)
+ (princ-to-string error)))
+ "File not found while attempting to decrypt /tmp/does-not-exist")
--
2.37.2
More information about the sgo-software-discuss
mailing list