From ef4c65b741724d724452a3a0efe8dff0d450514a Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Mon, 24 Apr 2023 15:28:50 -0700 Subject: Boost::urls::format Boost 1.82 dropped a lovely new toy, boost::urls::format, which is a lot like our urlFromPieces method, but better in that it makes the resulting uris more readable, and allows doing things like fragments in a single line instead of multiple. We should prefer it in some cases. Tested: Redfish service validator passes. Spot checks of URLs work as expected. Unit tests pass. Signed-off-by: Ed Tanous Change-Id: Ia7b38f0a95771c862507e7d5b4aa68aa1c98403c --- redfish-core/lib/chassis.hpp | 49 +++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 26 deletions(-) (limited to 'redfish-core/lib/chassis.hpp') diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp index dc6afd8754..a2744210cf 100644 --- a/redfish-core/lib/chassis.hpp +++ b/redfish-core/lib/chassis.hpp @@ -26,6 +26,7 @@ #include "utils/json_utils.hpp" #include +#include #include #include @@ -273,21 +274,18 @@ inline void asyncResp->res.jsonValue["@odata.type"] = "#Chassis.v1_22_0.Chassis"; asyncResp->res.jsonValue["@odata.id"] = - crow::utility::urlFromPieces("redfish", "v1", "Chassis", - chassisId); + boost::urls::format("/redfish/v1/Chassis/{}", chassisId); asyncResp->res.jsonValue["Name"] = "Chassis Collection"; asyncResp->res.jsonValue["ChassisType"] = "RackMount"; asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] = - crow::utility::urlFromPieces("redfish", "v1", "Chassis", - chassisId, "Actions", - "Chassis.Reset"); + boost::urls::format( + "/redfish/v1/Chassis/{}/Actions/Chassis.Reset", chassisId); asyncResp->res .jsonValue["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"] = - crow::utility::urlFromPieces("redfish", "v1", "Chassis", - chassisId, "ResetActionInfo"); + boost::urls::format("/redfish/v1/Chassis/{}/ResetActionInfo", + chassisId); asyncResp->res.jsonValue["PCIeDevices"]["@odata.id"] = - crow::utility::urlFromPieces("redfish", "v1", "Systems", - "system", "PCIeDevices"); + "/redfish/v1/Systems/system/PCIeDevices"; dbus::utility::getAssociationEndPoints( path + "/drive", @@ -300,8 +298,8 @@ inline void } nlohmann::json reference; - reference["@odata.id"] = crow::utility::urlFromPieces( - "redfish", "v1", "Chassis", chassisId, "Drives"); + reference["@odata.id"] = boost::urls::format( + "/redfish/v1/Chassis/{}/Drives", chassisId); asyncResp->res.jsonValue["Drives"] = std::move(reference); }); @@ -425,29 +423,28 @@ inline void asyncResp->res.jsonValue["Id"] = chassisId; #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL asyncResp->res.jsonValue["Thermal"]["@odata.id"] = - crow::utility::urlFromPieces("redfish", "v1", "Chassis", - chassisId, "Thermal"); + boost::urls::format("/redfish/v1/Chassis/{}/Thermal", + chassisId); // Power object asyncResp->res.jsonValue["Power"]["@odata.id"] = - crow::utility::urlFromPieces("redfish", "v1", "Chassis", - chassisId, "Power"); + boost::urls::format("/redfish/v1/Chassis/{}/Power", + chassisId); #endif #ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] = - crow::utility::urlFromPieces("redfish", "v1", "Chassis", - chassisId, "ThermalSubsystem"); + boost::urls::format( + "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId); asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] = - crow::utility::urlFromPieces("redfish", "v1", "Chassis", - chassisId, "PowerSubsystem"); + boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", + chassisId); asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] = - crow::utility::urlFromPieces("redfish", "v1", "Chassis", - chassisId, - "EnvironmentMetrics"); + boost::urls::format( + "/redfish/v1/Chassis/{}/EnvironmentMetrics", chassisId); #endif // SensorCollection asyncResp->res.jsonValue["Sensors"]["@odata.id"] = - crow::utility::urlFromPieces("redfish", "v1", "Chassis", - chassisId, "Sensors"); + boost::urls::format("/redfish/v1/Chassis/{}/Sensors", + chassisId); asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; nlohmann::json::array_t computerSystems; @@ -737,8 +734,8 @@ inline void handleChassisResetActionInfoGet( return; } asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo"; - asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( - "redfish", "v1", "Chassis", chassisId, "ResetActionInfo"); + asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( + "/redfish/v1/Chassis/{}/ResetActionInfo", chassisId); asyncResp->res.jsonValue["Name"] = "Reset Action Info"; asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; -- cgit v1.2.3