PEL: New repository method to get PEL data

Add the getPELData() function on the Repository class to return
PEL data based on a PEL ID or OBMC event log ID.

The intended use for this will be a D-Bus method, mainly used for
debug via the REST interface, to get the PEL data off the BMC when
only the OpenBMC event log ID is known, which will be the case until
the Redfish APIs are ready.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ia1d8bff627992fae16be9136f2814f01ea69009e
diff --git a/extensions/openpower-pels/repository.cpp b/extensions/openpower-pels/repository.cpp
index aa6a18b..0810dd4 100644
--- a/extensions/openpower-pels/repository.cpp
+++ b/extensions/openpower-pels/repository.cpp
@@ -125,5 +125,27 @@
     }
 }
 
+std::optional<std::vector<uint8_t>> Repository::getPELData(const LogID& id)
+{
+    auto pel = findPEL(id);
+    if (pel != _idsToPELs.end())
+    {
+        std::ifstream file{pel->second.c_str()};
+        if (!file.good())
+        {
+            auto e = errno;
+            log<level::ERR>("Unable to open PEL file", entry("ERRNO=%d", e),
+                            entry("PATH=%s", pel->second.c_str()));
+            throw file_error::Open();
+        }
+
+        std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
+                                  std::istreambuf_iterator<char>()};
+        return data;
+    }
+
+    return std::nullopt;
+}
+
 } // namespace pels
 } // namespace openpower