Patrick Venture | ab65000 | 2019-03-16 09:08:47 -0700 | [diff] [blame^] | 1 | #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 | |
| 9 | namespace google |
| 10 | { |
| 11 | namespace ipmi |
| 12 | { |
| 13 | |
| 14 | using namespace phosphor::logging; |
| 15 | using InternalFailure = |
| 16 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 17 | |
| 18 | nlohmann::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 |