summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Liu <liuxiwei@inspur.com>2022-11-16 06:12:21 +0300
committerGeorge Liu <liuxiwei@inspur.com>2022-11-23 03:35:33 +0300
commit1aee751c0feeb9b369eb76f09d7910d2bb124d61 (patch)
treeecc2050b5b34ba7fbb693810231c5330fabcc277
parent33a32b3427483fbeab3f1cf6c57dd1593db674a1 (diff)
downloadbmcweb-1aee751c0feeb9b369eb76f09d7910d2bb124d61.tar.xz
Add Link header handling to ThermalSubsystem
Along with adding Link header, this commit updates ThermalSubsystem to respond to HEAD requests. The link header is something required by the Redfish spec. Also, Removed redundant code[1] [1] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/58731/2/redfish-core/lib/thermal_subsystem.hpp#b48 Tested: HEAD /redfish/v1/Chassis/<str>/ThermalSubsystem returns a correct looking Link header. Following that Link header resolves the schema file. Get /redfish/v1/Chassis/BadChassis/ThermalSubsystem returns 404. Signed-off-by: George Liu <liuxiwei@inspur.com> Change-Id: Ib93573808e4370ac45c2051517cd3f1c28e0f8bb
-rw-r--r--redfish-core/lib/thermal_subsystem.hpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/redfish-core/lib/thermal_subsystem.hpp b/redfish-core/lib/thermal_subsystem.hpp
index 390b294206..d86e3c30db 100644
--- a/redfish-core/lib/thermal_subsystem.hpp
+++ b/redfish-core/lib/thermal_subsystem.hpp
@@ -24,6 +24,10 @@ inline void doThermalSubsystemCollection(
messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
return;
}
+
+ asyncResp->res.addHeader(
+ boost::beast::http::field::link,
+ "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
asyncResp->res.jsonValue["@odata.type"] =
"#ThermalSubsystem.v1_0_0.ThermalSubsystem";
asyncResp->res.jsonValue["Name"] = "Thermal Subsystem";
@@ -36,16 +40,40 @@ inline void doThermalSubsystemCollection(
asyncResp->res.jsonValue["Status"]["Health"] = "OK";
}
+inline void handleThermalSubsystemCollectionHead(
+ App& app, const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& chassisId)
+{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp))
+ {
+ return;
+ }
+
+ auto respHandler = [asyncResp, chassisId](
+ const std::optional<std::string>& validChassisPath) {
+ if (!validChassisPath)
+ {
+ messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
+ return;
+ }
+ asyncResp->res.addHeader(
+ boost::beast::http::field::link,
+ "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
+ };
+ redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
+ std::bind_front(respHandler));
+}
+
inline void handleThermalSubsystemCollectionGet(
App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param)
+ const std::string& chassisId)
{
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
{
return;
}
- const std::string& chassisId = param;
redfish::chassis_utils::getValidChassisPath(
asyncResp, chassisId,
@@ -55,6 +83,11 @@ inline void handleThermalSubsystemCollectionGet(
inline void requestRoutesThermalSubsystem(App& app)
{
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
+ .privileges(redfish::privileges::headThermalSubsystem)
+ .methods(boost::beast::http::verb::head)(std::bind_front(
+ handleThermalSubsystemCollectionHead, std::ref(app)));
+
+ BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
.privileges(redfish::privileges::getThermalSubsystem)
.methods(boost::beast::http::verb::get)(std::bind_front(
handleThermalSubsystemCollectionGet, std::ref(app)));