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 <dkodihal@in.ibm.com>
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 @@
     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 @@
 
         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 @@
             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