summaryrefslogtreecommitdiff
path: root/redfish-core/lib/ethernet.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-03-25 23:07:27 +0300
committerEd Tanous <ed@tanous.net>2022-04-06 00:20:56 +0300
commit45ca1b868e47978a4d2e8ebb680cb384e804c97e (patch)
tree985a905fd8ac9bff693933ff98e3f4206f6aee4b /redfish-core/lib/ethernet.hpp
parente7b1b62b39ba31ba368c42cb6f4fa7af43c65961 (diff)
downloadbmcweb-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/ethernet.hpp')
-rw-r--r--redfish-core/lib/ethernet.hpp88
1 files changed, 62 insertions, 26 deletions
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 85fa633330..bdc2a65152 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -20,6 +20,7 @@
#include <dbus_singleton.hpp>
#include <dbus_utility.hpp>
#include <error_messages.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <utils/json_utils.hpp>
@@ -1852,10 +1853,15 @@ inline void requestEthernetInterfacesRoutes(App& app)
{
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/")
.privileges(redfish::privileges::getEthernetInterfaceCollection)
- .methods(
- boost::beast::http::verb::
- get)([](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ .methods(boost::beast::http::verb::get)([&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"] =
"#EthernetInterfaceCollection.EthernetInterfaceCollection";
asyncResp->res.jsonValue["@odata.id"] =
@@ -1902,9 +1908,13 @@ inline void requestEthernetInterfacesRoutes(App& app)
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/")
.privileges(redfish::privileges::getEthernetInterface)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& ifaceId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& ifaceId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
getEthernetIfaceData(
ifaceId,
[asyncResp,
@@ -1939,9 +1949,13 @@ inline void requestEthernetInterfacesRoutes(App& app)
.privileges(redfish::privileges::patchEthernetInterface)
.methods(boost::beast::http::verb::patch)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& ifaceId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& ifaceId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::optional<std::string> hostname;
std::optional<std::string> fqdn;
std::optional<std::string> macAddress;
@@ -2096,11 +2110,15 @@ inline void requestEthernetInterfacesRoutes(App& app)
BMCWEB_ROUTE(
app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/<str>/")
.privileges(redfish::privileges::getVLanNetworkInterface)
-
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& /* req */,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& parentIfaceId, const std::string& ifaceId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& parentIfaceId,
+ const std::string& ifaceId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue["@odata.type"] =
"#VLanNetworkInterface.v1_1_0.VLanNetworkInterface";
asyncResp->res.jsonValue["Name"] = "VLAN Network Interface";
@@ -2142,9 +2160,14 @@ inline void requestEthernetInterfacesRoutes(App& app)
//.privileges(redfish::privileges::patchVLanNetworkInterface)
.privileges({{"ConfigureComponents"}})
.methods(boost::beast::http::verb::patch)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& parentIfaceId, const std::string& ifaceId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& parentIfaceId,
+ const std::string& ifaceId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (!verifyNames(parentIfaceId, ifaceId))
{
messages::resourceNotFound(
@@ -2224,9 +2247,14 @@ inline void requestEthernetInterfacesRoutes(App& app)
//.privileges(redfish::privileges::deleteVLanNetworkInterface)
.privileges({{"ConfigureComponents"}})
.methods(boost::beast::http::verb::delete_)(
- [](const crow::Request& /* req */,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& parentIfaceId, const std::string& ifaceId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& parentIfaceId,
+ const std::string& ifaceId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (!verifyNames(parentIfaceId, ifaceId))
{
messages::resourceNotFound(
@@ -2278,9 +2306,13 @@ inline void requestEthernetInterfacesRoutes(App& app)
.privileges(redfish::privileges::getVLanNetworkInterfaceCollection)
.methods(
boost::beast::http::verb::
- get)([](const crow::Request& /* req */,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& rootInterfaceName) {
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& rootInterfaceName) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
// Get eth interface list, and call the below callback for JSON
// preparation
getEthernetIfaceList([asyncResp, rootInterfaceName](
@@ -2337,9 +2369,13 @@ inline void requestEthernetInterfacesRoutes(App& app)
//.privileges(redfish::privileges::postVLanNetworkInterfaceCollection)
.privileges({{"ConfigureComponents"}})
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& rootInterfaceName) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& rootInterfaceName) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
bool vlanEnable = false;
uint32_t vlanId = 0;
if (!json_util::readJsonPatch(req, asyncResp->res, "VLANId",