Implement Replace interface for Certificate objects

Replace interface is used to replace an existing certificate.

Change-Id: Ibf4bbc9a96fd68b25e447c1b11a24be42c547a26
Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
diff --git a/certificate.cpp b/certificate.cpp
index 413ad54..15f9367 100644
--- a/certificate.cpp
+++ b/certificate.cpp
@@ -9,8 +9,9 @@
 
 #include <fstream>
 #include <phosphor-logging/elog-errors.hpp>
-#include <xyz/openbmc_project/Certs/Install/error.hpp>
+#include <xyz/openbmc_project/Certs/error.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
+
 namespace phosphor
 {
 namespace certs
@@ -27,8 +28,8 @@
 using InternalFailure =
     sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
 using InvalidCertificate =
-    sdbusplus::xyz::openbmc_project::Certs::Install::Error::InvalidCertificate;
-using Reason = xyz::openbmc_project::Certs::Install::InvalidCertificate::REASON;
+    sdbusplus::xyz::openbmc_project::Certs::Error::InvalidCertificate;
+using Reason = xyz::openbmc_project::Certs::InvalidCertificate::REASON;
 
 // Trust chain related errors.`
 #define TRUST_CHAIN_ERR(errnum)                                                \
@@ -102,7 +103,12 @@
     }
 }
 
-void Certificate::install(const std::string filePath)
+void Certificate::replace(const std::string filePath)
+{
+    install(filePath);
+}
+
+void Certificate::install(const std::string& filePath)
 {
     log<level::INFO>("Certificate install ",
                      entry("FILEPATH=%s", filePath.c_str()));
diff --git a/certificate.hpp b/certificate.hpp
index 878ae71..6fbef52 100644
--- a/certificate.hpp
+++ b/certificate.hpp
@@ -5,7 +5,7 @@
 #include <filesystem>
 #include <phosphor-logging/elog.hpp>
 #include <xyz/openbmc_project/Certs/Certificate/server.hpp>
-#include <xyz/openbmc_project/Certs/Install/server.hpp>
+#include <xyz/openbmc_project/Certs/Replace/server.hpp>
 
 namespace phosphor
 {
@@ -13,9 +13,9 @@
 {
 using CertificateIface = sdbusplus::server::object::object<
     sdbusplus::xyz::openbmc_project::Certs::server::Certificate>;
-using InstallIface = sdbusplus::xyz::openbmc_project::Certs::server::Install;
+using ReplaceIface = sdbusplus::xyz::openbmc_project::Certs::server::Replace;
 using CertIfaces =
-    sdbusplus::server::object::object<CertificateIface, InstallIface>;
+    sdbusplus::server::object::object<CertificateIface, ReplaceIface>;
 
 using CertificateType = std::string;
 using UnitsToRestart = std::string;
@@ -67,14 +67,19 @@
                 const CertInstallPath& installPath,
                 const CertUploadPath& uploadPath);
 
-    /** @brief Implementation for Install
-     *  Replace the existing certificate file with another
+    /** @brief Validate certificate and replace the existing certificate
+     *  @param[in] filePath - Certificate file path.
+     */
+    void replace(const std::string filePath) override;
+
+  private:
+    /** @brief Validate and Replace/Install the certificate file
+     *  Install/Replace the existing certificate file with another
      *  (possibly CA signed) Certificate file.
      *  @param[in] filePath - Certificate file path.
      */
-    void install(const std::string filePath) override;
+    void install(const std::string& filePath);
 
-  private:
     /** @brief Load Certificate file into the X509 structre.
      *  @param[in] fileName - Certificate and key full file path.
      *  @return pointer to the X509 structure.
diff --git a/certs_manager.cpp b/certs_manager.cpp
index b55363f..ea19fcd 100644
--- a/certs_manager.cpp
+++ b/certs_manager.cpp
@@ -1,7 +1,7 @@
 #include "certs_manager.hpp"
 
 #include <phosphor-logging/elog-errors.hpp>
-#include <xyz/openbmc_project/Certs/Install/error.hpp>
+#include <xyz/openbmc_project/Certs/error.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 namespace phosphor
 {
@@ -25,10 +25,9 @@
     bus(bus), objectPath(path), certType(type), unitToRestart(std::move(unit)),
     certInstallPath(std::move(installPath))
 {
-    using InvalidCertificate = sdbusplus::xyz::openbmc_project::Certs::Install::
-        Error::InvalidCertificate;
-    using Reason =
-        xyz::openbmc_project::Certs::Install::InvalidCertificate::REASON;
+    using InvalidCertificate =
+        sdbusplus::xyz::openbmc_project::Certs::Error::InvalidCertificate;
+    using Reason = xyz::openbmc_project::Certs::InvalidCertificate::REASON;
     if (fs::exists(certInstallPath))
     {
         try
diff --git a/test/certs_manager_test.cpp b/test/certs_manager_test.cpp
index 82793a2..7b318d7 100644
--- a/test/certs_manager_test.cpp
+++ b/test/certs_manager_test.cpp
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #include "certificate.hpp"
 #include "certs_manager.hpp"
 
@@ -6,18 +8,15 @@
 #include <fstream>
 #include <iterator>
 #include <string>
-#include <xyz/openbmc_project/Certs/Install/error.hpp>
+#include <xyz/openbmc_project/Certs/error.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
 #include <gtest/gtest.h>
 namespace fs = std::filesystem;
-static constexpr auto BUSNAME = "xyz.openbmc_project.Certs.Manager";
-static constexpr auto OBJPATH = "/xyz/openbmc_project/certs";
 using InternalFailure =
     sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
-
 using InvalidCertificate =
-    sdbusplus::xyz::openbmc_project::Certs::Install::Error::InvalidCertificate;
+    sdbusplus::xyz::openbmc_project::Certs::Error::InvalidCertificate;
 using namespace phosphor::certs;
 
 /**