[PATCH 3/3] Support prompt in keyring CreateItem as well

wgh at torlan.ru wgh at torlan.ru
Sun Mar 21 17:44:06 UTC 2021


From: WGH <wgh at torlan.ru>

I haven't seen the implementation that needs prompt confirmation here,
though, so I haven't really tested it. The code path is pretty much the
same as in Delete, though, which I did test.
---
 virtManager/lib/keyring.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/virtManager/lib/keyring.py b/virtManager/lib/keyring.py
index 1f956513..8d8eda37 100644
--- a/virtManager/lib/keyring.py
+++ b/virtManager/lib/keyring.py
@@ -73,6 +73,14 @@ class vmmKeyring(vmmGObject):
             return None
         return unlocked[0]
 
+    def _do_prompt_if_needed(self, path):
+        if path == "/":
+            return
+        iface = Gio.DBusProxy.new_sync(self._dbus, 0, None,
+                                       "org.freedesktop.secrets", path,
+                                       "org.freedesktop.Secret.Prompt", None)
+        iface.Prompt("(s)", "")
+
     def _add_secret(self, secret):
         try:
             props = {
@@ -84,8 +92,10 @@ class vmmKeyring(vmmGObject):
                       "text/plain; charset=utf8")
             replace = True
 
-            self._collection.CreateItem("(a{sv}(oayays)b)",
+            _, prompt = self._collection.CreateItem("(a{sv}(oayays)b)",
                                               props, params, replace)
+            self._do_prompt_if_needed(prompt)
+
         except Exception:  # pragma: no cover
             log.exception("Failed to add keyring secret")
 
@@ -99,11 +109,7 @@ class vmmKeyring(vmmGObject):
                                            "org.freedesktop.secrets", path,
                                            "org.freedesktop.Secret.Item", None)
             prompt = iface.Delete()
-            if prompt != "/":
-                iface = Gio.DBusProxy.new_sync(self._dbus, 0, None,
-                                               "org.freedesktop.secrets", prompt,
-                                               "org.freedesktop.Secret.Prompt", None)
-                iface.Prompt("(s)", "")
+            self._do_prompt_if_needed(prompt)
         except Exception:
             log.exception("Failed to delete keyring secret")
 
-- 
2.31.0





More information about the virt-tools-list mailing list