[gnus git] branch master updated: m0-9-60-g16f18e1 =1= auth-source.el: Build correct secrets pattern from auth-source pattern

Katsumi Yamaoka <[email protected]> Sat, 22 Feb 2014 09:05:54 +0100
Newsgroups gmane.emacs.gnus.cvs
Message-ID <[email protected]>
       via  16f18e1c694f315aa35174d61f9f7d6cfc100506 (commit)
      from  569c0da04cadc14d980f784be1134f3097f38b25 (commit)


- Log -----------------------------------------------------------------
commit 16f18e1c694f315aa35174d61f9f7d6cfc100506
Author: Daniel Colascione <[email protected]>
Date:   Sat Feb 22 08:05:43 2014 +0000

    auth-source.el: Build correct secrets pattern from auth-source pattern

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2184631..828d3d9 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2014-02-22  Daniel Colascione  <[email protected]>
+
+	* auth-source.el (auth-source-secrets-listify-pattern): New function.
+	(auth-source-secrets-search): Don't pass invalid patterns to secrets.el;
+	instead, build list of patterns.
+
 2014-02-17  Katsumi Yamaoka  <[email protected]>
 
 	* gnus-art.el (gnus-article-prepare, gnus-article-prepare-display):
diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index 5084a15..103b66e 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -1516,6 +1516,31 @@ Respects `auth-source-save-behavior'.  Uses
 ;; (let ((auth-sources '("secrets:Login"))) (auth-source-search :max 1))
 ;; (let ((auth-sources '("secrets:Login"))) (auth-source-search :max 1 :signon_realm "https://git.gnus.org/Git"))
 
+(defun auth-source-secrets-listify-pattern (pattern)
+  "Convert a pattern with lists to a list of string patterns.
+
+auth-source patterns can have values of the form :foo (\"bar\"
+\"qux\"), which means to match any secret with :foo equal to
+\"bar\" otr :foo equal to \"qux\".  The secrets backend supports
+only string values for patterns, so this routine returns a list
+of patterns that is equivalent to the single original pattern
+when interpreted such that if a secret matches any pattern in the
+list, it mathces the original pattern."
+  (if (null pattern)
+      '(nil)
+    (let* ((key (pop pattern))
+           (value (pop pattern))
+           (tails (auth-source-secrets-listify-pattern pattern))
+           (heads (if (stringp value)
+                      (list (list key value))
+                    (mapcar (lambda (v) (list key v)) value))))
+      (cl-loop
+         for h in heads
+         nconc
+           (cl-loop
+              for tl in tails
+              collect (append h tl))))))
+
 (defun* auth-source-secrets-search (&rest
                                     spec
                                     &key backend create delete label
@@ -1568,21 +1593,25 @@ authentication tokens:
                             collect (nth i spec)))
          ;; build a search spec without the ignored keys
          ;; if a search key is nil or t (match anything), we skip it
-         (search-spec (apply 'append (mapcar
+         (search-specs (auth-source-secrets-listify-pattern
+                        (apply 'append (mapcar
                                       (lambda (k)
                                         (if (or (null (plist-get spec k))
                                                 (eq t (plist-get spec k)))
                                             nil
                                           (list k (plist-get spec k))))
-                                      search-keys)))
+                                      search-keys))))
          ;; needed keys (always including host, login, port, and secret)
          (returned-keys (mm-delete-duplicates (append
                                                '(:host :login :port :secret)
                                                search-keys)))
-         (items (loop for item in (apply 'secrets-search-items coll search-spec)
+         (items
+          (loop for search-spec in search-specs
+               nconc
+               (loop for item in (apply 'secrets-search-items coll search-spec)
                   unless (and (stringp label)
                               (not (string-match label item)))
-                      collect item))
+                  collect item)))
          ;; TODO: respect max in `secrets-search-items', not after the fact
          (items (butlast items (- (length items) max)))
          ;; convert the item name to a full plist

-----------------------------------------------------------------------
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we listed those
revisions in full, above.

Summary of changes:
 lisp/ChangeLog      |    6 ++++++
 lisp/auth-source.el |   41 +++++++++++++++++++++++++++++++++++------
 2 files changed, 41 insertions(+), 6 deletions(-)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnus Project".

The branch, master has been updated


hooks/post-receive
-- 
Gnus Project