diff options
author | Ed Tanous <edtanous@google.com> | 2022-03-25 23:07:27 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-04-06 00:20:56 +0300 |
commit | 45ca1b868e47978a4d2e8ebb680cb384e804c97e (patch) | |
tree | 985a905fd8ac9bff693933ff98e3f4206f6aee4b /redfish-core/lib/sensors.hpp | |
parent | e7b1b62b39ba31ba368c42cb6f4fa7af43c65961 (diff) | |
download | bmcweb-45ca1b868e47978a4d2e8ebb680cb384e804c97e.tar.xz |
Add setUpRedfishRoute to all nodes in redfish
For better or worse, the series ahead of this is making use of
setUpRedfishRoute to do the common "redfish specified" things that need
to be done for a connection, like header checking, filtering, and other
things. In the current model, where BMCWEB_ROUTE is a common function
for all HTTP routes, this means we need to propagate this injection call
into the whole tree ahead of the requests being handled.
In a perfect world, we would invent something like a REDFISH_ROUTE
macro, but because macros are discouraged, the routes take a variadic
template of parameters, and each call to the route has a .privileges()
call in the middle, there's no good way to effect this change in a less
costly manner. This was messaged both in the prior reviews, and on
discord sourcing improvements on this pattern, to which none arose.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Id29cc799e214edad41e48fc7ce6eed0521f90ecb
Diffstat (limited to 'redfish-core/lib/sensors.hpp')
-rw-r--r-- | redfish-core/lib/sensors.hpp | 106 |
1 files changed, 59 insertions, 47 deletions
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index d501b70022..25ac5e0448 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -22,6 +22,7 @@ #include <boost/range/algorithm/replace_copy_if.hpp> #include <dbus_singleton.hpp> #include <dbus_utility.hpp> +#include <query.hpp> #include <registries/privilege_registry.hpp> #include <sdbusplus/asio/property.hpp> #include <utils/json_utils.hpp> @@ -2924,56 +2925,62 @@ inline void requestRoutesSensorCollection(App& app) { BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Sensors/") .privileges(redfish::privileges::getSensorCollection) - .methods( - boost::beast::http::verb::get)([](const crow::Request&, - const std::shared_ptr< - bmcweb::AsyncResp>& aResp, - const std::string& chassisId) { - BMCWEB_LOG_DEBUG << "SensorCollection doGet enter"; + .methods(boost::beast::http::verb::get)( + [&app](const crow::Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& aResp, + const std::string& chassisId) { + if (!redfish::setUpRedfishRoute(app, req, aResp->res)) + { + return; + } - std::shared_ptr<SensorsAsyncResp> asyncResp = - std::make_shared<SensorsAsyncResp>( - aResp, chassisId, - sensors::dbus::paths.at(sensors::node::sensors), - sensors::node::sensors); + BMCWEB_LOG_DEBUG << "SensorCollection doGet enter"; - auto getChassisCb = - [asyncResp]( - const std::shared_ptr< - boost::container::flat_set<std::string>>& sensorNames) { - BMCWEB_LOG_DEBUG << "getChassisCb enter"; + std::shared_ptr<SensorsAsyncResp> asyncResp = + std::make_shared<SensorsAsyncResp>( + aResp, chassisId, + sensors::dbus::paths.at(sensors::node::sensors), + sensors::node::sensors); - nlohmann::json& entriesArray = - asyncResp->asyncResp->res.jsonValue["Members"]; - for (auto& sensor : *sensorNames) - { - BMCWEB_LOG_DEBUG << "Adding sensor: " << sensor; + auto getChassisCb = + [asyncResp](const std::shared_ptr< + boost::container::flat_set<std::string>>& + sensorNames) { + BMCWEB_LOG_DEBUG << "getChassisCb enter"; - sdbusplus::message::object_path path(sensor); - std::string sensorName = path.filename(); - if (sensorName.empty()) + nlohmann::json& entriesArray = + asyncResp->asyncResp->res.jsonValue["Members"]; + for (auto& sensor : *sensorNames) { - BMCWEB_LOG_ERROR << "Invalid sensor path: " - << sensor; - messages::internalError(asyncResp->asyncResp->res); - return; + BMCWEB_LOG_DEBUG << "Adding sensor: " << sensor; + + sdbusplus::message::object_path path(sensor); + std::string sensorName = path.filename(); + if (sensorName.empty()) + { + BMCWEB_LOG_ERROR << "Invalid sensor path: " + << sensor; + messages::internalError( + asyncResp->asyncResp->res); + return; + } + entriesArray.push_back( + {{"@odata.id", "/redfish/v1/Chassis/" + + asyncResp->chassisId + "/" + + asyncResp->chassisSubNode + + "/" + sensorName}}); } - entriesArray.push_back( - {{"@odata.id", "/redfish/v1/Chassis/" + - asyncResp->chassisId + "/" + - asyncResp->chassisSubNode + "/" + - sensorName}}); - } - asyncResp->asyncResp->res.jsonValue["Members@odata.count"] = - entriesArray.size(); - BMCWEB_LOG_DEBUG << "getChassisCb exit"; - }; + asyncResp->asyncResp->res + .jsonValue["Members@odata.count"] = + entriesArray.size(); + BMCWEB_LOG_DEBUG << "getChassisCb exit"; + }; - // Get set of sensors in chassis - getChassis(asyncResp, std::move(getChassisCb)); - BMCWEB_LOG_DEBUG << "SensorCollection doGet exit"; - }); + // Get set of sensors in chassis + getChassis(asyncResp, std::move(getChassisCb)); + BMCWEB_LOG_DEBUG << "SensorCollection doGet exit"; + }); } inline void requestRoutesSensor(App& app) @@ -2981,11 +2988,16 @@ inline void requestRoutesSensor(App& app) BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Sensors/<str>/") .privileges(redfish::privileges::getSensor) .methods( - boost::beast::http::verb::get)([](const crow::Request&, - const std::shared_ptr< - bmcweb::AsyncResp>& aResp, - const std::string& chassisId, - const std::string& sensorName) { + boost::beast::http::verb::get)([&app]( + const crow::Request& req, + const std::shared_ptr< + bmcweb::AsyncResp>& aResp, + const std::string& chassisId, + const std::string& sensorName) { + if (!redfish::setUpRedfishRoute(app, req, aResp->res)) + { + return; + } BMCWEB_LOG_DEBUG << "Sensor doGet enter"; std::shared_ptr<SensorsAsyncResp> asyncResp = std::make_shared<SensorsAsyncResp>(aResp, chassisId, |