Certificate delete API – middleware

With introducing Mutual-TLS and option to add multiple certificates
there is a need to give user a possibility to remove them, for example
when they expire. This commit adds implementation of DELETE function
to TLS Certificate node, so each of them can be removed.

Beckend implementation is here:
https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-certificate-manager/+/25268

Tested with uploaded multiple TLS certificates.
Other certificates remains irremovable as they were so far.

Signed-off-by: Zbigniew Kurzynski <zbigniew.kurzynski@intel.com>
Change-Id: I9781c5c79288ec5d080e80e42c63a55e471ddb77
Depends-On: I9dd6fa998e8bd8081fbd13549831bc94a4a7aa54
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index b40b1e9..9b4f60e 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -26,6 +26,7 @@
     "/xyz/openbmc_project/certs/server/https";
 constexpr char const *certInstallIntf = "xyz.openbmc_project.Certs.Install";
 constexpr char const *certReplaceIntf = "xyz.openbmc_project.Certs.Replace";
+constexpr char const *objDeleteIntf = "xyz.openbmc_project.Object.Delete";
 constexpr char const *certPropIntf = "xyz.openbmc_project.Certs.Certificate";
 constexpr char const *dbusPropIntf = "org.freedesktop.DBus.Properties";
 constexpr char const *dbusObjManagerIntf = "org.freedesktop.DBus.ObjectManager";
@@ -1363,5 +1364,46 @@
                                  certs::authorityServiceName, id, certURL,
                                  "TrustStore Certificate");
     }
+
+    void doDelete(crow::Response &res, const crow::Request &req,
+                  const std::vector<std::string> &params) override
+    {
+        auto asyncResp = std::make_shared<AsyncResp>(res);
+
+        if (params.size() != 1)
+        {
+            messages::internalError(asyncResp->res);
+            return;
+        }
+
+        long id = getIDFromURL(req.url);
+        if (id < 0)
+        {
+            BMCWEB_LOG_ERROR << "Invalid url value: " << req.url;
+            messages::resourceNotFound(asyncResp->res, "TrustStore Certificate",
+                                       std::string(req.url));
+            return;
+        }
+        BMCWEB_LOG_DEBUG << "TrustStoreCertificate::doDelete ID="
+                         << std::to_string(id);
+        std::string certPath = certs::authorityObjectPath;
+        certPath += "/";
+        certPath += std::to_string(id);
+
+        crow::connections::systemBus->async_method_call(
+            [asyncResp, id](const boost::system::error_code ec) {
+                if (ec)
+                {
+                    messages::resourceNotFound(asyncResp->res,
+                                               "TrustStore Certificate",
+                                               std::to_string(id));
+                    return;
+                }
+                BMCWEB_LOG_INFO << "Certificate deleted";
+                asyncResp->res.result(boost::beast::http::status::no_content);
+            },
+            certs::authorityServiceName, certPath, certs::objDeleteIntf,
+            "Delete");
+    }
 }; // TrustStoreCertificate
 } // namespace redfish