[PATCH consfigurator 2/3] factor out gpg-file-as-string

David Bremner david at tethera.net
Sat Feb 19 19:43:42 GMT 2022


This will allow re-use in a new data source based on the pass(1) data store.
---
 src/data/pgp.lisp  | 10 ++--------
 src/data/util.lisp | 11 +++++++++++
 src/package.lisp   |  5 +++--
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/data/pgp.lisp b/src/data/pgp.lisp
index 90e046b..7f3179b 100644
--- a/src/data/pgp.lisp
+++ b/src/data/pgp.lisp
@@ -51,14 +51,8 @@
       (cons #'check #'extract))))
 
 (defun read-store (location)
-  (handler-case
-      (safe-read-from-string
-       (run-program
-        (escape-sh-command (list "gpg" "--decrypt" (unix-namestring location)))
-        :output :string))
-    (subprocess-error (error)
-      (missing-data-source "While attempt to decrypt, gpg exited with ~A"
-			   (uiop:subprocess-error-code error)))))
+  (safe-read-from-string
+   (util:gpg-file-as-string location)))
 
 (defun put-store (location data)
   (run-program (list "gpg" "--encrypt")
diff --git a/src/data/util.lisp b/src/data/util.lisp
index 2c9c0d1..857f5be 100644
--- a/src/data/util.lisp
+++ b/src/data/util.lisp
@@ -1,6 +1,7 @@
 ;;; Consfigurator -- Lisp declarative configuration management system
 
 ;;; Copyright (C) 2022 David Bremner <david at tethera.net>
+;;; Copyright (C) 2021  Sean Whitton <spwhitton at spwhitton.name>
 
 ;;; This file is free software; you can redistribute it and/or modify
 ;;; it under the terms of the GNU General Public License as published by
@@ -28,3 +29,13 @@ optionally adding extension TYPE."
     (uiop:relativize-pathname-directory
      (ensure-directory-pathname iden1))
     base-path)))
+
+(defun gpg-file-as-string (location)
+  "Decrypt the contents of a gpg encrypted file, return as a string."
+  (handler-case
+      (run-program
+       (escape-sh-command (list "gpg" "--decrypt" (unix-namestring location)))
+       :output :string)
+    (subprocess-error (error)
+      (missing-data-source "While attempt to decrypt, gpg exited with ~A"
+			   (uiop:subprocess-error-code error)))))
diff --git a/src/package.lisp b/src/package.lisp
index effac88..e8464a7 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -1005,12 +1005,13 @@
                              (#:lxc  #:consfigurator.property.lxc)))
 
   (package :consfigurator.data.util
-           (:export #:data-file-path))
+           (:export #:data-file-path #:gpg-file-as-string))
 
   (package :consfigurator.data.asdf)
 
   (package :consfigurator.data.pgp
-           (:export #:list-data #:get-data #:set-data #:set-data-from-file))
+           (:export #:list-data #:get-data #:set-data #:set-data-from-file)
+           (:local-nicknames (#:util  #:consfigurator.data.util)))
 
   (package :consfigurator.data.git-snapshot)
 
-- 
2.34.1




More information about the sgo-software-discuss mailing list