diff options
author | Ed Tanous <edtanous@google.com> | 2023-04-25 01:28:50 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-05-16 19:05:33 +0300 |
commit | ef4c65b741724d724452a3a0efe8dff0d450514a (patch) | |
tree | 9667bdff1dd9d2dbeac94bc8bd46efd83177512b /redfish-core/lib/chassis.hpp | |
parent | a87c4180fd7f2127960fbc4c89c31b7659f0cfb8 (diff) | |
download | bmcweb-ef4c65b741724d724452a3a0efe8dff0d450514a.tar.xz |
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 <edtanous@google.com>
Change-Id: Ia7b38f0a95771c862507e7d5b4aa68aa1c98403c
Diffstat (limited to 'redfish-core/lib/chassis.hpp')
-rw-r--r-- | redfish-core/lib/chassis.hpp | 49 |
1 files changed, 23 insertions, 26 deletions
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 <boost/system/error_code.hpp> +#include <boost/url/format.hpp> #include <sdbusplus/asio/property.hpp> #include <sdbusplus/unpack_properties.hpp> @@ -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"; |