bmc: buildjson: provide helper for common filesystemd type

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: If0c106301538a6a11e199c8033cf7328f21575e6
diff --git a/bmc/buildjson.cpp b/bmc/buildjson.cpp
index 0fd40ef..6f9c319 100644
--- a/bmc/buildjson.cpp
+++ b/bmc/buildjson.cpp
@@ -34,6 +34,25 @@
 namespace ipmi_flash
 {
 
+std::unique_ptr<TriggerableActionInterface>
+    buildFileSystemd(const nlohmann::json& data)
+{
+    /* This type of action requires a path and unit, and optionally a mode. */
+    const auto& path = data.at("path");
+    const auto& unit = data.at("unit");
+
+    /* the mode parameter is optional. */
+    std::string systemdMode = "replace";
+    const auto& mode = data.find("mode");
+    if (mode != data.end())
+    {
+        systemdMode = data.at("mode").get<std::string>();
+    }
+
+    return SystemdWithStatusFile::CreateSystemdWithStatusFile(
+        sdbusplus::bus::new_default(), path, unit, systemdMode);
+}
+
 std::vector<HandlerConfig> buildHandlerFromJson(const nlohmann::json& data)
 {
     std::vector<HandlerConfig> handlers;
@@ -89,20 +108,7 @@
             const std::string verifyType = verify.at("type");
             if (verifyType == "fileSystemdVerify")
             {
-                const auto& path = verify.at("path");
-                const auto& unit = verify.at("unit");
-
-                /* the mode parameter is optional. */
-                std::string systemdMode = "replace";
-                const auto& mode = verify.find("mode");
-                if (mode != verify.end())
-                {
-                    systemdMode = verify.at("mode").get<std::string>();
-                }
-
-                pack->verification =
-                    SystemdWithStatusFile::CreateSystemdWithStatusFile(
-                        sdbusplus::bus::new_default(), path, unit, systemdMode);
+                pack->verification = std::move(buildFileSystemd(verify));
             }
             else
             {
@@ -121,20 +127,7 @@
             }
             else if (updateType == "fileSystemdUpdate")
             {
-                const auto& path = update.at("path");
-                const auto& unit = update.at("unit");
-
-                /* the mode parameter is optional. */
-                std::string systemdMode = "replace";
-                const auto& mode = update.find("mode");
-                if (mode != update.end())
-                {
-                    systemdMode = update.at("mode").get<std::string>();
-                }
-
-                pack->update =
-                    SystemdWithStatusFile::CreateSystemdWithStatusFile(
-                        sdbusplus::bus::new_default(), path, unit, systemdMode);
+                pack->update = std::move(buildFileSystemd(update));
             }
             else if (updateType == "systemd")
             {