[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 19e642f: Extend secrets.el by searching for object
From: |
Michael Albinus |
Subject: |
[Emacs-diffs] master 19e642f: Extend secrets.el by searching for object paths. |
Date: |
Tue, 22 May 2018 05:32:41 -0400 (EDT) |
branch: master
commit 19e642fdb07b0b6522983e2fa35872ba5fb9f75e
Author: Michael Albinus <address@hidden>
Commit: Michael Albinus <address@hidden>
Extend secrets.el by searching for object paths.
* lisp/net/secrets.el (secrets-search-item-paths): New function.
(secrets-search-items): Use it.
(secrets-create-item): Adapt docstring.
* test/lisp/net/secrets-tests.el (secrets-test04-search): Extend test.
---
lisp/net/secrets.el | 43 ++++++++++++++++++++++++------------------
test/lisp/net/secrets-tests.el | 5 ++++-
2 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/lisp/net/secrets.el b/lisp/net/secrets.el
index 45c98ca..ca75d95 100644
--- a/lisp/net/secrets.el
+++ b/lisp/net/secrets.el
@@ -602,16 +602,16 @@ If successful, return the object path of the collection."
(secrets-get-item-property item-path "Label"))
(secrets-get-items collection-path)))))
-(defun secrets-search-items (collection &rest attributes)
+(defun secrets-search-item-paths (collection &rest attributes)
"Search items in COLLECTION with ATTRIBUTES.
ATTRIBUTES are key-value pairs. The keys are keyword symbols,
starting with a colon. Example:
- (secrets-search-items \"Tramp collection\" :user \"joe\")
+ (secrets-search-item-paths \"Tramp collection\" :user \"joe\")
-The object labels of the found items are returned as list."
+The object paths of the found items are returned as list."
(let ((collection-path (secrets-unlock-collection collection))
- result props)
+ props)
(unless (secrets-empty-path collection-path)
;; Create attributes list.
(while (consp (cdr attributes))
@@ -626,23 +626,30 @@ The object labels of the found items are returned as
list."
,(cadr attributes))))
attributes (cddr attributes)))
;; Search. The result is a list of object paths.
- (setq result
- (dbus-call-method
- :session secrets-service collection-path
- secrets-interface-collection "SearchItems"
- (if props
- (cons :array props)
- '(:array :signature "{ss}"))))
- ;; Return the found items.
- (mapcar
- (lambda (item-path) (secrets-get-item-property item-path "Label"))
- result))))
+ (dbus-call-method
+ :session secrets-service collection-path
+ secrets-interface-collection "SearchItems"
+ (if props
+ (cons :array props)
+ '(:array :signature "{ss}"))))))
+
+(defun secrets-search-items (collection &rest attributes)
+ "Search items in COLLECTION with ATTRIBUTES.
+ATTRIBUTES are key-value pairs. The keys are keyword symbols,
+starting with a colon. Example:
+
+ (secrets-search-items \"Tramp collection\" :user \"joe\")
+
+The object labels of the found items are returned as list."
+ (mapcar
+ (lambda (item-path) (secrets-get-item-property item-path "Label"))
+ (apply 'secrets-search-item-paths collection attributes)))
(defun secrets-create-item (collection item password &rest attributes)
"Create a new item in COLLECTION with label ITEM and password PASSWORD.
-The label ITEM must not be unique in COLLECTION. ATTRIBUTES are
-key-value pairs set for the created item. The keys are keyword
-symbols, starting with a colon. Example:
+The label ITEM does not have to be unique in COLLECTION.
+ATTRIBUTES are key-value pairs set for the created item. The
+keys are keyword symbols, starting with a colon. Example:
(secrets-create-item \"Tramp collection\" \"item\" \"geheim\"
:method \"sudo\" :user \"joe\" :host \"remote-host\")
diff --git a/test/lisp/net/secrets-tests.el b/test/lisp/net/secrets-tests.el
index 9a61bca..b501fa6 100644
--- a/test/lisp/net/secrets-tests.el
+++ b/test/lisp/net/secrets-tests.el
@@ -232,7 +232,10 @@
"session" "baz" "secret"
:method "ssh" :user "joe" :host "other-host"))
- ;; Search the items.
+ ;; Search the items. `secrets-search-items' uses
+ ;; `secrets-search-item-paths' internally, it is sufficient to
+ ;; test only one of them.
+ (should-not (secrets-search-item-paths "session" :user "john"))
(should-not (secrets-search-items "session" :user "john"))
(should-not
(secrets-search-items "session" :xdg:schema "org.gnu.Emacs.foo"))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 19e642f: Extend secrets.el by searching for object paths.,
Michael Albinus <=