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/processor.hpp b/redfish-core/lib/processor.hpp
index f304eb8..2a0e028 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -22,6 +22,7 @@
#include <app.hpp>
#include <boost/container/flat_map.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <sdbusplus/asio/property.hpp>
#include <sdbusplus/message/native_types.hpp>
@@ -1056,10 +1057,14 @@
app, "/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/")
.privileges(redfish::privileges::getOperatingConfigCollection)
.methods(
- boost::beast::http::verb::get)([](const crow::Request& req,
- const std::shared_ptr<
- bmcweb::AsyncResp>& asyncResp,
- const std::string& cpuName) {
+ boost::beast::http::verb::
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& cpuName) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue["@odata.type"] =
"#OperatingConfigCollection.OperatingConfigCollection";
asyncResp->res.jsonValue["@odata.id"] = req.url;
@@ -1118,11 +1123,15 @@
"/redfish/v1/Systems/system/Processors/<str>/OperatingConfigs/<str>/")
.privileges(redfish::privileges::getOperatingConfig)
.methods(
- boost::beast::http::verb::get)([](const crow::Request& req,
- const std::shared_ptr<
- bmcweb::AsyncResp>& asyncResp,
- const std::string& cpuName,
- const std::string& configName) {
+ boost::beast::http::verb::
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& cpuName,
+ const std::string& configName) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
// Ask for all objects implementing OperatingConfig so we can search
// for one with a matching name
crow::connections::systemBus->async_method_call(
@@ -1181,8 +1190,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Processors/")
.privileges(redfish::privileges::getProcessorCollection)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue["@odata.type"] =
"#ProcessorCollection.ProcessorCollection";
asyncResp->res.jsonValue["Name"] = "Processor Collection";
@@ -1206,9 +1219,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Processors/<str>/")
.privileges(redfish::privileges::getProcessor)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& processorId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& processorId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue["@odata.type"] =
"#Processor.v1_11_0.Processor";
asyncResp->res.jsonValue["@odata.id"] =
@@ -1220,9 +1237,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Processors/<str>/")
.privileges(redfish::privileges::patchProcessor)
.methods(boost::beast::http::verb::patch)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& processorId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& processorId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::optional<nlohmann::json> appliedConfigJson;
if (!json_util::readJsonPatch(req, asyncResp->res,
"AppliedOperatingConfig",