blob: 02dab830b2e34c2fe2ff504781313c4a02f18e8c [file] [log] [blame]
Patrick Ventureab650002019-03-16 09:08:47 -07001#include "util.hpp"
2
3#include <fstream>
4#include <nlohmann/json.hpp>
5#include <phosphor-logging/elog-errors.hpp>
6#include <string>
7#include <xyz/openbmc_project/Common/error.hpp>
8
9namespace google
10{
11namespace ipmi
12{
13
14using namespace phosphor::logging;
15using InternalFailure =
16 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
17
18nlohmann::json parseConfig(const std::string& file)
19{
20 std::ifstream jsonFile(file);
21 if (!jsonFile.is_open())
22 {
23 log<level::ERR>("Entity association JSON file not found");
24 elog<InternalFailure>();
25 }
26
27 auto data = nlohmann::json::parse(jsonFile, nullptr, false);
28 if (data.is_discarded())
29 {
30 log<level::ERR>("Entity association JSON parser failure");
31 elog<InternalFailure>();
32 }
33
34 return data;
35}
36
37} // namespace ipmi
38} // namespace google