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/account_service.hpp b/redfish-core/lib/account_service.hpp
index 6e7cf28..435d890 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -20,6 +20,7 @@
#include <error_messages.hpp>
#include <openbmc_dbus_rest.hpp>
#include <persistent_data.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <sdbusplus/asio/property.hpp>
#include <utils/json_utils.hpp>
@@ -1261,11 +1262,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
.privileges(redfish::privileges::getAccountService)
- .methods(
- boost::beast::http::verb::get)([](const crow::Request& req,
- const std::shared_ptr<
- bmcweb::AsyncResp>& asyncResp)
- -> void {
+ .methods(boost::beast::http::verb::get)([&app](const crow::Request& req,
+ const std::shared_ptr<
+ bmcweb::AsyncResp>&
+ asyncResp) -> void {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
const persistent_data::AuthConfigMethods& authMethodsConfig =
persistent_data::SessionStore::getInstance()
.getAuthMethodsConfig();
@@ -1378,8 +1382,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
.privileges(redfish::privileges::patchAccountService)
.methods(boost::beast::http::verb::patch)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) -> void {
+ [&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) -> void {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::optional<uint32_t> unlockTimeout;
std::optional<uint16_t> lockoutThreshold;
std::optional<uint8_t> minPasswordLength;
@@ -1495,8 +1504,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
.privileges(redfish::privileges::getManagerAccountCollection)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) -> void {
+ [&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) -> void {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue = {
{"@odata.id", "/redfish/v1/AccountService/Accounts"},
{"@odata.type", "#ManagerAccountCollection."
@@ -1569,10 +1583,15 @@
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
.privileges(redfish::privileges::postManagerAccountCollection)
- .methods(boost::beast::http::verb::post)([](const crow::Request& req,
- const std::shared_ptr<
- bmcweb::AsyncResp>&
- asyncResp) -> void {
+ .methods(
+ boost::beast::http::verb::post)([&app](const crow::Request& req,
+ const std::shared_ptr<
+ bmcweb::AsyncResp>&
+ asyncResp) -> void {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::string username;
std::string password;
std::optional<std::string> roleId("User");
@@ -1689,9 +1708,13 @@
.privileges(redfish::privileges::getManagerAccount)
.methods(
boost::beast::http::verb::
- get)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& accountName) -> void {
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& accountName) -> void {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (req.session->username != accountName)
{
// At this point we've determined that the user is trying to
@@ -1847,9 +1870,13 @@
// yet
.privileges({{"ConfigureUsers"}, {"ConfigureSelf"}})
.methods(boost::beast::http::verb::patch)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& username) -> void {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& username) -> void {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::optional<std::string> newUserName;
std::optional<std::string> password;
std::optional<bool> enabled;
@@ -1924,9 +1951,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
.privileges(redfish::privileges::deleteManagerAccount)
.methods(boost::beast::http::verb::delete_)(
- [](const crow::Request& /*req*/,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& username) -> void {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& username) -> void {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
tempObjPath /= username;
const std::string userPath(tempObjPath);
diff --git a/redfish-core/lib/bios.hpp b/redfish-core/lib/bios.hpp
index d8475ae..084c846 100644
--- a/redfish-core/lib/bios.hpp
+++ b/redfish-core/lib/bios.hpp
@@ -1,17 +1,23 @@
#pragma once
#include <app.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <utils/fw_utils.hpp>
+
namespace redfish
{
/**
* BiosService class supports handle get method for bios.
*/
inline void
- handleBiosServiceGet(const crow::Request& /*req*/,
+ handleBiosServiceGet(crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios";
asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
@@ -24,11 +30,13 @@
fw_util::populateFirmwareInformation(asyncResp, fw_util::biosPurpose, "",
true);
}
+
inline void requestRoutesBiosService(App& app)
{
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/")
.privileges(redfish::privileges::getBios)
- .methods(boost::beast::http::verb::get)(handleBiosServiceGet);
+ .methods(boost::beast::http::verb::get)(
+ std::bind_front(handleBiosServiceGet, std::ref(app)));
}
/**
@@ -39,9 +47,13 @@
* Analyzes POST body message before sends Reset request data to D-Bus.
*/
inline void
- handleBiosResetPost(const crow::Request& /*req*/,
+ handleBiosResetPost(crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec) {
if (ec)
@@ -59,7 +71,8 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/")
.privileges(redfish::privileges::postBios)
- .methods(boost::beast::http::verb::post)(handleBiosResetPost);
+ .methods(boost::beast::http::verb::post)(
+ std::bind_front(handleBiosResetPost, std::ref(app)));
}
} // namespace redfish
diff --git a/redfish-core/lib/cable.hpp b/redfish-core/lib/cable.hpp
index 241baf4..6ab87a8 100644
--- a/redfish-core/lib/cable.hpp
+++ b/redfish-core/lib/cable.hpp
@@ -1,5 +1,6 @@
#pragma once
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <utils/json_utils.hpp>
namespace redfish
@@ -102,9 +103,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Cables/<str>/")
.privileges(redfish::privileges::getCable)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& cableId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& cableId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
BMCWEB_LOG_DEBUG << "Cable Id: " << cableId;
auto respHandler =
[asyncResp,
@@ -166,8 +171,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Cables/")
.privileges(redfish::privileges::getCableCollection)
.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"] =
"#CableCollection.CableCollection";
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Cables";
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index 4882ec3..9bea9b9 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -4,6 +4,7 @@
#include <boost/convert.hpp>
#include <boost/convert/strtol.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
namespace redfish
@@ -44,10 +45,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/CertificateService/")
.privileges(redfish::privileges::getCertificateService)
- .methods(
- boost::beast::http::verb::
- get)([](const crow::Request& req,
- 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",
"#CertificateService.v1_0_0.CertificateService"},
@@ -247,8 +252,13 @@
.privileges({{"ConfigureComponents"}})
.methods(
boost::beast::http::verb::
- post)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ post)([&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
static const int rsaKeyBitLength = 2048;
// Required parameters
@@ -674,8 +684,13 @@
.privileges(redfish::privileges::postCertificateService)
.methods(
boost::beast::http::verb::
- post)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ post)([&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::string certificate;
nlohmann::json certificateUri;
std::optional<std::string> certificateType = "PEM";
@@ -792,9 +807,13 @@
.privileges(redfish::privileges::getCertificate)
.methods(
boost::beast::http::verb::
- get)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) -> void {
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) -> void {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (param.empty())
{
messages::internalError(asyncResp->res);
@@ -824,10 +843,14 @@
BMCWEB_ROUTE(app,
"/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/")
.privileges(redfish::privileges::getCertificateCollection)
- .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.id",
"/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates"},
@@ -870,8 +893,13 @@
.privileges(redfish::privileges::postCertificateCollection)
.methods(
boost::beast::http::verb::
- post)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ post)([&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
BMCWEB_LOG_DEBUG << "HTTPSCertificateCollection::doPost";
asyncResp->res.jsonValue = {{"Name", "HTTPS Certificate"},
@@ -972,10 +1000,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/CertificateService/CertificateLocations/")
.privileges(redfish::privileges::getCertificateLocations)
- .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.id",
"/redfish/v1/CertificateService/CertificateLocations"},
@@ -1011,10 +1043,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/LDAP/Certificates/")
.privileges(redfish::privileges::getCertificateCollection)
- .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.id", "/redfish/v1/AccountService/LDAP/Certificates"},
{"@odata.type", "#CertificateCollection.CertificateCollection"},
@@ -1056,8 +1092,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/LDAP/Certificates/")
.privileges(redfish::privileges::postCertificateCollection)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
- 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;
+ }
std::string certFileBody =
getCertificateFromReqBody(asyncResp, req);
@@ -1113,9 +1153,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/LDAP/Certificates/<str>/")
.privileges(redfish::privileges::getCertificate)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string&) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string&) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
long id = getIDFromURL(req.url);
if (id < 0)
{
@@ -1143,10 +1187,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Truststore/Certificates/")
.privileges(redfish::privileges::getCertificate)
- .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.id",
"/redfish/v1/Managers/bmc/Truststore/Certificates/"},
@@ -1189,8 +1237,13 @@
.privileges(redfish::privileges::postCertificateCollection)
.methods(
boost::beast::http::verb::
- post)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ post)([&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::string certFileBody =
getCertificateFromReqBody(asyncResp, req);
@@ -1244,9 +1297,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Truststore/Certificates/<str>/")
.privileges(redfish::privileges::getCertificate)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string&) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string&) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
long id = getIDFromURL(req.url);
if (id < 0)
{
@@ -1270,9 +1327,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Truststore/Certificates/<str>/")
.privileges(redfish::privileges::deleteCertificate)
.methods(boost::beast::http::verb::delete_)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (param.empty())
{
messages::internalError(asyncResp->res);
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index 45348db..47b5070 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -20,6 +20,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <sdbusplus/asio/property.hpp>
#include <utils/collection.hpp>
@@ -141,8 +142,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/")
.privileges(redfish::privileges::getChassisCollection)
.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"] =
"#ChassisCollection.ChassisCollection";
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
@@ -206,10 +211,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
.privileges(redfish::privileges::getChassis)
.methods(
- boost::beast::http::verb::get)([](const crow::Request&,
- const std::shared_ptr<
- bmcweb::AsyncResp>& asyncResp,
- const std::string& chassisId) {
+ boost::beast::http::verb::
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& chassisId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
const std::array<const char*, 2> interfaces = {
"xyz.openbmc_project.Inventory.Item.Board",
"xyz.openbmc_project.Inventory.Item.Chassis"};
@@ -438,9 +447,14 @@
.privileges(redfish::privileges::patchChassis)
.methods(
boost::beast::http::verb::
- patch)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ patch)([&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::optional<bool> locationIndicatorActive;
std::optional<std::string> indicatorLed;
@@ -636,9 +650,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/")
.privileges(redfish::privileges::postChassis)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string&) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string&) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
std::string resetType;
@@ -671,11 +689,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/")
.privileges(redfish::privileges::getActionInfo)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& chassisId)
-
- {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& chassisId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue = {
{"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"},
{"@odata.id",
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 85fa633..bdc2a65 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 @@
{
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 @@
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 @@
.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 @@
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 @@
//.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 @@
//.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 @@
.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 @@
//.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",
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index 134ef24..04b46e0 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -18,6 +18,7 @@
#include <app.hpp>
#include <boost/beast/http/fields.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <span>
@@ -46,10 +47,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/EventService/")
.privileges(redfish::privileges::getEventService)
- .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", "#EventService.v1_5_0.EventService"},
{"Id", "EventService"},
@@ -91,10 +96,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/EventService/")
.privileges(redfish::privileges::patchEventService)
.methods(boost::beast::http::verb::patch)(
- [](const crow::Request& req,
- 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;
+ }
std::optional<bool> serviceEnabled;
std::optional<uint32_t> retryAttemps;
std::optional<uint32_t> retryInterval;
@@ -159,8 +166,12 @@
app, "/redfish/v1/EventService/Actions/EventService.SubmitTestEvent/")
.privileges(redfish::privileges::postEventService)
.methods(boost::beast::http::verb::post)(
- [](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;
+ }
if (!EventServiceManager::getInstance().sendTestEventLog())
{
messages::serviceDisabled(asyncResp->res,
@@ -176,8 +187,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/")
.privileges(redfish::privileges::getEventDestinationCollection)
.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",
"#EventDestinationCollection.EventDestinationCollection"},
@@ -204,8 +219,13 @@
.privileges(redfish::privileges::postEventDestinationCollection)
.methods(
boost::beast::http::verb::
- post)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ post)([&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (EventServiceManager::getInstance().getNumberOfSubscriptions() >=
maxNoOfSubscriptions)
{
@@ -501,9 +521,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/<str>/")
.privileges(redfish::privileges::getEventDestination)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::shared_ptr<Subscription> subValue =
EventServiceManager::getInstance().getSubscription(param);
if (subValue == nullptr)
@@ -556,9 +580,13 @@
//.privileges(redfish::privileges::patchEventDestination)
.privileges({{"ConfigureManager"}})
.methods(boost::beast::http::verb::patch)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::shared_ptr<Subscription> subValue =
EventServiceManager::getInstance().getSubscription(param);
if (subValue == nullptr)
@@ -632,9 +660,13 @@
//.privileges(redfish::privileges::deleteEventDestination)
.privileges({{"ConfigureManager"}})
.methods(boost::beast::http::verb::delete_)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (!EventServiceManager::getInstance().isSubscriptionExist(
param))
{
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index ed83ff6..e01b55f 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -5,6 +5,7 @@
#include <dbus_singleton.hpp>
#include <dbus_utility.hpp>
#include <error_messages.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <sdbusplus/asio/property.hpp>
#include <utils/json_utils.hpp>
@@ -728,10 +729,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/hypervisor/")
.privileges(redfish::privileges::getComputerSystem)
- .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;
+ }
sdbusplus::asio::getProperty<std::string>(
*crow::connections::systemBus, "xyz.openbmc_project.Settings",
"/xyz/openbmc_project/network/hypervisor",
@@ -772,10 +777,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/hypervisor/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;
+ }
const std::array<const char*, 1> interfaces = {
"xyz.openbmc_project.Network.EthernetInterface"};
@@ -829,17 +838,21 @@
BMCWEB_ROUTE(app,
"/redfish/v1/Systems/hypervisor/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& id) {
- getHypervisorIfaceData(
- id,
- [asyncResp, ifaceId{std::string(id)}](
- const bool& success, const EthernetInterfaceData& ethData,
- const boost::container::flat_set<IPv4AddressData>&
- ipv4Data) {
+ .methods(boost::beast::http::verb::get)(
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& id) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+ getHypervisorIfaceData(id, [asyncResp,
+ ifaceId{std::string(id)}](
+ const bool& success,
+ const EthernetInterfaceData&
+ ethData,
+ const boost::container::flat_set<
+ IPv4AddressData>& ipv4Data) {
if (!success)
{
messages::resourceNotFound(
@@ -855,16 +868,21 @@
parseInterfaceData(asyncResp->res.jsonValue, ifaceId,
ethData, ipv4Data);
});
- });
+ });
BMCWEB_ROUTE(app,
"/redfish/v1/Systems/hypervisor/EthernetInterfaces/<str>/")
.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) {
+ patch)([&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::vector<nlohmann::json>> ipv4StaticAddresses;
std::optional<nlohmann::json> ipv4Addresses;
@@ -976,8 +994,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/hypervisor/ResetActionInfo/")
.privileges(redfish::privileges::getActionInfo)
.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;
+ }
// Only return action info if hypervisor D-Bus object present
crow::connections::systemBus->async_method_call(
[asyncResp](
@@ -1035,8 +1057,12 @@
"/redfish/v1/Systems/hypervisor/Actions/ComputerSystem.Reset/")
.privileges(redfish::privileges::postComputerSystem)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
- 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;
+ }
std::optional<std::string> resetType;
if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
resetType))
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index e474f0a..b79fd03 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -34,6 +34,7 @@
#include <boost/system/linux_error.hpp>
#include <dbus_utility.hpp>
#include <error_messages.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <charconv>
@@ -527,9 +528,14 @@
}
inline void
- getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ getDumpEntryById(crow::App& app, const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& entryID, const std::string& dumpType)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::string dumpPath;
if (dumpType == "BMC")
{
@@ -767,7 +773,6 @@
inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const crow::Request& req, const std::string& dumpType)
{
-
std::string dumpPath;
if (dumpType == "BMC")
{
@@ -934,89 +939,92 @@
*/
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/")
.privileges(redfish::privileges::getLogServiceCollection)
- .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))
{
- // Collections don't include the static data added by SubRoute
- // because it has a duplicate entry for members
- asyncResp->res.jsonValue["@odata.type"] =
- "#LogServiceCollection.LogServiceCollection";
- asyncResp->res.jsonValue["@odata.id"] =
- "/redfish/v1/Systems/system/LogServices";
- asyncResp->res.jsonValue["Name"] =
- "System Log Services Collection";
- asyncResp->res.jsonValue["Description"] =
- "Collection of LogServices for this Computer System";
- nlohmann::json& logServiceArray =
- asyncResp->res.jsonValue["Members"];
- logServiceArray = nlohmann::json::array();
- logServiceArray.push_back(
- {{"@odata.id",
- "/redfish/v1/Systems/system/LogServices/EventLog"}});
+ return;
+ }
+ // Collections don't include the static data added by SubRoute
+ // because it has a duplicate entry for members
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#LogServiceCollection.LogServiceCollection";
+ asyncResp->res.jsonValue["@odata.id"] =
+ "/redfish/v1/Systems/system/LogServices";
+ asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
+ asyncResp->res.jsonValue["Description"] =
+ "Collection of LogServices for this Computer System";
+ nlohmann::json& logServiceArray =
+ asyncResp->res.jsonValue["Members"];
+ logServiceArray = nlohmann::json::array();
+ logServiceArray.push_back(
+ {{"@odata.id",
+ "/redfish/v1/Systems/system/LogServices/EventLog"}});
#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
- logServiceArray.push_back(
- {{"@odata.id",
- "/redfish/v1/Systems/system/LogServices/Dump"}});
+ logServiceArray.push_back(
+ {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}});
#endif
#ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
- logServiceArray.push_back(
- {{"@odata.id",
- "/redfish/v1/Systems/system/LogServices/Crashdump"}});
+ logServiceArray.push_back(
+ {{"@odata.id",
+ "/redfish/v1/Systems/system/LogServices/Crashdump"}});
#endif
#ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER
- logServiceArray.push_back(
- {{"@odata.id",
- "/redfish/v1/Systems/system/LogServices/HostLogger"}});
+ logServiceArray.push_back(
+ {{"@odata.id",
+ "/redfish/v1/Systems/system/LogServices/HostLogger"}});
#endif
- asyncResp->res.jsonValue["Members@odata.count"] =
- logServiceArray.size();
+ asyncResp->res.jsonValue["Members@odata.count"] =
+ logServiceArray.size();
- crow::connections::systemBus->async_method_call(
- [asyncResp](
- const boost::system::error_code ec,
- const dbus::utility::MapperGetSubTreePathsResponse&
- subtreePath) {
- if (ec)
+ crow::connections::systemBus->async_method_call(
+ [asyncResp](const boost::system::error_code ec,
+ const dbus::utility::MapperGetSubTreePathsResponse&
+ subtreePath) {
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << ec;
+ return;
+ }
+
+ for (const auto& pathStr : subtreePath)
+ {
+ if (pathStr.find("PostCode") != std::string::npos)
{
- BMCWEB_LOG_ERROR << ec;
+ nlohmann::json& logServiceArrayLocal =
+ asyncResp->res.jsonValue["Members"];
+ logServiceArrayLocal.push_back(
+ {{"@odata.id",
+ "/redfish/v1/Systems/system/LogServices/PostCodes"}});
+ asyncResp->res.jsonValue["Members@odata.count"] =
+ logServiceArrayLocal.size();
return;
}
-
- for (const auto& pathStr : subtreePath)
- {
- if (pathStr.find("PostCode") != std::string::npos)
- {
- nlohmann::json& logServiceArrayLocal =
- asyncResp->res.jsonValue["Members"];
- logServiceArrayLocal.push_back(
- {{"@odata.id",
- "/redfish/v1/Systems/system/LogServices/PostCodes"}});
- asyncResp->res
- .jsonValue["Members@odata.count"] =
- logServiceArrayLocal.size();
- return;
- }
- }
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/",
- 0, std::array<const char*, 1>{postCodeIface});
- });
+ }
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
+ std::array<const char*, 1>{postCodeIface});
+ });
}
inline void requestRoutesEventLogService(App& app)
{
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/EventLog/")
.privileges(redfish::privileges::getLogService)
- .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.id"] =
"/redfish/v1/Systems/system/LogServices/EventLog";
asyncResp->res.jsonValue["@odata.type"] =
@@ -1051,8 +1059,12 @@
"/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/")
.privileges({{"ConfigureComponents"}})
.methods(boost::beast::http::verb::post)(
- [](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;
+ }
// Clear the EventLog by deleting the log files
std::vector<std::filesystem::path> redfishLogFiles;
if (getRedfishLogFiles(redfishLogFiles))
@@ -1184,10 +1196,14 @@
BMCWEB_ROUTE(app,
"/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
.privileges(redfish::privileges::getLogEntryCollection)
- .methods(
- boost::beast::http::verb::
- get)([](const crow::Request& req,
- 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;
+ }
uint64_t skip = 0;
uint64_t top = maxEntriesPerPage; // Show max entries by default
if (!getSkipParam(asyncResp, req, skip))
@@ -1278,9 +1294,13 @@
app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
const std::string& targetID = param;
// Go through the log files and check the unique ID for each
@@ -1339,10 +1359,14 @@
BMCWEB_ROUTE(app,
"/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
.privileges(redfish::privileges::getLogEntryCollection)
- .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;
+ }
// Collections don't include the static data added by SubRoute
// because it has a duplicate entry for members
asyncResp->res.jsonValue["@odata.type"] =
@@ -1499,129 +1523,135 @@
BMCWEB_ROUTE(
app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/")
.privileges(redfish::privileges::getLogEntry)
- .methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param)
-
+ .methods(
+ boost::beast::http::verb::
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
{
- std::string entryID = param;
- dbus::utility::escapePathForDbus(entryID);
+ return;
+ }
+ std::string entryID = param;
+ dbus::utility::escapePathForDbus(entryID);
- // DBus implementation of EventLog/Entries
- // Make call to Logging Service to find all log entry objects
- crow::connections::systemBus->async_method_call(
- [asyncResp,
- entryID](const boost::system::error_code ec,
- const dbus::utility::DBusPropertiesMap& resp) {
- if (ec.value() == EBADR)
- {
- messages::resourceNotFound(
- asyncResp->res, "EventLogEntry", entryID);
- return;
- }
- if (ec)
- {
- BMCWEB_LOG_ERROR
- << "EventLogEntry (DBus) resp_handler got error "
- << ec;
- messages::internalError(asyncResp->res);
- return;
- }
- const uint32_t* id = nullptr;
- const uint64_t* timestamp = nullptr;
- const uint64_t* updateTimestamp = nullptr;
- const std::string* severity = nullptr;
- const std::string* message = nullptr;
- const std::string* filePath = nullptr;
- bool resolved = false;
+ // DBus implementation of EventLog/Entries
+ // Make call to Logging Service to find all log entry objects
+ crow::connections::systemBus->async_method_call(
+ [asyncResp,
+ entryID](const boost::system::error_code ec,
+ const dbus::utility::DBusPropertiesMap& resp) {
+ if (ec.value() == EBADR)
+ {
+ messages::resourceNotFound(asyncResp->res,
+ "EventLogEntry", entryID);
+ return;
+ }
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR
+ << "EventLogEntry (DBus) resp_handler got error "
+ << ec;
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ const uint32_t* id = nullptr;
+ const uint64_t* timestamp = nullptr;
+ const uint64_t* updateTimestamp = nullptr;
+ const std::string* severity = nullptr;
+ const std::string* message = nullptr;
+ const std::string* filePath = nullptr;
+ bool resolved = false;
- for (const auto& propertyMap : resp)
+ for (const auto& propertyMap : resp)
+ {
+ if (propertyMap.first == "Id")
{
- if (propertyMap.first == "Id")
- {
- id = std::get_if<uint32_t>(&propertyMap.second);
- }
- else if (propertyMap.first == "Timestamp")
- {
- timestamp =
- std::get_if<uint64_t>(&propertyMap.second);
- }
- else if (propertyMap.first == "UpdateTimestamp")
- {
- updateTimestamp =
- std::get_if<uint64_t>(&propertyMap.second);
- }
- else if (propertyMap.first == "Severity")
- {
- severity = std::get_if<std::string>(
- &propertyMap.second);
- }
- else if (propertyMap.first == "Message")
- {
- message = std::get_if<std::string>(
- &propertyMap.second);
- }
- else if (propertyMap.first == "Resolved")
- {
- const bool* resolveptr =
- std::get_if<bool>(&propertyMap.second);
- if (resolveptr == nullptr)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- resolved = *resolveptr;
- }
- else if (propertyMap.first == "Path")
- {
- filePath = std::get_if<std::string>(
- &propertyMap.second);
- }
+ id = std::get_if<uint32_t>(&propertyMap.second);
}
- if (id == nullptr || message == nullptr ||
- severity == nullptr || timestamp == nullptr ||
- updateTimestamp == nullptr)
+ else if (propertyMap.first == "Timestamp")
{
- messages::internalError(asyncResp->res);
- return;
+ timestamp =
+ std::get_if<uint64_t>(&propertyMap.second);
}
- asyncResp->res.jsonValue["@odata.type"] =
- "#LogEntry.v1_8_0.LogEntry";
- asyncResp->res.jsonValue["@odata.id"] =
- "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
+ else if (propertyMap.first == "UpdateTimestamp")
+ {
+ updateTimestamp =
+ std::get_if<uint64_t>(&propertyMap.second);
+ }
+ else if (propertyMap.first == "Severity")
+ {
+ severity =
+ std::get_if<std::string>(&propertyMap.second);
+ }
+ else if (propertyMap.first == "Message")
+ {
+ message =
+ std::get_if<std::string>(&propertyMap.second);
+ }
+ else if (propertyMap.first == "Resolved")
+ {
+ const bool* resolveptr =
+ std::get_if<bool>(&propertyMap.second);
+ if (resolveptr == nullptr)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ resolved = *resolveptr;
+ }
+ else if (propertyMap.first == "Path")
+ {
+ filePath =
+ std::get_if<std::string>(&propertyMap.second);
+ }
+ }
+ if (id == nullptr || message == nullptr ||
+ severity == nullptr || timestamp == nullptr ||
+ updateTimestamp == nullptr)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#LogEntry.v1_8_0.LogEntry";
+ asyncResp->res.jsonValue["@odata.id"] =
+ "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
+ std::to_string(*id);
+ asyncResp->res.jsonValue["Name"] = "System Event Log Entry";
+ asyncResp->res.jsonValue["Id"] = std::to_string(*id);
+ asyncResp->res.jsonValue["Message"] = *message;
+ asyncResp->res.jsonValue["Resolved"] = resolved;
+ asyncResp->res.jsonValue["EntryType"] = "Event";
+ asyncResp->res.jsonValue["Severity"] =
+ translateSeverityDbusToRedfish(*severity);
+ asyncResp->res.jsonValue["Created"] =
+ crow::utility::getDateTimeUintMs(*timestamp);
+ asyncResp->res.jsonValue["Modified"] =
+ crow::utility::getDateTimeUintMs(*updateTimestamp);
+ if (filePath != nullptr)
+ {
+ asyncResp->res.jsonValue["AdditionalDataURI"] =
+ "/redfish/v1/Systems/system/LogServices/EventLog/attachment/" +
std::to_string(*id);
- asyncResp->res.jsonValue["Name"] =
- "System Event Log Entry";
- asyncResp->res.jsonValue["Id"] = std::to_string(*id);
- asyncResp->res.jsonValue["Message"] = *message;
- asyncResp->res.jsonValue["Resolved"] = resolved;
- asyncResp->res.jsonValue["EntryType"] = "Event";
- asyncResp->res.jsonValue["Severity"] =
- translateSeverityDbusToRedfish(*severity);
- asyncResp->res.jsonValue["Created"] =
- crow::utility::getDateTimeUintMs(*timestamp);
- asyncResp->res.jsonValue["Modified"] =
- crow::utility::getDateTimeUintMs(*updateTimestamp);
- if (filePath != nullptr)
- {
- asyncResp->res.jsonValue["AdditionalDataURI"] =
- "/redfish/v1/Systems/system/LogServices/EventLog/attachment/" +
- std::to_string(*id);
- }
- },
- "xyz.openbmc_project.Logging",
- "/xyz/openbmc_project/logging/entry/" + entryID,
- "org.freedesktop.DBus.Properties", "GetAll", "");
- });
+ }
+ },
+ "xyz.openbmc_project.Logging",
+ "/xyz/openbmc_project/logging/entry/" + entryID,
+ "org.freedesktop.DBus.Properties", "GetAll", "");
+ });
BMCWEB_ROUTE(
app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/")
.privileges(redfish::privileges::patchLogEntry)
.methods(boost::beast::http::verb::patch)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& entryId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& entryId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::optional<bool> resolved;
if (!json_util::readJsonPatch(req, asyncResp->res, "Resolved",
@@ -1651,49 +1681,52 @@
app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/")
.privileges(redfish::privileges::deleteLogEntry)
- .methods(boost::beast::http::verb::delete_)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param)
-
+ .methods(boost::beast::http::verb::
+ delete_)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>&
+ asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
{
- BMCWEB_LOG_DEBUG << "Do delete single event entries.";
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Do delete single event entries.";
- std::string entryID = param;
+ std::string entryID = param;
- dbus::utility::escapePathForDbus(entryID);
+ dbus::utility::escapePathForDbus(entryID);
- // Process response from Logging service.
- auto respHandler = [asyncResp, entryID](
- const boost::system::error_code ec) {
- BMCWEB_LOG_DEBUG
- << "EventLogEntry (DBus) doDelete callback: Done";
- if (ec)
+ // Process response from Logging service.
+ auto respHandler = [asyncResp,
+ entryID](const boost::system::error_code ec) {
+ BMCWEB_LOG_DEBUG
+ << "EventLogEntry (DBus) doDelete callback: Done";
+ if (ec)
+ {
+ if (ec.value() == EBADR)
{
- if (ec.value() == EBADR)
- {
- messages::resourceNotFound(asyncResp->res,
- "LogEntry", entryID);
- return;
- }
- // TODO Handle for specific error code
- BMCWEB_LOG_ERROR
- << "EventLogEntry (DBus) doDelete respHandler got error "
- << ec;
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
+ messages::resourceNotFound(asyncResp->res, "LogEntry",
+ entryID);
return;
}
+ // TODO Handle for specific error code
+ BMCWEB_LOG_ERROR
+ << "EventLogEntry (DBus) doDelete respHandler got error "
+ << ec;
+ asyncResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ return;
+ }
- asyncResp->res.result(boost::beast::http::status::ok);
- };
+ asyncResp->res.result(boost::beast::http::status::ok);
+ };
- // Make call to Logging service to request Delete Log
- crow::connections::systemBus->async_method_call(
- respHandler, "xyz.openbmc_project.Logging",
- "/xyz/openbmc_project/logging/entry/" + entryID,
- "xyz.openbmc_project.Object.Delete", "Delete");
- });
+ // Make call to Logging service to request Delete Log
+ crow::connections::systemBus->async_method_call(
+ respHandler, "xyz.openbmc_project.Logging",
+ "/xyz/openbmc_project/logging/entry/" + entryID,
+ "xyz.openbmc_project.Object.Delete", "Delete");
+ });
}
inline void requestRoutesDBusEventLogEntryDownload(App& app)
@@ -1703,11 +1736,13 @@
"/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/attachment")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param)
-
- {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (!http_helpers::isOctetAccepted(
req.getHeaderValue("Accept")))
{
@@ -1875,10 +1910,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/HostLogger/")
.privileges(redfish::privileges::getLogService)
- .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.id"] =
"/redfish/v1/Systems/system/LogServices/HostLogger";
asyncResp->res.jsonValue["@odata.type"] =
@@ -1897,10 +1936,14 @@
BMCWEB_ROUTE(app,
"/redfish/v1/Systems/system/LogServices/HostLogger/Entries/")
.privileges(redfish::privileges::getLogEntry)
- .methods(
- boost::beast::http::verb::
- get)([](const crow::Request& req,
- 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;
+ }
uint64_t skip = 0;
uint64_t top = maxEntriesPerPage; // Show max 1000 entries by
// default, allow range 1 to
@@ -1975,9 +2018,13 @@
app, "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/<str>/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
const std::string& targetID = param;
uint64_t idInt = 0;
@@ -2034,8 +2081,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/")
.privileges(redfish::privileges::getLogServiceCollection)
.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;
+ }
// Collections don't include the static data added by SubRoute
// because it has a duplicate entry for members
asyncResp->res.jsonValue["@odata.type"] =
@@ -2069,10 +2120,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
.privileges(redfish::privileges::getLogService)
.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"] =
"#LogService.v1_1_0.LogService";
asyncResp->res.jsonValue["@odata.id"] =
@@ -2162,10 +2215,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
.privileges(redfish::privileges::getLogEntryCollection)
- .methods(
- boost::beast::http::verb::
- get)([](const crow::Request& req,
- 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;
+ }
static constexpr const long maxEntriesPerPage = 1000;
uint64_t skip = 0;
uint64_t top = maxEntriesPerPage; // Show max entries by default
@@ -2252,9 +2309,13 @@
"/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& entryID) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& entryID) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
// Convert the unique ID back to a timestamp to find the entry
uint64_t ts = 0;
uint64_t index = 0;
@@ -2320,10 +2381,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
.privileges(redfish::privileges::getLogService)
- .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.id"] =
"/redfish/v1/Managers/bmc/LogServices/Dump";
asyncResp->res.jsonValue["@odata.type"] =
@@ -2361,8 +2426,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
.privileges(redfish::privileges::getLogEntryCollection)
.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"] =
"#LogEntryCollection.LogEntryCollection";
asyncResp->res.jsonValue["@odata.id"] =
@@ -2381,32 +2450,44 @@
"/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
- getDumpEntryById(asyncResp, param, "BMC");
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+
+ getDumpEntryById(app, req, asyncResp, param, "BMC");
});
BMCWEB_ROUTE(app,
"/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/")
.privileges(redfish::privileges::deleteLogEntry)
.methods(boost::beast::http::verb::delete_)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
deleteDumpEntry(asyncResp, param, "bmc");
});
}
inline void requestRoutesBMCDumpCreate(App& app)
{
-
BMCWEB_ROUTE(
app,
"/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
.privileges(redfish::privileges::postLogService)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
- 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;
+ }
createDump(asyncResp, req, "BMC");
});
}
@@ -2418,8 +2499,12 @@
"/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog/")
.privileges(redfish::privileges::postLogService)
.methods(boost::beast::http::verb::post)(
- [](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;
+ }
clearDump(asyncResp, "BMC");
});
}
@@ -2428,39 +2513,40 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/")
.privileges(redfish::privileges::getLogService)
- .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))
{
- asyncResp->res.jsonValue["@odata.id"] =
- "/redfish/v1/Systems/system/LogServices/Dump";
- asyncResp->res.jsonValue["@odata.type"] =
- "#LogService.v1_2_0.LogService";
- asyncResp->res.jsonValue["Name"] = "Dump LogService";
- asyncResp->res.jsonValue["Description"] =
- "System Dump LogService";
- asyncResp->res.jsonValue["Id"] = "Dump";
- asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
+ return;
+ }
+ asyncResp->res.jsonValue["@odata.id"] =
+ "/redfish/v1/Systems/system/LogServices/Dump";
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#LogService.v1_2_0.LogService";
+ asyncResp->res.jsonValue["Name"] = "Dump LogService";
+ asyncResp->res.jsonValue["Description"] = "System Dump LogService";
+ asyncResp->res.jsonValue["Id"] = "Dump";
+ asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
- std::pair<std::string, std::string> redfishDateTimeOffset =
- crow::utility::getDateTimeOffsetNow();
- asyncResp->res.jsonValue["DateTime"] =
- redfishDateTimeOffset.first;
- asyncResp->res.jsonValue["DateTimeLocalOffset"] =
- redfishDateTimeOffset.second;
+ std::pair<std::string, std::string> redfishDateTimeOffset =
+ crow::utility::getDateTimeOffsetNow();
+ asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
+ asyncResp->res.jsonValue["DateTimeLocalOffset"] =
+ redfishDateTimeOffset.second;
- asyncResp->res.jsonValue["Entries"] = {
- {"@odata.id",
- "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
- asyncResp->res.jsonValue["Actions"] = {
- {"#LogService.ClearLog",
- {{"target",
- "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog"}}},
- {"#LogService.CollectDiagnosticData",
- {{"target",
- "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData"}}}};
- });
+ asyncResp->res.jsonValue["Entries"] = {
+ {"@odata.id",
+ "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
+ asyncResp->res.jsonValue["Actions"] = {
+ {"#LogService.ClearLog",
+ {{"target",
+ "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog"}}},
+ {"#LogService.CollectDiagnosticData",
+ {{"target",
+ "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData"}}}};
+ });
}
inline void requestRoutesSystemDumpEntryCollection(App& app)
@@ -2472,8 +2558,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/")
.privileges(redfish::privileges::getLogEntryCollection)
.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"] =
"#LogEntryCollection.LogEntryCollection";
asyncResp->res.jsonValue["@odata.id"] =
@@ -2493,19 +2583,23 @@
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
- getDumpEntryById(asyncResp, param, "System");
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ getDumpEntryById(app, req, asyncResp, param, "System");
});
BMCWEB_ROUTE(app,
"/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/")
.privileges(redfish::privileges::deleteLogEntry)
.methods(boost::beast::http::verb::delete_)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
deleteDumpEntry(asyncResp, param, "system");
});
}
@@ -2517,10 +2611,14 @@
"/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData/")
.privileges(redfish::privileges::postLogService)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
-
- { createDump(asyncResp, req, "System"); });
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+ createDump(asyncResp, req, "System");
+ });
}
inline void requestRoutesSystemDumpClear(App& app)
@@ -2530,10 +2628,16 @@
"/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog/")
.privileges(redfish::privileges::postLogService)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
- { clearDump(asyncResp, "System"); });
+ {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+ clearDump(asyncResp, "System");
+ });
}
inline void requestRoutesCrashdumpService(App& app)
@@ -2547,10 +2651,14 @@
// This is incorrect, should be:
//.privileges(redfish::privileges::getLogService)
.privileges({{"ConfigureManager"}})
- .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;
+ }
// Copy over the static data to include the entries added by
// SubRoute
asyncResp->res.jsonValue["@odata.id"] =
@@ -2591,8 +2699,12 @@
//.privileges(redfish::privileges::postLogService)
.privileges({{"ConfigureComponents"}})
.methods(boost::beast::http::verb::post)(
- [](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;
+ }
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec,
const std::string&) {
@@ -2692,10 +2804,14 @@
// This is incorrect, should be.
//.privileges(redfish::privileges::postLogEntryCollection)
.privileges({{"ConfigureComponents"}})
- .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;
+ }
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec,
const std::vector<std::string>& resp) {
@@ -2754,9 +2870,13 @@
// .privileges(redfish::privileges::getLogEntry)
.privileges({{"ConfigureComponents"}})
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
const std::string& logID = param;
logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
});
@@ -2771,9 +2891,13 @@
"/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& logID, const std::string& fileName) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& logID, const std::string& fileName) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
auto getStoredLogCallback =
[asyncResp, logID, fileName,
url(boost::urls::url(req.urlView))](
@@ -2867,8 +2991,13 @@
.privileges({{"ConfigureComponents"}})
.methods(
boost::beast::http::verb::
- post)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ post)([&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::string diagnosticDataType;
std::string oemDiagnosticDataType;
if (!redfish::json_util::readJsonAction(
@@ -2990,8 +3119,12 @@
"/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog/")
.privileges(redfish::privileges::postLogService)
.methods(boost::beast::http::verb::post)(
- [](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;
+ }
BMCWEB_LOG_DEBUG << "Do delete all entries.";
// Process response from Logging service.
@@ -3029,10 +3162,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/")
.privileges(redfish::privileges::getLogService)
- .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.id",
"/redfish/v1/Systems/system/LogServices/PostCodes"},
@@ -3066,8 +3203,12 @@
//.privileges(redfish::privileges::postLogService)
.privileges({{"ConfigureComponents"}})
.methods(boost::beast::http::verb::post)(
- [](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;
+ }
BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
// Make call to post-code service to request clear all
@@ -3335,8 +3476,12 @@
"/redfish/v1/Systems/system/LogServices/PostCodes/Entries/")
.privileges(redfish::privileges::getLogEntryCollection)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- 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"] =
"#LogEntryCollection.LogEntryCollection";
asyncResp->res.jsonValue["@odata.id"] =
@@ -3408,9 +3553,13 @@
"/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/attachment/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& postCodeID) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& postCodeID) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (!http_helpers::isOctetAccepted(
req.getHeaderValue("Accept")))
{
@@ -3488,9 +3637,13 @@
app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& targetID) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& targetID) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
uint16_t bootIndex = 0;
uint64_t codeIndex = 0;
if (!parsePostCode(targetID, codeIndex, bootIndex))
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 96b0d5d..aa4c694 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -22,6 +22,7 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/date_time.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <utils/fw_utils.hpp>
#include <utils/systemd_utils.hpp>
@@ -112,8 +113,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/")
.privileges(redfish::privileges::postManager)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
- 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;
+ }
BMCWEB_LOG_DEBUG << "Post Manager Reset.";
std::string resetType;
@@ -168,8 +173,12 @@
"/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/")
.privileges(redfish::privileges::postManager)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
- 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;
+ }
BMCWEB_LOG_DEBUG << "Post ResetToDefaults.";
std::string resetType;
@@ -227,8 +236,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/")
.privileges(redfish::privileges::getActionInfo)
.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", "#ActionInfo.v1_1_2.ActionInfo"},
{"@odata.id", "/redfish/v1/Managers/bmc/ResetActionInfo"},
@@ -1948,10 +1961,15 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")
.privileges(redfish::privileges::getManager)
- .methods(boost::beast::http::verb::get)([uuid](const crow::Request&,
- const std::shared_ptr<
- bmcweb::AsyncResp>&
- asyncResp) {
+ .methods(
+ boost::beast::http::verb::
+ get)([&app, uuid](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc";
asyncResp->res.jsonValue["@odata.type"] =
"#Manager.v1_11_0.Manager";
@@ -2197,83 +2215,88 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")
.privileges(redfish::privileges::patchManager)
- .methods(
- boost::beast::http::verb::
- patch)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- std::optional<nlohmann::json> oem;
- std::optional<nlohmann::json> links;
- std::optional<std::string> datetime;
-
- if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem,
- "DateTime", datetime, "Links", links))
- {
- return;
- }
-
- if (oem)
- {
- std::optional<nlohmann::json> openbmc;
- if (!redfish::json_util::readJson(*oem, asyncResp->res,
- "OpenBmc", openbmc))
+ .methods(boost::beast::http::verb::patch)(
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
{
- BMCWEB_LOG_ERROR
- << "Illegal Property "
- << oem->dump(2, ' ', true,
- nlohmann::json::error_handler_t::replace);
return;
}
- if (openbmc)
+ std::optional<nlohmann::json> oem;
+ std::optional<nlohmann::json> links;
+ std::optional<std::string> datetime;
+
+ if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem,
+ "DateTime", datetime, "Links",
+ links))
{
- std::optional<nlohmann::json> fan;
- if (!redfish::json_util::readJson(*openbmc, asyncResp->res,
- "Fan", fan))
+ return;
+ }
+
+ if (oem)
+ {
+ std::optional<nlohmann::json> openbmc;
+ if (!redfish::json_util::readJson(*oem, asyncResp->res,
+ "OpenBmc", openbmc))
{
BMCWEB_LOG_ERROR
<< "Illegal Property "
- << openbmc->dump(
+ << oem->dump(
2, ' ', true,
nlohmann::json::error_handler_t::replace);
return;
}
- if (fan)
+ if (openbmc)
{
- auto pid =
- std::make_shared<SetPIDValues>(asyncResp, *fan);
- pid->run();
+ std::optional<nlohmann::json> fan;
+ if (!redfish::json_util::readJson(
+ *openbmc, asyncResp->res, "Fan", fan))
+ {
+ BMCWEB_LOG_ERROR
+ << "Illegal Property "
+ << openbmc->dump(2, ' ', true,
+ nlohmann::json::
+ error_handler_t::replace);
+ return;
+ }
+ if (fan)
+ {
+ auto pid =
+ std::make_shared<SetPIDValues>(asyncResp, *fan);
+ pid->run();
+ }
}
}
- }
- if (links)
- {
- std::optional<nlohmann::json> activeSoftwareImage;
- if (!redfish::json_util::readJson(*links, asyncResp->res,
- "ActiveSoftwareImage",
- activeSoftwareImage))
+ if (links)
{
- return;
- }
- if (activeSoftwareImage)
- {
- std::optional<std::string> odataId;
- if (!json_util::readJson(*activeSoftwareImage,
- asyncResp->res, "@odata.id",
- odataId))
+ std::optional<nlohmann::json> activeSoftwareImage;
+ if (!redfish::json_util::readJson(*links, asyncResp->res,
+ "ActiveSoftwareImage",
+ activeSoftwareImage))
{
return;
}
-
- if (odataId)
+ if (activeSoftwareImage)
{
- setActiveFirmwareImage(asyncResp, *odataId);
+ std::optional<std::string> odataId;
+ if (!json_util::readJson(*activeSoftwareImage,
+ asyncResp->res, "@odata.id",
+ odataId))
+ {
+ return;
+ }
+
+ if (odataId)
+ {
+ setActiveFirmwareImage(asyncResp, *odataId);
+ }
}
}
- }
- if (datetime)
- {
- setDateTime(asyncResp, std::move(*datetime));
- }
- });
+ if (datetime)
+ {
+ setDateTime(asyncResp, std::move(*datetime));
+ }
+ });
}
inline void requestRoutesManagerCollection(App& app)
@@ -2281,8 +2304,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/")
.privileges(redfish::privileges::getManagerCollection)
.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;
+ }
// Collections don't include the static data added by SubRoute
// because it has a duplicate entry for members
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp
index 6d03514..20bbfb2 100644
--- a/redfish-core/lib/memory.hpp
+++ b/redfish-core/lib/memory.hpp
@@ -19,6 +19,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <utils/collection.hpp>
#include <utils/hex_utils.hpp>
@@ -870,8 +871,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Memory/")
.privileges(redfish::privileges::getMemoryCollection)
.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"] =
"#MemoryCollection.MemoryCollection";
asyncResp->res.jsonValue["Name"] = "Memory Module Collection";
@@ -892,9 +897,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Memory/<str>/")
.privileges(redfish::privileges::getMemory)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& dimmId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& dimmId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue["@odata.type"] =
"#Memory.v1_11_0.Memory";
asyncResp->res.jsonValue["@odata.id"] =
diff --git a/redfish-core/lib/message_registries.hpp b/redfish-core/lib/message_registries.hpp
index c030e5a..fe4c592 100644
--- a/redfish-core/lib/message_registries.hpp
+++ b/redfish-core/lib/message_registries.hpp
@@ -22,15 +22,20 @@
#include "registries/task_event_message_registry.hpp"
#include <app.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
namespace redfish
{
inline void handleMessageRegistryFileCollectionGet(
- const crow::Request& /*req*/,
+ crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
// Collections don't include the static data added by SubRoute
// because it has a duplicate entry for members
@@ -55,15 +60,19 @@
*/
BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
.privileges(redfish::privileges::getMessageRegistryFileCollection)
- .methods(boost::beast::http::verb::get)(
- handleMessageRegistryFileCollectionGet);
+ .methods(boost::beast::http::verb::get)(std::bind_front(
+ handleMessageRegistryFileCollectionGet, std::ref(app)));
}
inline void handleMessageRoutesMessageRegistryFileGet(
- const crow::Request& /*req*/,
+ crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& registry)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
const registries::Header* header = nullptr;
std::string dmtf = "DMTF ";
const char* url = nullptr;
@@ -120,16 +129,20 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
.privileges(redfish::privileges::getMessageRegistryFile)
- .methods(boost::beast::http::verb::get)(
- handleMessageRoutesMessageRegistryFileGet);
+ .methods(boost::beast::http::verb::get)(std::bind_front(
+ handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
}
inline void handleMessageRegistryGet(
- const crow::Request& /*req*/,
+ crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& registry, const std::string& registryMatch)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
const registries::Header* header = nullptr;
std::vector<const registries::MessageEntry*> registryEntries;
if (registry == "Base")
@@ -223,6 +236,7 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
.privileges(redfish::privileges::getMessageRegistryFile)
- .methods(boost::beast::http::verb::get)(handleMessageRegistryGet);
+ .methods(boost::beast::http::verb::get)(
+ std::bind_front(handleMessageRegistryGet, std::ref(app)));
}
} // namespace redfish
diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp
index 2fb8d82..a47f6ef 100644
--- a/redfish-core/lib/metric_report.hpp
+++ b/redfish-core/lib/metric_report.hpp
@@ -5,6 +5,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <sdbusplus/asio/property.hpp>
@@ -65,8 +66,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/MetricReports/")
.privileges(redfish::privileges::getMetricReportCollection)
.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"] =
"#MetricReportCollection.MetricReportCollection";
asyncResp->res.jsonValue["@odata.id"] =
@@ -85,9 +91,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/MetricReports/<str>/")
.privileges(redfish::privileges::getMetricReport)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& id) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& id) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
const std::string reportPath = telemetry::getDbusReportPath(id);
crow::connections::systemBus->async_method_call(
[asyncResp, id,
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp
index e960af7..d61afd9 100644
--- a/redfish-core/lib/metric_report_definition.hpp
+++ b/redfish-core/lib/metric_report_definition.hpp
@@ -7,6 +7,7 @@
#include <app.hpp>
#include <boost/container/flat_map.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <tuple>
@@ -366,8 +367,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/MetricReportDefinitions/")
.privileges(redfish::privileges::getMetricReportDefinitionCollection)
.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"] =
"#MetricReportDefinitionCollection."
"MetricReportDefinitionCollection";
@@ -386,8 +392,14 @@
.privileges(redfish::privileges::postMetricReportDefinitionCollection)
.methods(
boost::beast::http::verb::
- post)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ post)([&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+
telemetry::AddReportArgs args;
if (!telemetry::getUserParameters(asyncResp->res, req, args))
{
@@ -431,9 +443,14 @@
"/redfish/v1/TelemetryService/MetricReportDefinitions/<str>/")
.privileges(redfish::privileges::getMetricReportDefinition)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& id) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& id) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+
crow::connections::systemBus->async_method_call(
[asyncResp,
id](const boost::system::error_code ec,
@@ -464,11 +481,16 @@
"/redfish/v1/TelemetryService/MetricReportDefinitions/<str>/")
.privileges(redfish::privileges::deleteMetricReportDefinitionCollection)
.methods(boost::beast::http::verb::delete_)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& id)
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& id)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+
const std::string reportPath = telemetry::getDbusReportPath(id);
crow::connections::systemBus->async_method_call(
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index aac7f66..7e50b46 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -21,6 +21,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <sdbusplus/asio/property.hpp>
#include <utils/json_utils.hpp>
@@ -400,9 +401,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/NetworkProtocol/")
.privileges(redfish::privileges::patchManagerNetworkProtocol)
.methods(
- boost::beast::http::verb::
- patch)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ boost::beast::http::verb::patch)([&app](const crow::Request& req,
+ const std::shared_ptr<
+ bmcweb::AsyncResp>&
+ asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::optional<std::string> newHostName;
std::optional<nlohmann::json> ntp;
std::optional<nlohmann::json> ipmi;
@@ -484,8 +490,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/NetworkProtocol/")
.privileges(redfish::privileges::getManagerNetworkProtocol)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- 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;
+ }
getNetworkData(asyncResp, req);
});
}
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index ca1eb8f..fdc2af2 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -19,6 +19,7 @@
#include <app.hpp>
#include <boost/system/linux_error.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
namespace redfish
@@ -81,10 +82,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/PCIeDevices/")
.privileges(redfish::privileges::getPCIeDeviceCollection)
.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",
"#PCIeDeviceCollection.PCIeDeviceCollection"},
@@ -140,112 +143,113 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/PCIeDevices/<str>/")
.privileges(redfish::privileges::getPCIeDevice)
- .methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& device)
-
+ .methods(
+ boost::beast::http::verb::
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& device) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
{
- auto getPCIeDeviceCallback =
- [asyncResp, device](const boost::system::error_code ec,
- const dbus::utility::DBusPropertiesMap&
- pcieDevProperties) {
- if (ec)
+ return;
+ }
+ auto getPCIeDeviceCallback =
+ [asyncResp, device](
+ const boost::system::error_code ec,
+ const dbus::utility::DBusPropertiesMap& pcieDevProperties) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG
+ << "failed to get PCIe Device properties ec: "
+ << ec.value() << ": " << ec.message();
+ if (ec.value() ==
+ boost::system::linux_error::bad_request_descriptor)
{
- BMCWEB_LOG_DEBUG
- << "failed to get PCIe Device properties ec: "
- << ec.value() << ": " << ec.message();
- if (ec.value() == boost::system::linux_error::
- bad_request_descriptor)
- {
- messages::resourceNotFound(
- asyncResp->res, "PCIeDevice", device);
- }
- else
+ messages::resourceNotFound(asyncResp->res,
+ "PCIeDevice", device);
+ }
+ else
+ {
+ messages::internalError(asyncResp->res);
+ }
+ return;
+ }
+
+ asyncResp->res.jsonValue = {
+ {"@odata.type", "#PCIeDevice.v1_4_0.PCIeDevice"},
+ {"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" + device},
+ {"Name", "PCIe Device"},
+ {"Id", device}};
+ asyncResp->res.jsonValue["PCIeFunctions"] = {
+ {"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" + device +
+ "/PCIeFunctions"}};
+ for (const auto& property : pcieDevProperties)
+ {
+ const std::string* propertyString =
+ std::get_if<std::string>(&property.second);
+ if (property.first == "Manufacturer")
+ {
+ if (propertyString == nullptr)
{
messages::internalError(asyncResp->res);
+ return;
}
- return;
+ asyncResp->res.jsonValue["Manufacturer"] =
+ *propertyString;
}
-
- asyncResp->res.jsonValue = {
- {"@odata.type", "#PCIeDevice.v1_4_0.PCIeDevice"},
- {"@odata.id",
- "/redfish/v1/Systems/system/PCIeDevices/" +
- device},
- {"Name", "PCIe Device"},
- {"Id", device}};
- asyncResp->res.jsonValue["PCIeFunctions"] = {
- {"@odata.id",
- "/redfish/v1/Systems/system/PCIeDevices/" +
- device + "/PCIeFunctions"}};
- for (const auto& property : pcieDevProperties)
+ if (property.first == "DeviceType")
{
- const std::string* propertyString =
- std::get_if<std::string>(&property.second);
- if (property.first == "Manufacturer")
+ if (propertyString == nullptr)
{
- if (propertyString == nullptr)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["Manufacturer"] =
- *propertyString;
+ messages::internalError(asyncResp->res);
+ return;
}
- if (property.first == "DeviceType")
- {
- if (propertyString == nullptr)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["DeviceType"] =
- *propertyString;
- }
- if (property.first == "DeviceType")
- {
- if (propertyString == nullptr)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["DeviceType"] =
- *propertyString;
- }
- if (property.first == "GenerationInUse")
- {
- if (propertyString == nullptr)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- std::optional<std::string> generationInUse =
- redfishPcieGenerationFromDbus(
- *propertyString);
- if (!generationInUse)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- if (generationInUse->empty())
- {
- // unknown, no need to handle
- return;
- }
- asyncResp->res
- .jsonValue["PCIeInterface"]["PCIeType"] =
- *generationInUse;
- }
+ asyncResp->res.jsonValue["DeviceType"] =
+ *propertyString;
}
- };
- std::string escapedPath = std::string(pciePath) + "/" + device;
- dbus::utility::escapePathForDbus(escapedPath);
- crow::connections::systemBus->async_method_call(
- std::move(getPCIeDeviceCallback), pcieService, escapedPath,
- "org.freedesktop.DBus.Properties", "GetAll",
- pcieDeviceInterface);
- });
+ if (property.first == "DeviceType")
+ {
+ if (propertyString == nullptr)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ asyncResp->res.jsonValue["DeviceType"] =
+ *propertyString;
+ }
+ if (property.first == "GenerationInUse")
+ {
+ if (propertyString == nullptr)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ std::optional<std::string> generationInUse =
+ redfishPcieGenerationFromDbus(*propertyString);
+ if (!generationInUse)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ if (generationInUse->empty())
+ {
+ // unknown, no need to handle
+ return;
+ }
+ asyncResp->res
+ .jsonValue["PCIeInterface"]["PCIeType"] =
+ *generationInUse;
+ }
+ }
+ };
+ std::string escapedPath = std::string(pciePath) + "/" + device;
+ dbus::utility::escapePathForDbus(escapedPath);
+ crow::connections::systemBus->async_method_call(
+ std::move(getPCIeDeviceCallback), pcieService, escapedPath,
+ "org.freedesktop.DBus.Properties", "GetAll",
+ pcieDeviceInterface);
+ });
}
inline void requestRoutesSystemPCIeFunctionCollection(App& app)
@@ -256,84 +260,87 @@
BMCWEB_ROUTE(app,
"/redfish/v1/Systems/system/PCIeDevices/<str>/PCIeFunctions/")
.privileges(redfish::privileges::getPCIeFunctionCollection)
- .methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& device)
-
+ .methods(
+ boost::beast::http::verb::
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& device) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
{
- asyncResp->res.jsonValue = {
- {"@odata.type",
- "#PCIeFunctionCollection.PCIeFunctionCollection"},
- {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices/" +
- device + "/PCIeFunctions"},
- {"Name", "PCIe Function Collection"},
- {"Description",
- "Collection of PCIe Functions for PCIe Device " + device}};
+ return;
+ }
+ asyncResp->res.jsonValue = {
+ {"@odata.type",
+ "#PCIeFunctionCollection.PCIeFunctionCollection"},
+ {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices/" +
+ device + "/PCIeFunctions"},
+ {"Name", "PCIe Function Collection"},
+ {"Description",
+ "Collection of PCIe Functions for PCIe Device " + device}};
- auto getPCIeDeviceCallback =
- [asyncResp, device](const boost::system::error_code ec,
- const dbus::utility::DBusPropertiesMap&
- pcieDevProperties) {
- if (ec)
+ auto getPCIeDeviceCallback =
+ [asyncResp, device](
+ const boost::system::error_code ec,
+ const dbus::utility::DBusPropertiesMap& pcieDevProperties) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG
+ << "failed to get PCIe Device properties ec: "
+ << ec.value() << ": " << ec.message();
+ if (ec.value() ==
+ boost::system::linux_error::bad_request_descriptor)
{
- BMCWEB_LOG_DEBUG
- << "failed to get PCIe Device properties ec: "
- << ec.value() << ": " << ec.message();
- if (ec.value() == boost::system::linux_error::
- bad_request_descriptor)
+ messages::resourceNotFound(asyncResp->res,
+ "PCIeDevice", device);
+ }
+ else
+ {
+ messages::internalError(asyncResp->res);
+ }
+ return;
+ }
+
+ nlohmann::json& pcieFunctionList =
+ asyncResp->res.jsonValue["Members"];
+ pcieFunctionList = nlohmann::json::array();
+ static constexpr const int maxPciFunctionNum = 8;
+ for (int functionNum = 0; functionNum < maxPciFunctionNum;
+ functionNum++)
+ {
+ // Check if this function exists by looking for a
+ // device ID
+ std::string devIDProperty =
+ "Function" + std::to_string(functionNum) +
+ "DeviceId";
+ const std::string* property = nullptr;
+ for (const auto& propEntry : pcieDevProperties)
+ {
+ if (propEntry.first == devIDProperty)
{
- messages::resourceNotFound(
- asyncResp->res, "PCIeDevice", device);
+ property =
+ std::get_if<std::string>(&propEntry.second);
}
- else
- {
- messages::internalError(asyncResp->res);
- }
+ }
+ if (property == nullptr || !property->empty())
+ {
return;
}
-
- nlohmann::json& pcieFunctionList =
- asyncResp->res.jsonValue["Members"];
- pcieFunctionList = nlohmann::json::array();
- static constexpr const int maxPciFunctionNum = 8;
- for (int functionNum = 0;
- functionNum < maxPciFunctionNum; functionNum++)
- {
- // Check if this function exists by looking for a
- // device ID
- std::string devIDProperty =
- "Function" + std::to_string(functionNum) +
- "DeviceId";
- const std::string* property = nullptr;
- for (const auto& propEntry : pcieDevProperties)
- {
- if (propEntry.first == devIDProperty)
- {
- property = std::get_if<std::string>(
- &propEntry.second);
- }
- }
- if (property == nullptr || !property->empty())
- {
- return;
- }
- pcieFunctionList.push_back(
- {{"@odata.id",
- "/redfish/v1/Systems/system/PCIeDevices/" +
- device + "/PCIeFunctions/" +
- std::to_string(functionNum)}});
- }
- asyncResp->res.jsonValue["Members@odata.count"] =
- pcieFunctionList.size();
- };
- std::string escapedPath = std::string(pciePath) + "/" + device;
- dbus::utility::escapePathForDbus(escapedPath);
- crow::connections::systemBus->async_method_call(
- std::move(getPCIeDeviceCallback), pcieService, escapedPath,
- "org.freedesktop.DBus.Properties", "GetAll",
- pcieDeviceInterface);
- });
+ pcieFunctionList.push_back(
+ {{"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" +
+ device + "/PCIeFunctions/" +
+ std::to_string(functionNum)}});
+ }
+ asyncResp->res.jsonValue["Members@odata.count"] =
+ pcieFunctionList.size();
+ };
+ std::string escapedPath = std::string(pciePath) + "/" + device;
+ dbus::utility::escapePathForDbus(escapedPath);
+ crow::connections::systemBus->async_method_call(
+ std::move(getPCIeDeviceCallback), pcieService, escapedPath,
+ "org.freedesktop.DBus.Properties", "GetAll",
+ pcieDeviceInterface);
+ });
}
inline void requestRoutesSystemPCIeFunction(App& app)
@@ -343,11 +350,15 @@
"/redfish/v1/Systems/system/PCIeDevices/<str>/PCIeFunctions/<str>/")
.privileges(redfish::privileges::getPCIeFunction)
.methods(
- boost::beast::http::verb::get)([](const crow::Request&,
- const std::shared_ptr<
- bmcweb::AsyncResp>& asyncResp,
- const std::string& device,
- const std::string& function) {
+ boost::beast::http::verb::
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& device,
+ const std::string& function) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
auto getPCIeDeviceCallback =
[asyncResp, device, function](
const boost::system::error_code ec,
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),
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",
diff --git a/redfish-core/lib/redfish_sessions.hpp b/redfish-core/lib/redfish_sessions.hpp
index 3c2247b..6c55f75 100644
--- a/redfish-core/lib/redfish_sessions.hpp
+++ b/redfish-core/lib/redfish_sessions.hpp
@@ -20,6 +20,7 @@
#include <app.hpp>
#include <http/utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
namespace redfish
@@ -44,10 +45,14 @@
}
inline void
- handleSessionGet(const crow::Request& /*req*/,
+ handleSessionGet(crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& sessionId)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
// Note that control also reaches here via doPost and doDelete.
auto session =
persistent_data::SessionStore::getInstance().getSessionByUid(sessionId);
@@ -62,10 +67,14 @@
}
inline void
- handleSessionDelete(const crow::Request& req,
+ handleSessionDelete(crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& sessionId)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
auto session =
persistent_data::SessionStore::getInstance().getSessionByUid(sessionId);
@@ -111,9 +120,13 @@
}
inline void handleSessionCollectionGet(
- const crow::Request& /*req*/,
+ crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue["Members"] = getSessionCollectionMembers();
asyncResp->res.jsonValue["Members@odata.count"] =
asyncResp->res.jsonValue["Members"].size();
@@ -126,16 +139,24 @@
}
inline void handleSessionCollectionMembersGet(
- const crow::Request& /*req*/,
+ crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
asyncResp->res.jsonValue = getSessionCollectionMembers();
}
void handleSessionCollectionPost(
- const crow::Request& req,
+ crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::string username;
std::string password;
std::optional<nlohmann::json> oemObject;
@@ -206,10 +227,14 @@
fillSessionObject(asyncResp->res, *session);
}
inline void
- handleSessionServiceGet(const crow::Request& /* req */,
+ handleSessionServiceGet(crow::App& 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"] =
"#SessionService.v1_0_2.SessionService";
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/SessionService/";
@@ -225,9 +250,13 @@
}
inline void handleSessionServicePatch(
- const crow::Request& req,
+ crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::optional<int64_t> sessionTimeout;
if (!json_util::readJsonPatch(req, asyncResp->res, "SessionTimeout",
sessionTimeout))
@@ -263,15 +292,18 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/")
.privileges(redfish::privileges::getSession)
- .methods(boost::beast::http::verb::get)(handleSessionGet);
+ .methods(boost::beast::http::verb::get)(
+ std::bind_front(handleSessionGet, std::ref(app)));
BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/")
.privileges(redfish::privileges::deleteSession)
- .methods(boost::beast::http::verb::delete_)(handleSessionDelete);
+ .methods(boost::beast::http::verb::delete_)(
+ std::bind_front(handleSessionDelete, std::ref(app)));
BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/")
.privileges(redfish::privileges::getSessionCollection)
- .methods(boost::beast::http::verb::get)(handleSessionCollectionGet);
+ .methods(boost::beast::http::verb::get)(
+ std::bind_front(handleSessionCollectionGet, std::ref(app)));
// Note, the next two routes technically don't match the privilege
// registry given the way login mechanisms work. The base privilege
@@ -280,19 +312,23 @@
// is itself its own route, it needs to not require Login
BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/")
.privileges({})
- .methods(boost::beast::http::verb::post)(handleSessionCollectionPost);
+ .methods(boost::beast::http::verb::post)(
+ std::bind_front(handleSessionCollectionPost, std::ref(app)));
BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/Members/")
.privileges({})
- .methods(boost::beast::http::verb::post)(handleSessionCollectionPost);
+ .methods(boost::beast::http::verb::post)(
+ std::bind_front(handleSessionCollectionPost, std::ref(app)));
BMCWEB_ROUTE(app, "/redfish/v1/SessionService/")
.privileges(redfish::privileges::getSessionService)
- .methods(boost::beast::http::verb::get)(handleSessionServiceGet);
+ .methods(boost::beast::http::verb::get)(
+ std::bind_front(handleSessionServiceGet, std::ref(app)));
BMCWEB_ROUTE(app, "/redfish/v1/SessionService/")
.privileges(redfish::privileges::patchSessionService)
- .methods(boost::beast::http::verb::patch)(handleSessionServicePatch);
+ .methods(boost::beast::http::verb::patch)(
+ std::bind_front(handleSessionServicePatch, std::ref(app)));
}
} // namespace redfish
diff --git a/redfish-core/lib/roles.hpp b/redfish-core/lib/roles.hpp
index 6c67a33..dd8a790 100644
--- a/redfish-core/lib/roles.hpp
+++ b/redfish-core/lib/roles.hpp
@@ -17,6 +17,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <sdbusplus/asio/property.hpp>
@@ -77,9 +78,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Roles/<str>/")
.privileges(redfish::privileges::getRole)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& roleId) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& roleId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
nlohmann::json privArray = nlohmann::json::array();
if (!getAssignedPrivFromRole(roleId, privArray))
{
@@ -106,8 +111,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Roles/")
.privileges(redfish::privileges::getRoleCollection)
.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.id", "/redfish/v1/AccountService/Roles"},
{"@odata.type", "#RoleCollection.RoleCollection"},
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index d501b70..25ac5e0 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 @@
{
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 @@
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,
diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp
index 6809958..7f1e0de 100644
--- a/redfish-core/lib/storage.hpp
+++ b/redfish-core/lib/storage.hpp
@@ -20,6 +20,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <sdbusplus/asio/property.hpp>
@@ -30,8 +31,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Storage/")
.privileges(redfish::privileges::getStorageCollection)
.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"] =
"#StorageCollection.StorageCollection";
asyncResp->res.jsonValue["@odata.id"] =
@@ -47,10 +52,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Storage/1/")
.privileges(redfish::privileges::getStorage)
- .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"] = "#Storage.v1_7_1.Storage";
asyncResp->res.jsonValue["@odata.id"] =
"/redfish/v1/Systems/system/Storage/1";
@@ -477,10 +486,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Storage/1/Drives/<str>/")
.privileges(redfish::privileges::getDrive)
.methods(
- boost::beast::http::verb::get)([](const crow::Request&,
- const std::shared_ptr<
- bmcweb::AsyncResp>& asyncResp,
- const std::string& driveId) {
+ boost::beast::http::verb::
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& driveId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
crow::connections::systemBus->async_method_call(
[asyncResp, driveId](
const boost::system::error_code ec,
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 83f9dad..b619513 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -2731,8 +2731,13 @@
.privileges(redfish::privileges::postComputerSystem)
.methods(
boost::beast::http::verb::
- post)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ post)([&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::string resetType;
if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
resetType))
@@ -2856,10 +2861,14 @@
*/
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/")
.privileges(redfish::privileges::getComputerSystem)
- .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"] =
"#ComputerSystem.v1_16_0.ComputerSystem";
asyncResp->res.jsonValue["Name"] = "system";
@@ -2979,8 +2988,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/")
.privileges(redfish::privileges::patchComputerSystem)
.methods(boost::beast::http::verb::patch)(
- [](const crow::Request& req,
- 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;
+ }
std::optional<bool> locationIndicatorActive;
std::optional<std::string> indicatorLed;
std::optional<nlohmann::json> bootProps;
@@ -3121,8 +3134,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/ResetActionInfo/")
.privileges(redfish::privileges::getActionInfo)
.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", "#ActionInfo.v1_1_2.ActionInfo"},
{"@odata.id", "/redfish/v1/Systems/system/ResetActionInfo"},
diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp
index 6c0a4b6..199bc84 100644
--- a/redfish-core/lib/task.hpp
+++ b/redfish-core/lib/task.hpp
@@ -19,6 +19,7 @@
#include <boost/asio/post.hpp>
#include <boost/asio/steady_timer.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <task_messages.hpp>
@@ -319,9 +320,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/Monitor/")
.privileges(redfish::privileges::getTask)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& strParam) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& strParam) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
auto find = std::find_if(
task::tasks.begin(), task::tasks.end(),
[&strParam](const std::shared_ptr<task::TaskData>& task) {
@@ -358,9 +363,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/<str>/")
.privileges(redfish::privileges::getTask)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& strParam) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& strParam) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
auto find = std::find_if(
task::tasks.begin(), task::tasks.end(),
[&strParam](const std::shared_ptr<task::TaskData>& task) {
@@ -426,8 +435,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/TaskService/Tasks/")
.privileges(redfish::privileges::getTaskCollection)
.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"] =
"#TaskCollection.TaskCollection";
asyncResp->res.jsonValue["@odata.id"] =
@@ -456,8 +469,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/TaskService/")
.privileges(redfish::privileges::getTaskService)
.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"] =
"#TaskService.v1_1_4.TaskService";
asyncResp->res.jsonValue["@odata.id"] =
diff --git a/redfish-core/lib/telemetry_service.hpp b/redfish-core/lib/telemetry_service.hpp
index e0f6c03..7cdc497 100644
--- a/redfish-core/lib/telemetry_service.hpp
+++ b/redfish-core/lib/telemetry_service.hpp
@@ -4,15 +4,20 @@
#include <app.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
namespace redfish
{
inline void handleTelemetryServiceGet(
- const crow::Request& /*req*/,
+ crow::App& 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"] =
"#TelemetryService.v1_2_1.TelemetryService";
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService";
@@ -78,7 +83,8 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/")
.privileges(redfish::privileges::getTelemetryService)
- .methods(boost::beast::http::verb::get)(handleTelemetryServiceGet);
+ .methods(boost::beast::http::verb::get)(
+ std::bind_front(handleTelemetryServiceGet, std::ref(app)));
}
} // namespace redfish
diff --git a/redfish-core/lib/thermal.hpp b/redfish-core/lib/thermal.hpp
index c49bb0b..847d170 100644
--- a/redfish-core/lib/thermal.hpp
+++ b/redfish-core/lib/thermal.hpp
@@ -18,6 +18,7 @@
#include "sensors.hpp"
#include <app.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
namespace redfish
@@ -28,9 +29,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
.privileges(redfish::privileges::getThermal)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- 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 thermalPaths =
sensors::dbus::paths.find(sensors::node::thermal);
if (thermalPaths == sensors::dbus::paths.end())
@@ -50,9 +56,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
.privileges(redfish::privileges::patchThermal)
.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 thermalPaths =
sensors::dbus::paths.find(sensors::node::thermal);
if (thermalPaths == sensors::dbus::paths.end())
diff --git a/redfish-core/lib/trigger.hpp b/redfish-core/lib/trigger.hpp
index da6a5db..e2f46ec 100644
--- a/redfish-core/lib/trigger.hpp
+++ b/redfish-core/lib/trigger.hpp
@@ -4,6 +4,7 @@
#include "utils/telemetry_utils.hpp"
#include <app.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <tuple>
@@ -282,8 +283,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/")
.privileges(redfish::privileges::getTriggersCollection)
.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"] =
"#TriggersCollection.TriggersCollection";
asyncResp->res.jsonValue["@odata.id"] = telemetry::triggerUri;
@@ -301,9 +306,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/<str>/")
.privileges(redfish::privileges::getTriggers)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& id) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& id) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
crow::connections::systemBus->async_method_call(
[asyncResp,
id](const boost::system::error_code ec,
@@ -338,9 +347,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/<str>/")
.privileges(redfish::privileges::deleteTriggers)
.methods(boost::beast::http::verb::delete_)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& id) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& id) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
const std::string triggerPath =
telemetry::getDbusTriggerPath(id);
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index 729aa56..70fe8db 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -19,6 +19,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <sdbusplus/asio/property.hpp>
#include <utils/fw_utils.hpp>
@@ -416,8 +417,14 @@
.privileges(redfish::privileges::postUpdateService)
.methods(
boost::beast::http::verb::
- post)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ post)([&app](
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+
std::optional<std::string> transferProtocol;
std::string imageURI;
@@ -534,10 +541,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/")
.privileges(redfish::privileges::getUpdateService)
- .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"] =
"#UpdateService.v1_5_0.UpdateService";
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/UpdateService";
@@ -602,9 +613,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/")
.privileges(redfish::privileges::patchUpdateService)
.methods(
- boost::beast::http::verb::
- patch)([](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ boost::beast::http::verb::patch)([&app](const crow::Request& req,
+ const std::shared_ptr<
+ bmcweb::AsyncResp>&
+ asyncResp) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
BMCWEB_LOG_DEBUG << "doPatch...";
std::optional<nlohmann::json> pushUriOptions;
@@ -680,8 +696,12 @@
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/")
.privileges(redfish::privileges::postUpdateService)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
- 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;
+ }
BMCWEB_LOG_DEBUG << "doPost...";
// Setup callback for when new software detected
@@ -705,10 +725,14 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/FirmwareInventory/")
.privileges(redfish::privileges::getSoftwareInventoryCollection)
- .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"] =
"#SoftwareInventoryCollection.SoftwareInventoryCollection";
asyncResp->res.jsonValue["@odata.id"] =
@@ -791,10 +815,14 @@
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/FirmwareInventory/<str>/")
.privileges(redfish::privileges::getSoftwareInventory)
.methods(
- boost::beast::http::verb::get)([](const crow::Request&,
- const std::shared_ptr<
- bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
+ boost::beast::http::verb::
+ get)([&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
std::shared_ptr<std::string> swId =
std::make_shared<std::string>(param);
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 7159be1..e94e233 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -20,6 +20,7 @@
#include <boost/process/async_pipe.hpp>
#include <boost/type_traits/has_dereference.hpp>
#include <boost/url/url_view.hpp>
+#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <utils/json_utils.hpp>
@@ -778,9 +779,13 @@
"/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.InsertMedia")
.privileges(redfish::privileges::postVirtualMedia)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& name, const std::string& resName) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& name, const std::string& resName) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (name != "bmc")
{
messages::resourceNotFound(asyncResp->res,
@@ -913,9 +918,13 @@
"/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.EjectMedia")
.privileges(redfish::privileges::postVirtualMedia)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& name, const std::string& resName) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& name, const std::string& resName) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (name != "bmc")
{
messages::resourceNotFound(asyncResp->res,
@@ -1003,9 +1012,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/")
.privileges(redfish::privileges::getVirtualMediaCollection)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& /* req */,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& name) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& name) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (name != "bmc")
{
messages::resourceNotFound(asyncResp->res, "VirtualMedia",
@@ -1048,9 +1061,13 @@
BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/<str>/")
.privileges(redfish::privileges::getVirtualMedia)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request& /* req */,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& name, const std::string& resName) {
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& name, const std::string& resName) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
if (name != "bmc")
{
messages::resourceNotFound(asyncResp->res, "VirtualMedia",