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
diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp
index dd67aea..8eacb9b 100644
--- a/redfish-core/lib/power.hpp
+++ b/redfish-core/lib/power.hpp
@@ -20,6 +20,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
namespace redfish
@@ -119,10 +120,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Power/")
.privileges(redfish::privileges::getPower)
.methods(
- boost::beast::http::verb::get)([](const crow::Request&,
- const std::shared_ptr<
- bmcweb::AsyncResp>& asyncResp,
- const std::string& chassisName) {
+ boost::beast::http::verb::
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& chassisName) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue["PowerControl"] = nlohmann::json::array();
auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
@@ -309,9 +314,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Power/")
.privileges(redfish::privileges::patchPower)
.methods(boost::beast::http::verb::patch)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& chassisName) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& chassisName) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
asyncResp, chassisName,
sensors::dbus::paths.at(sensors::node::power),