Function: secrets-create-item
secrets-create-item is an autoloaded and byte-compiled function
defined in secrets.el.gz.
Signature
(secrets-create-item COLLECTION ITEM PASSWORD &rest ATTRIBUTES)
Documentation
Create a new item in COLLECTION with label ITEM and password PASSWORD.
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")
The key :xdg:schema determines the scope of the item to be
generated, i.e. for which applications the item is intended for.
This is just a string like "org.freedesktop.NetworkManager.Mobile"
or "org.gnome.OnlineAccounts", the other required keys are
determined by this. If no :xdg:schema is given,
"org.freedesktop.Secret.Generic" is used by default.
The object path of the created item is returned.
Source Code
;; Defined in /usr/src/emacs/lisp/net/secrets.el.gz
(defun secrets-create-item (collection item password &rest attributes)
"Create a new item in COLLECTION with label ITEM and password PASSWORD.
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\")
The key `:xdg:schema' determines the scope of the item to be
generated, i.e. for which applications the item is intended for.
This is just a string like \"org.freedesktop.NetworkManager.Mobile\"
or \"org.gnome.OnlineAccounts\", the other required keys are
determined by this. If no `:xdg:schema' is given,
\"org.freedesktop.Secret.Generic\" is used by default.
The object path of the created item is returned."
(let ((collection-path (secrets-unlock-collection collection))
result props)
(unless (secrets-empty-path collection-path)
;; Set default type if needed.
(unless (member :xdg:schema attributes)
(setq attributes
(append
attributes `(:xdg:schema ,secrets-interface-item-type-generic))))
;; Create attributes list.
(while (consp (cdr attributes))
(unless (keywordp (car attributes))
(error 'wrong-type-argument (car attributes)))
(unless (stringp (cadr attributes))
(error 'wrong-type-argument (cadr attributes)))
(setq props (append
props
`((:dict-entry
,(substring (symbol-name (car attributes)) 1)
,(cadr attributes))))
attributes (cddr attributes)))
;; Create the item.
(setq result
(dbus-call-method
:session secrets-service collection-path
secrets-interface-collection "CreateItem"
;; Properties.
(append
`(:array
(:dict-entry ,(concat secrets-interface-item ".Label")
(:variant ,item)))
(when props
`((:dict-entry ,(concat secrets-interface-item ".Attributes")
(:variant ,(append '(:array) props))))))
;; Secret.
`(:struct :object-path ,secrets-session-path
(:array :signature "y") ;; No parameters.
,(dbus-string-to-byte-array password)
,secrets-struct-secret-content-type)
;; Do not replace. Replace does not seem to work.
nil))
(secrets-prompt (cadr result))
;; Return the object path.
(car result))))