#8194 Migrate dbus code to GIO
Closed: wontfix 4 years ago by rcritten. Opened 4 years ago by abbra.

FreeIPA currently uses python3-dbus API which is deprecated for a decade now and is wished for a removal by GNOME developers. While this is not going to happen in Fedora 32, we need to prepare.

FreeIPA uses D-BUS to communicate with the following external processes:
- certmonger
- oddjob helpers
- SSSD

Below is a sample Python code that uses GIO to communicate with certmonger over the system bus (run as root) to enumerate certificates:

from gi.repository import Gio, GLib

DBUS_CM_PATH = '/org/fedorahosted/certmonger'
DBUS_CM_IF = 'org.fedorahosted.certmonger'
DBUS_CM_NAME = 'org.fedorahosted.certmonger'
DBUS_CM_REQUEST_IF = 'org.fedorahosted.certmonger.request'
DBUS_CM_CA_IF = 'org.fedorahosted.certmonger.ca'
DBUS_PROPERTY_IF = 'org.freedesktop.DBus.Properties'

try:
    bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
    proxy = Gio.DBusProxy.new_sync(bus, 
                                   Gio.DBusProxyFlags.NONE,
                                   None,
                                   DBUS_CM_NAME, DBUS_CM_PATH, DBUS_CM_IF,
                                   None)
except GLib.Error as e:
    if e.code == Gio.DBusError.ACCESS_DENIED:
        print("access was denied")
    exit(1)

try:
    res = proxy.call_sync('get_requests',
                          None,
                          Gio.DBusCallFlags.NO_AUTO_START, 500, None)[0]
    for req in res:
        print(f"Request {req}")
        req_proxy = Gio.DBusProxy.new_sync(bus,
                                           Gio.DBusProxyFlags.NONE,
                                           None,
                                           DBUS_CM_NAME, req, DBUS_CM_REQUEST_IF,
                                           None)
        req_res = req_proxy.get_cached_property_names()
        for prop in req_res:
            value = req_proxy.get_cached_property(prop)
            print(f"\t{prop}: {value}")
except GLib.Error as e:
    print(e.message)
    if e.code == Gio.DBusError.ACCESS_DENIED:
        print("access was denied")
    exit(1)

Example test code: https://gitlab.gnome.org/GNOME/pygobject/blob/master/tests/test_gdbus.py
One can also use help(proxy) and apply the same approach on other objects or use pydoc gi.repository.Gio to see whole generated documentation.

Metadata Update from @abbra:
- Issue set to the milestone: FreeIPA 4.9

4 years ago

I think that 500 should be replaced with -1 to use default timeout. An alternative approach is use of auto proxy, e.g. proxy.call_sync('get_requests', ...) can be replaced with proxy.get_requests().

Metadata Update from @cheimes:
- Issue set to the milestone: None (was: FreeIPA 4.9)

4 years ago

Marking as closed, we'll stick with dbus-python.

Metadata Update from @rcritten:
- Issue close_status updated to: wontfix
- Issue status updated to: Closed (was: Open)

4 years ago

Login to comment on this ticket.

Metadata