Implement certificate delete
A deletion of a certificate is invoked by calling the DELETE verb on the
certificate REST endpoint. This application intercepts this and deletes
the certificate file. It also reloads/restarts the associated systemd
unit, which may generate a self-signed certificate.
Change-Id: I879551c1aff160cab0c07d1c73ae147f85a6e17e
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/certs_manager.cpp b/certs_manager.cpp
index 28b0957..4ebf71c 100644
--- a/certs_manager.cpp
+++ b/certs_manager.cpp
@@ -112,8 +112,6 @@
void Manager::copy(const std::string& src, const std::string& dst)
{
- namespace fs = std::experimental::filesystem;
-
try
{
auto path = fs::path(dst).parent_path();
@@ -329,5 +327,33 @@
return true;
}
+
+void Manager::delete_()
+{
+ try
+ {
+ if (!fs::remove(certPath))
+ {
+ log<level::INFO>("Certificate file not found!",
+ entry("PATH=%s", certPath.c_str()));
+ }
+ else
+ {
+ reloadOrReset(unit);
+ }
+ }
+ catch (const InternalFailure& e)
+ {
+ throw;
+ }
+ catch (const std::exception& e)
+ {
+ log<level::ERR>(
+ "Failed to delete certificate", entry("UNIT=%s", unit.c_str()),
+ entry("ERR=%s", e.what()), entry("PATH=%s", certPath.c_str()));
+ elog<InternalFailure>();
+ }
+}
+
} // namespace certs
} // namespace phosphor