summaryrefslogtreecommitdiff
path: root/redfish-core/lib/bios.hpp
diff options
context:
space:
mode:
authorJohn Edward Broadbent <jebr@google.com>2021-04-09 01:57:16 +0300
committerEd Tanous <ed@tanous.net>2021-06-03 21:18:02 +0300
commit7e860f1550c8686eec42f7a75bc5f2ef51e756ad (patch)
tree989da47a8427bc1a60119f480e2523151b1433aa /redfish-core/lib/bios.hpp
parenteb75770c6c4369984cb150ded4f5ace410ed24a9 (diff)
downloadbmcweb-7e860f1550c8686eec42f7a75bc5f2ef51e756ad.tar.xz
Remove Redfish Node class
Reduces the total number of lines and will allow for easier testing of the redfish responses. A main purpose of the node class was to set app.routeDynamic(). However now app.routeDynamic can handle the complexity that was once in critical to node. The macro app.routeDynamic() provides a shorter cleaner interface to the unerlying app.routeDyanic call. The old pattern set permissions for 6 interfaces (get, head, patch, put, delete_, and post) even if only one interface is created. That pattern creates unneeded code that can be safely removed with no effect. Unit test for the responses would have to mock the node the class in order to fully test responses. see https://github.com/openbmc/bmcweb/issues/181 The following files still need node to be extracted. virtual_media.hpp account_service.hpp redfish_sessions.hpp ethernet.hpp The files above use a pattern that is not trivial to address. Often their responses call an async lambda capturing the inherited class. ie (https://github.com/openbmc/bmcweb/blob/ffed87b5ad1797ca966d030e7f979770 28d258fa/redfish-core/lib/account_service.hpp#L1393) At a later point I plan to remove node from the files above. Tested: I ran the docker unit test with the following command. WORKSPACE=$(pwd) UNIT_TEST_PKG=bmcweb ./openbmc-build-scripts/run-unit-test-docker.sh I ran the validator and this change did not create any issues. python3 RedfishServiceValidator.py -c config.ini Signed-off-by: John Edward Broadbent <jebr@google.com> Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I147a0289c52cb4198345b1ad9bfe6fdddf57f3df
Diffstat (limited to 'redfish-core/lib/bios.hpp')
-rw-r--r--redfish-core/lib/bios.hpp105
1 files changed, 46 insertions, 59 deletions
diff --git a/redfish-core/lib/bios.hpp b/redfish-core/lib/bios.hpp
index 0917cc7f47..de6f9a1f56 100644
--- a/redfish-core/lib/bios.hpp
+++ b/redfish-core/lib/bios.hpp
@@ -1,75 +1,62 @@
#pragma once
-#include "node.hpp"
-
+#include <app.hpp>
#include <utils/fw_utils.hpp>
namespace redfish
{
/**
* BiosService class supports handle get method for bios.
*/
-class BiosService : public Node
+inline void requestRoutesBiosService(App& app)
{
- public:
- BiosService(App& app) : Node(app, "/redfish/v1/Systems/system/Bios/")
- {
- entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}}};
- }
-
- private:
- void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const crow::Request&, const std::vector<std::string>&) override
- {
- 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";
- asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
- asyncResp->res.jsonValue["Id"] = "BIOS";
- asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
- {"target",
- "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/")
+ .privileges({"Login"})
+ .methods(boost::beast::http::verb::get)(
+ [](const crow::Request&,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ 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";
+ asyncResp->res.jsonValue["Description"] =
+ "BIOS Configuration Service";
+ asyncResp->res.jsonValue["Id"] = "BIOS";
+ asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
+ {"target",
+ "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
- // Get the ActiveSoftwareImage and SoftwareImages
- fw_util::populateFirmwareInformation(asyncResp, fw_util::biosPurpose,
- "", true);
- }
-};
+ // Get the ActiveSoftwareImage and SoftwareImages
+ fw_util::populateFirmwareInformation(
+ asyncResp, fw_util::biosPurpose, "", true);
+ });
+}
/**
* BiosReset class supports handle POST method for Reset bios.
* The class retrieves and sends data directly to D-Bus.
+ *
+ * Function handles POST method request.
+ * Analyzes POST body message before sends Reset request data to D-Bus.
*/
-class BiosReset : public Node
-{
- public:
- BiosReset(App& app) :
- Node(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/")
- {
- entityPrivileges = {
- {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
- }
- private:
- /**
- * Function handles POST method request.
- * Analyzes POST body message before sends Reset request data to D-Bus.
- */
- void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const crow::Request&, const std::vector<std::string>&) override
- {
-
- crow::connections::systemBus->async_method_call(
- [asyncResp](const boost::system::error_code ec) {
- if (ec)
- {
- BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
- messages::internalError(asyncResp->res);
- return;
- }
- },
- "org.open_power.Software.Host.Updater",
- "/xyz/openbmc_project/software",
- "xyz.openbmc_project.Common.FactoryReset", "Reset");
- }
-};
+inline void requestRoutesBiosReset(App& app)
+{
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/")
+ .privileges({"ConfigureManager"})
+ .methods(boost::beast::http::verb::post)(
+ [](const crow::Request&,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ crow::connections::systemBus->async_method_call(
+ [asyncResp](const boost::system::error_code ec) {
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ },
+ "org.open_power.Software.Host.Updater",
+ "/xyz/openbmc_project/software",
+ "xyz.openbmc_project.Common.FactoryReset", "Reset");
+ });
+}
} // namespace redfish