Update most resources to use urlFromPieces
Only id in event_service and account_service have not been updated due
to the risk of it breaking the username/id. It will require further
testing to verify.
Use urlFromPieces wherever that is needed to insert a variable in the
URI. Don't use urlFromPieces when it is hardcoded values. This allow us
to control all resource URIs that is dynamically added and to sync with
the current recommanded method for `@odata.id`. The goal is to have a
common place to manage the url created from dbus-paths in order to
manage/update it easily when needed.
Tested:
RedfishValidtor Passed for all resource including the sensors with the
fragments.
Change-Id: I95cdfaaee58fc7f21c95f5944e1e5c813b3215f2
Signed-off-by: Willy Tu <wltu@google.com>
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index b807bc4..bb9552a 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -1295,8 +1295,9 @@
// Fill in the log entry with the gathered data
logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
- logEntryJson["@odata.id"] =
- "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + logEntryID;
+ logEntryJson["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Systems", "system", "LogServices", "EventLog",
+ "Entries", logEntryID);
logEntryJson["Name"] = "System Event Log Entry";
logEntryJson["Id"] = logEntryID;
logEntryJson["Message"] = std::move(msg);
@@ -1629,9 +1630,9 @@
entriesArray.push_back({});
nlohmann::json& thisEntry = entriesArray.back();
thisEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
- thisEntry["@odata.id"] =
- "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
- std::to_string(*id);
+ thisEntry["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Systems", "system", "LogServices",
+ "EventLog", "Entries", std::to_string(*id));
thisEntry["Name"] = "System Event Log Entry";
thisEntry["Id"] = std::to_string(*id);
thisEntry["Message"] = *message;
@@ -1750,8 +1751,9 @@
asyncResp->res.jsonValue["@odata.type"] =
"#LogEntry.v1_9_0.LogEntry";
asyncResp->res.jsonValue["@odata.id"] =
- "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
- std::to_string(*id);
+ crow::utility::urlFromPieces(
+ "redfish", "v1", "Systems", "system", "LogServices",
+ "EventLog", "Entries", std::to_string(*id));
asyncResp->res.jsonValue["Name"] = "System Event Log Entry";
asyncResp->res.jsonValue["Id"] = std::to_string(*id);
asyncResp->res.jsonValue["Message"] = *message;
@@ -2047,9 +2049,9 @@
{
// Fill in the log entry with the gathered data.
logEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
- logEntryJson["@odata.id"] =
- "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/" +
- logEntryID;
+ logEntryJson["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Systems", "system", "LogServices", "HostLogger",
+ "Entries", logEntryID);
logEntryJson["Name"] = "Host Logger Entry";
logEntryJson["Id"] = logEntryID;
logEntryJson["Message"] = msg;
@@ -2397,9 +2399,9 @@
// Fill in the log entry with the gathered data
bmcJournalLogEntryJson["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
- bmcJournalLogEntryJson["@odata.id"] =
- "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" +
- bmcJournalLogEntryID;
+ bmcJournalLogEntryJson["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Managers", "bmc", "LogServices", "Journal", "Entries",
+ bmcJournalLogEntryID);
bmcJournalLogEntryJson["Name"] = "BMC Journal Entry";
bmcJournalLogEntryJson["Id"] = bmcJournalLogEntryID;
bmcJournalLogEntryJson["Message"] = std::move(message);
@@ -3018,7 +3020,8 @@
redfishDateTimeOffset.second;
asyncResp->res.jsonValue["Entries"]["@odata.id"] =
- "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
+ crow::utility::urlFromPieces("redfish", "v1", "Systems", "system",
+ "LogServices", "Crashdump", "Entries");
asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] =
"/redfish/v1/Systems/system/LogServices/Crashdump/Actions/LogService.ClearLog";
asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"]
@@ -3102,8 +3105,9 @@
logID + "/" + filename;
nlohmann::json::object_t logEntry;
logEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
- logEntry["@odata.id"] =
- "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + logID;
+ logEntry["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Systems", "system", "LogServices", "Crashdump",
+ "Entries", logID);
logEntry["Name"] = "CPU Crashdump";
logEntry["Id"] = logID;
logEntry["EntryType"] = "Oem";
@@ -3741,9 +3745,9 @@
// Format entry
nlohmann::json::object_t bmcLogEntry;
bmcLogEntry["@odata.type"] = "#LogEntry.v1_9_0.LogEntry";
- bmcLogEntry["@odata.id"] =
- "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/" +
- postcodeEntryID;
+ bmcLogEntry["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Systems", "system", "LogServices", "PostCodes",
+ "Entries", postcodeEntryID);
bmcLogEntry["Name"] = "POST Code Log Entry";
bmcLogEntry["Id"] = postcodeEntryID;
bmcLogEntry["Message"] = std::move(msg);