aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/net/secrets.el43
-rw-r--r--test/lisp/net/secrets-tests.el5
2 files changed, 29 insertions, 19 deletions
diff --git a/lisp/net/secrets.el b/lisp/net/secrets.el
index 45c98cae60d..ca75d953c43 100644
--- a/lisp/net/secrets.el
+++ b/lisp/net/secrets.el
@@ -602,16 +602,16 @@ If successful, return the object path of the collection."
602 (secrets-get-item-property item-path "Label")) 602 (secrets-get-item-property item-path "Label"))
603 (secrets-get-items collection-path))))) 603 (secrets-get-items collection-path)))))
604 604
605(defun secrets-search-items (collection &rest attributes) 605(defun secrets-search-item-paths (collection &rest attributes)
606 "Search items in COLLECTION with ATTRIBUTES. 606 "Search items in COLLECTION with ATTRIBUTES.
607ATTRIBUTES are key-value pairs. The keys are keyword symbols, 607ATTRIBUTES are key-value pairs. The keys are keyword symbols,
608starting with a colon. Example: 608starting with a colon. Example:
609 609
610 (secrets-search-items \"Tramp collection\" :user \"joe\") 610 (secrets-search-item-paths \"Tramp collection\" :user \"joe\")
611 611
612The object labels of the found items are returned as list." 612The object paths of the found items are returned as list."
613 (let ((collection-path (secrets-unlock-collection collection)) 613 (let ((collection-path (secrets-unlock-collection collection))
614 result props) 614 props)
615 (unless (secrets-empty-path collection-path) 615 (unless (secrets-empty-path collection-path)
616 ;; Create attributes list. 616 ;; Create attributes list.
617 (while (consp (cdr attributes)) 617 (while (consp (cdr attributes))
@@ -626,23 +626,30 @@ The object labels of the found items are returned as list."
626 ,(cadr attributes)))) 626 ,(cadr attributes))))
627 attributes (cddr attributes))) 627 attributes (cddr attributes)))
628 ;; Search. The result is a list of object paths. 628 ;; Search. The result is a list of object paths.
629 (setq result 629 (dbus-call-method
630 (dbus-call-method 630 :session secrets-service collection-path
631 :session secrets-service collection-path 631 secrets-interface-collection "SearchItems"
632 secrets-interface-collection "SearchItems" 632 (if props
633 (if props 633 (cons :array props)
634 (cons :array props) 634 '(:array :signature "{ss}"))))))
635 '(:array :signature "{ss}")))) 635
636 ;; Return the found items. 636(defun secrets-search-items (collection &rest attributes)
637 (mapcar 637 "Search items in COLLECTION with ATTRIBUTES.
638 (lambda (item-path) (secrets-get-item-property item-path "Label")) 638ATTRIBUTES are key-value pairs. The keys are keyword symbols,
639 result)))) 639starting with a colon. Example:
640
641 (secrets-search-items \"Tramp collection\" :user \"joe\")
642
643The object labels of the found items are returned as list."
644 (mapcar
645 (lambda (item-path) (secrets-get-item-property item-path "Label"))
646 (apply 'secrets-search-item-paths collection attributes)))
640 647
641(defun secrets-create-item (collection item password &rest attributes) 648(defun secrets-create-item (collection item password &rest attributes)
642 "Create a new item in COLLECTION with label ITEM and password PASSWORD. 649 "Create a new item in COLLECTION with label ITEM and password PASSWORD.
643The label ITEM must not be unique in COLLECTION. ATTRIBUTES are 650The label ITEM does not have to be unique in COLLECTION.
644key-value pairs set for the created item. The keys are keyword 651ATTRIBUTES are key-value pairs set for the created item. The
645symbols, starting with a colon. Example: 652keys are keyword symbols, starting with a colon. Example:
646 653
647 (secrets-create-item \"Tramp collection\" \"item\" \"geheim\" 654 (secrets-create-item \"Tramp collection\" \"item\" \"geheim\"
648 :method \"sudo\" :user \"joe\" :host \"remote-host\") 655 :method \"sudo\" :user \"joe\" :host \"remote-host\")
diff --git a/test/lisp/net/secrets-tests.el b/test/lisp/net/secrets-tests.el
index 9a61bca4351..b501fa602d0 100644
--- a/test/lisp/net/secrets-tests.el
+++ b/test/lisp/net/secrets-tests.el
@@ -232,7 +232,10 @@
232 "session" "baz" "secret" 232 "session" "baz" "secret"
233 :method "ssh" :user "joe" :host "other-host")) 233 :method "ssh" :user "joe" :host "other-host"))
234 234
235 ;; Search the items. 235 ;; Search the items. `secrets-search-items' uses
236 ;; `secrets-search-item-paths' internally, it is sufficient to
237 ;; test only one of them.
238 (should-not (secrets-search-item-paths "session" :user "john"))
236 (should-not (secrets-search-items "session" :user "john")) 239 (should-not (secrets-search-items "session" :user "john"))
237 (should-not 240 (should-not
238 (secrets-search-items "session" :xdg:schema "org.gnu.Emacs.foo")) 241 (secrets-search-items "session" :xdg:schema "org.gnu.Emacs.foo"))