1
0
Fork 0

Make DBusExporter reusable for other services

Do not hardcode Polkit namespace into DBusExporter,
provide it as a parameter in the constructor.
This commit is contained in:
Pavol Žáčik 2023-12-07 15:18:52 +01:00
parent b15de12ec9
commit 4502d7abd7
No known key found for this signature in database
GPG key ID: B99527D5E6487A92
3 changed files with 6 additions and 5 deletions

View file

@ -79,7 +79,7 @@ if __name__ == "__main__":
args.no_socket = True
if not args.no_dbus:
app.attach_to_dbus(consts.DBUS_BUS, consts.DBUS_OBJECT, consts.DBUS_INTERFACE)
app.attach_to_dbus(consts.DBUS_BUS, consts.DBUS_OBJECT, consts.DBUS_INTERFACE, consts.NAMESPACE)
if not args.no_socket:
app.attach_to_unix_socket()

View file

@ -71,11 +71,11 @@ class Application(object):
self._handle_signal(signal.SIGINT, self._controller.terminate)
self._handle_signal(signal.SIGTERM, self._controller.terminate)
def attach_to_dbus(self, bus_name, object_name, interface_name):
def attach_to_dbus(self, bus_name, object_name, interface_name, namespace):
if self._dbus_exporter is not None:
raise TunedException("DBus interface is already initialized.")
self._dbus_exporter = exports.dbus.DBusExporter(bus_name, interface_name, object_name)
self._dbus_exporter = exports.dbus.DBusExporter(bus_name, interface_name, object_name, namespace)
exports.register_exporter(self._dbus_exporter)
def attach_to_unix_socket(self):

View file

@ -63,7 +63,7 @@ class DBusExporter(interfaces.ExporterInterface):
to an object we dynamically construct.
"""
def __init__(self, bus_name, interface_name, object_name):
def __init__(self, bus_name, interface_name, object_name, namespace):
# Monkey patching of the D-Bus library _method_reply_error() to reply
# tracebacks via D-Bus only if in the debug mode. It doesn't seem there is a
# more simple way how to cover all possible exceptions that could occur in
@ -82,6 +82,7 @@ class DBusExporter(interfaces.ExporterInterface):
self._bus_name = bus_name
self._interface_name = interface_name
self._object_name = object_name
self._namespace = namespace
self._thread = None
self._bus_object = None
self._polkit = polkit()
@ -130,7 +131,7 @@ class DBusExporter(interfaces.ExporterInterface):
raise Exception("Method with this name is already exported.")
def wrapper(owner, *args, **kwargs):
action_id = consts.NAMESPACE + "." + method.__name__
action_id = self._namespace + "." + method.__name__
caller = args[-1]
log.debug("checking authorization for action '%s' requested by caller '%s'" % (action_id, caller))
ret = self._polkit.check_authorization(caller, action_id)