1 #pragma once 2 3 #include "app.hpp" 4 #include "query.hpp" 5 #include "registries/privilege_registry.hpp" 6 #include "utils/chassis_utils.hpp" 7 8 #include <memory> 9 #include <optional> 10 #include <string> 11 12 namespace redfish 13 { 14 15 inline void doPowerSubsystemCollection( 16 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 17 const std::string& chassisId, 18 const std::optional<std::string>& validChassisPath) 19 { 20 if (!validChassisPath) 21 { 22 BMCWEB_LOG_ERROR << "Not a valid chassis ID" << chassisId; 23 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 24 return; 25 } 26 27 asyncResp->res.jsonValue["@odata.type"] = 28 "#PowerSubsystem.v1_1_0.PowerSubsystem"; 29 asyncResp->res.jsonValue["Name"] = "Power Subsystem"; 30 asyncResp->res.jsonValue["Id"] = "PowerSubsystem"; 31 asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( 32 "redfish", "v1", "Chassis", chassisId, "PowerSubsystem"); 33 asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 34 asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 35 36 asyncResp->res.addHeader( 37 boost::beast::http::field::link, 38 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby"); 39 } 40 41 inline void handlePowerSubsystemCollectionGet( 42 App& app, const crow::Request& req, 43 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 44 const std::string& chassisId) 45 { 46 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 47 { 48 return; 49 } 50 51 redfish::chassis_utils::getValidChassisPath( 52 asyncResp, chassisId, 53 std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId)); 54 } 55 56 inline void requestRoutesPowerSubsystem(App& app) 57 { 58 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/") 59 .privileges(redfish::privileges::getPowerSubsystem) 60 .methods(boost::beast::http::verb::get)( 61 std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app))); 62 } 63 64 } // namespace redfish 65