[PATCH consfigurator 3/3] introduce the pass data store.
David Bremner
david at tethera.net
Sat Feb 19 19:43:43 GMT 2022
In this initial version, only IDEN1 of the form '--user-passwd-HOST' is
supported.
---
consfigurator.asd | 1 +
src/data/pass.lisp | 60 ++++++++++++++++++++++++++++++++++++++++++++++
src/package.lisp | 3 +++
3 files changed, 64 insertions(+)
create mode 100644 src/data/pass.lisp
diff --git a/consfigurator.asd b/consfigurator.asd
index d159ba0..c542879 100644
--- a/consfigurator.asd
+++ b/consfigurator.asd
@@ -95,6 +95,7 @@
(:file "src/data/gpgpubkeys")
(:file "src/data/ssh-askpass")
(:file "src/data/local-file")
+ (:file "src/data/pass")
(:file "src/data/files-tree"))
:in-order-to ((test-op (test-op "consfigurator/tests"))))
diff --git a/src/data/pass.lisp b/src/data/pass.lisp
new file mode 100644
index 0000000..fea1c3a
--- /dev/null
+++ b/src/data/pass.lisp
@@ -0,0 +1,60 @@
+;;; Consfigurator -- Lisp declarative configuration management system
+
+;;; Copyright (C) 2022 David Bremner <david at tethera.net>
+
+;;; 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
+;;; the Free Software Foundation; either version 3, or (at your option)
+;;; any later version.
+
+;;; This file is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+(in-package :consfigurator.data.pass)
+(named-readtables:in-readtable :consfigurator)
+
+(define-constant =prefix= "--user-passwd-" :test #'equal)
+
+(defun %read-gpg (location)
+ (string-right-trim
+ '(#\Return #\Newline)
+ (util:gpg-file-as-string location)))
+
+(defmethod register-data-source ((type (eql :pass)) &key (location "~/.password-store"))
+ "Provide the contents of a pass(1) on the machine running the root
+Lisp. Register this data source multiple times to provide multiple stores.
+
+LOCATION specifies the root of the password store.
+
+When retrieving a password, IDEN1 should be specified as `--user-passwd-HOST'
+and IDEN2 as username. HOST does not need to be an actual hostname and is
+interpreted as a directory in the password store. In particular HOST may
+contain one or more occurences of `/'."
+ (let ((base-path (ensure-directory-pathname (uiop:native-namestring location))))
+ (unless (directory-exists-p base-path)
+ (missing-data-source
+ "~A does not exist, or is not a directory." base-path))
+ (labels ((%make-path (iden1 iden2)
+ (when-let ((host (and (string-prefix-p =prefix= iden1)
+ (subseq iden1 (length =prefix=)))))
+ (util:data-file-path base-path host iden2 :type "gpg")))
+ (check (iden1 iden2)
+ (when-let ((file-path (%make-path iden1 iden2)))
+ (informat 4 "~&checking pass ~a ~a ~a" iden1 iden2 file-path)
+ (and (file-exists-p file-path)
+ (file-write-date file-path))))
+ (extract (iden1 iden2)
+ (when-let ((file-path (%make-path iden1 iden2)))
+ (informat 4 "~&extracting from pass ~a ~a ~a" iden1 iden2 file-path)
+ (and (file-exists-p file-path)
+ (make-instance 'string-data
+ :string (%read-gpg file-path)
+ :iden1 iden1
+ :iden2 iden2
+ :version (file-write-date file-path))))))
+ (cons #'check #'extract))))
diff --git a/src/package.lisp b/src/package.lisp
index e8464a7..c4d834e 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -1022,5 +1022,8 @@
(package :consfigurator.data.local-file)
+ (package :consfigurator.data.pass
+ (:local-nicknames (#:util #:consfigurator.data.util)))
+
(package :consfigurator.data.files-tree
(:local-nicknames (#:util #:consfigurator.data.util))))
--
2.34.1
More information about the sgo-software-discuss
mailing list