PEL: Fixed Userdata section parsing

A previous commit incorrectly tries to call python parsers when they do
not exist. This fixes it.

Signed-off-by: Harisuddin Mohamed Isa <harisuddin@gmail.com>
Change-Id: I6e65bc89e60b9ac31077009921d4376ddc8254bf
diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp
index 56d442d..d23bf92 100644
--- a/extensions/openpower-pels/pel.cpp
+++ b/extensions/openpower-pels/pel.cpp
@@ -295,15 +295,7 @@
         }
         else if (sectionID == "UD")
         {
-            std::string subsystem = getNumberString("%c", tolower(creatorID));
-            std::string component =
-                getNumberString("%04x", section.header().componentID);
-            if ((std::find(plugins.begin(), plugins.end(),
-                           subsystem + component) != plugins.end()) ||
-                pv::creatorIDs.at(getNumberString("%c", creatorID)) == "BMC")
-            {
-                json = section.getJSON(creatorID);
-            }
+            json = section.getJSON(creatorID, plugins);
         }
         else
         {
diff --git a/extensions/openpower-pels/section.hpp b/extensions/openpower-pels/section.hpp
index 0d079f2..4a11d77 100644
--- a/extensions/openpower-pels/section.hpp
+++ b/extensions/openpower-pels/section.hpp
@@ -74,10 +74,13 @@
     /**
      * @brief Get section in JSON. Derived classes to override when required to.
      * @param[in] creatorID - Creator Subsystem ID from Private Header
+     * @param[in] plugins - Vector of strings of plugins found in filesystem
      * @return std::optional<std::string> - If a section comes with a JSON
      * representation, this would return the string for it.
      */
-    virtual std::optional<std::string> getJSON(uint8_t creatorID) const
+    virtual std::optional<std::string>
+        getJSON(uint8_t creatorID,
+                const std::vector<std::string>& plugins) const
     {
         return std::nullopt;
     }
diff --git a/extensions/openpower-pels/user_data.cpp b/extensions/openpower-pels/user_data.cpp
index 092bfb6..fa4c577 100644
--- a/extensions/openpower-pels/user_data.cpp
+++ b/extensions/openpower-pels/user_data.cpp
@@ -95,11 +95,13 @@
     }
 }
 
-std::optional<std::string> UserData::getJSON(uint8_t creatorID) const
+std::optional<std::string>
+    UserData::getJSON(uint8_t creatorID,
+                      const std::vector<std::string>& plugins) const
 {
 #ifdef PELTOOL
     return user_data::getJSON(_header.componentID, _header.subType,
-                              _header.version, _data, creatorID);
+                              _header.version, _data, creatorID, plugins);
 #endif
     return std::nullopt;
 }
diff --git a/extensions/openpower-pels/user_data.hpp b/extensions/openpower-pels/user_data.hpp
index e27342e..7fc7ead 100644
--- a/extensions/openpower-pels/user_data.hpp
+++ b/extensions/openpower-pels/user_data.hpp
@@ -83,10 +83,13 @@
     /**
      * @brief Get the section contents in JSON
      * @param[in] creatorID - Creator Subsystem ID from Private Header
+     * @param[in] plugins - Vector of strings of plugins found in filesystem
      * @return The JSON as a string if a parser was found,
      *         otherwise std::nullopt.
      */
-    std::optional<std::string> getJSON(uint8_t creatorID) const override;
+    std::optional<std::string>
+        getJSON(uint8_t creatorID,
+                const std::vector<std::string>& plugins) const override;
 
     /**
      * @brief Shrink the section
diff --git a/extensions/openpower-pels/user_data_json.cpp b/extensions/openpower-pels/user_data_json.cpp
index 408f5c3..6f88cbd 100644
--- a/extensions/openpower-pels/user_data_json.cpp
+++ b/extensions/openpower-pels/user_data_json.cpp
@@ -367,8 +367,11 @@
 std::optional<std::string> getJSON(uint16_t componentID, uint8_t subType,
                                    uint8_t version,
                                    const std::vector<uint8_t>& data,
-                                   uint8_t creatorID)
+                                   uint8_t creatorID,
+                                   const std::vector<std::string>& plugins)
 {
+    std::string subsystem = getNumberString("%c", tolower(creatorID));
+    std::string component = getNumberString("%04x", componentID);
     try
     {
         if (pv::creatorIDs.at(getNumberString("%c", creatorID)) == "BMC" &&
@@ -376,7 +379,8 @@
         {
             return getBuiltinFormatJSON(componentID, subType, version, data);
         }
-        else
+        else if (std::find(plugins.begin(), plugins.end(),
+                           subsystem + component) != plugins.end())
         {
             return getPythonJSON(componentID, subType, version, data,
                                  creatorID);
diff --git a/extensions/openpower-pels/user_data_json.hpp b/extensions/openpower-pels/user_data_json.hpp
index 5a0cc19..9d6b79d 100644
--- a/extensions/openpower-pels/user_data_json.hpp
+++ b/extensions/openpower-pels/user_data_json.hpp
@@ -15,13 +15,14 @@
  * @param[in] version - The version from the UserData section header
  * @param[in] data - The section data
  * @param[in] creatorID - Creator Subsystem ID from Private Header
- *
+ * @param[in] plugins - Vector of strings of plugins found in filesystem
  * @return std::optional<std::string> - The JSON string if it could be created,
  *                                      else std::nullopt.
  */
 std::optional<std::string> getJSON(uint16_t componentID, uint8_t subType,
                                    uint8_t version,
                                    const std::vector<uint8_t>& data,
-                                   uint8_t creatorID);
+                                   uint8_t creatorID,
+                                   const std::vector<std::string>& plugins);
 
 } // namespace openpower::pels::user_data