From c043cdda0b2363c04abefdce0d7f19138b00b131 Mon Sep 17 00:00:00 2001 From: Deepak Kodihalli Date: Tue, 2 Oct 2018 06:27:57 -0500 Subject: certificate handler: use mapper Use mapper to retrieve a D-Bus busname, instead of assuming a well-known busname. Change-Id: I668f750ab098b847bf3a662abdf6614170471c41 Signed-off-by: Deepak Kodihalli --- module/obmc/wsgi/apps/rest_dbus.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'module/obmc/wsgi') diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py index 63d0f5e..5a5aaec 100644 --- a/module/obmc/wsgi/apps/rest_dbus.py +++ b/module/obmc/wsgi/apps/rest_dbus.py @@ -880,11 +880,10 @@ class CertificateHandler: file_loc = '/tmp' file_suffix = '.pem' file_prefix = 'cert_' - CERT_BUSNAME = 'xyz.openbmc_project.Certs.Manager' CERT_PATH = '/xyz/openbmc_project/certs' CERT_IFACE = 'xyz.openbmc_project.Certs.Install' - def do_upload(cls, cert_type, service): + def do_upload(cls, route_handler, cert_type, service): def cleanup(): if os.path.exists(temp.name): os.remove(temp.name) @@ -911,16 +910,20 @@ class CertificateHandler: try: bus = dbus.SystemBus() - busName = cls.CERT_BUSNAME + "." + cert_type.capitalize() + "." \ - + service.capitalize() certPath = cls.CERT_PATH + "/" + cert_type + "/" + service - obj = bus.get_object(busName, certPath) - iface = dbus.Interface(obj, cls.CERT_IFACE) - iface.Install(temp.name) - except dbus.exceptions.DBusException as e: + intfs = route_handler.try_mapper_call( + route_handler.mapper.get_object, path=certPath) + for busname,intf in intfs.items(): + if cls.CERT_IFACE in intf: + obj = bus.get_object(busName, certPath) + iface = dbus.Interface(obj, cls.CERT_IFACE) + iface.Install(temp.name) + cleanup() + return + abort(404, "Path not found") + except Exception as e: cleanup() abort(503, str(e)) - cleanup() class CertificatePutHandler(RouteHandler): @@ -935,7 +938,7 @@ class CertificatePutHandler(RouteHandler): app, bus, self.verbs, self.rules, self.content_type) def do_put(self, cert_type, service): - return CertificateHandler().do_upload(cert_type, service) + return CertificateHandler().do_upload(self, cert_type, service) def find(self, **kw): pass -- cgit v1.2.1