Refactor fillDbusEventLogEntry handling
Currently, EventLog entry output is directly produced from the
dbusPropertyMap in a function like
- Extract DbusEventLogEntry from PropertyMap
- Generate json output from DbusEventLogEntry struct.
There is a need to generate json output conditionally based on
DbusLogEntry content. For example, an OEM may choose to add a new
d-dbus field like `Hidden` to hide those entries from Redfish output.
For this kind of need, it is better to separate the current
`fillDbusEventLogEntryFromPropertyMap()` into 2 steps like
From:
```
fillEventLogLogEntryFromPropertyMap(asyncResp, resp, asyncResp->res.jsonValue);
==>
std::optional<DbusEventLogEntry> optEntry =
fillDbusEventLogEntryFromPropertyMap(propertyMap);
fillEventLogLogEntryFromDbusLogEntry(*optEntry, asyncResp->res.jsonValue);
```
Then, we can add a condition easily before generating json output like
this.
```
std::optional<DbusEventLogEntry> optEntry =
fillDbusEventLogEntryFromPropertyMap(propertyMap);
if( !optEntry->Hidden )
{
fillEventLogLogEntryFromDbusLogEntry(*optEntry, asyncResp->res.jsonValue);
}
```
Tested:
- Get /redfish/v1/Systems/system/LogServices/EventLog/Entries
- Compare the outputs of before and after change.
Change-Id: I75f4debb7f10037a5fbca445b04650e6903c7628
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index ab5a374..95c74ee 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -1433,21 +1433,9 @@
return LogParseError::success;
}
-inline bool fillEventLogLogEntryFromPropertyMap(
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const dbus::utility::DBusPropertiesMap& resp,
- nlohmann::json& objectToFillOut)
+inline void fillEventLogLogEntryFromDbusLogEntry(
+ const DbusEventLogEntry& entry, nlohmann::json& objectToFillOut)
{
- std::optional<DbusEventLogEntry> optEntry =
- fillDbusEventLogEntryFromPropertyMap(resp);
-
- if (!optEntry.has_value())
- {
- messages::internalError(asyncResp->res);
- return false;
- }
- DbusEventLogEntry entry = optEntry.value();
-
objectToFillOut["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
objectToFillOut["@odata.id"] = boost::urls::format(
"/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}",
@@ -1479,7 +1467,6 @@
"/redfish/v1/Systems/{}/LogServices/EventLog/Entries/{}/attachment",
BMCWEB_REDFISH_SYSTEM_URI_NAME, std::to_string(entry.Id));
}
- return true;
}
inline void afterLogEntriesGetManagedObjects(
@@ -1507,6 +1494,7 @@
{
continue;
}
+
for (const auto& interfaceMap : objectPath.second)
{
for (const auto& propertyMap : interfaceMap.second)
@@ -1515,12 +1503,16 @@
propertyMap.second);
}
}
- bool success = fillEventLogLogEntryFromPropertyMap(
- asyncResp, propsFlattened, entriesArray.emplace_back());
- if (!success)
+ std::optional<DbusEventLogEntry> optEntry =
+ fillDbusEventLogEntryFromPropertyMap(propsFlattened);
+
+ if (!optEntry.has_value())
{
+ messages::internalError(asyncResp->res);
return;
}
+ fillEventLogLogEntryFromDbusLogEntry(*optEntry,
+ entriesArray.emplace_back());
}
redfish::json_util::sortJsonArrayByKey(entriesArray, "Id");
@@ -1795,8 +1787,16 @@
return;
}
- fillEventLogLogEntryFromPropertyMap(asyncResp, resp,
- asyncResp->res.jsonValue);
+ std::optional<DbusEventLogEntry> optEntry =
+ fillDbusEventLogEntryFromPropertyMap(resp);
+
+ if (!optEntry.has_value())
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+
+ fillEventLogLogEntryFromDbusLogEntry(*optEntry, asyncResp->res.jsonValue);
}
inline void dBusEventLogEntryGet(