bmc: implement search for json files

Tested: Verified it prints out the blobs expected.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I1ba6af8b2ca066e6eb1699cb4214ce32f148005d
diff --git a/bmc/buildjson.cpp b/bmc/buildjson.cpp
index 5c14e61..a359add 100644
--- a/bmc/buildjson.cpp
+++ b/bmc/buildjson.cpp
@@ -16,13 +16,17 @@
 #include "buildjson.hpp"
 
 #include "file_handler.hpp"
+#include "fs.hpp"
 #include "prepare_systemd.hpp"
 #include "update_systemd.hpp"
 #include "verify_systemd.hpp"
 
+#include <algorithm>
 #include <cstdio>
 #include <exception>
+#include <fstream>
 #include <nlohmann/json.hpp>
+#include <phosphor-logging/log.hpp>
 #include <sdbusplus/bus.hpp>
 #include <string>
 #include <vector>
@@ -133,4 +137,37 @@
     return handlers;
 }
 
+std::vector<HandlerConfig> BuildHandlerConfigs(const std::string& directory)
+{
+    using namespace phosphor::logging;
+
+    std::vector<HandlerConfig> output;
+
+    std::vector<std::string> jsonPaths = GetJsonList(directory);
+
+    for (const auto& path : jsonPaths)
+    {
+        std::ifstream jsonFile(path);
+        if (!jsonFile.is_open())
+        {
+            log<level::ERR>("Unable to open json file",
+                            entry("PATH=%s", path.c_str()));
+            continue;
+        }
+
+        auto data = nlohmann::json::parse(jsonFile, nullptr, false);
+        if (data.is_discarded())
+        {
+            log<level::ERR>("Parsing json failed",
+                            entry("PATH=%s", path.c_str()));
+            continue;
+        }
+
+        std::vector<HandlerConfig> configs = buildHandlerFromJson(data);
+        std::move(configs.begin(), configs.end(), std::back_inserter(output));
+    }
+
+    return output;
+}
+
 } // namespace ipmi_flash