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

Sean Whitton spwhitton at spwhitton.name
Thu Mar 10 21:52:09 GMT 2022


Acked-by: Sean Whitton <spwhitton at spwhitton.name>

On Wed 09 Mar 2022 at 08:28pm -04, David Bremner wrote:

> 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   |  4 +++-
>  3 files changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/src/data/pgp.lisp b/src/data/pgp.lisp
> index 90e046b..9120759 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
> +   (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 15e0ab5..cd5644c 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
> @@ -29,3 +30,13 @@ optionally adding extension TYPE. No escaping of special characters is done."
>       (ensure-directory-pathname iden1))
>      (ensure-directory-pathname base-path))
>     nil))
> +
> +(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 ef499a5..d1c5836 100644
> --- a/src/package.lisp
> +++ b/src/package.lisp
> @@ -1005,13 +1005,15 @@
>                               (#:lxc  #:consfigurator.property.lxc)))
>  
>    (package :consfigurator.data.util
> -           (:export #:literal-data-pathname))
> +           (:export #:literal-data-pathname #:gpg-file-as-string))
>  
>    (package :consfigurator.data.asdf)
>  
>    (package :consfigurator.data.pgp
> +           (:use  #:consfigurator.data.util)
>             (:export #:list-data #:get-data #:set-data #:set-data-from-file))
>  
> +
>    (package :consfigurator.data.git-snapshot)
>  
>    (package :consfigurator.data.gpgpubkeys)

-- 
Sean Whitton



More information about the sgo-software-discuss mailing list