diff options
author | Ed Tanous <edtanous@google.com> | 2021-06-04 03:52:26 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2021-06-09 20:15:51 +0300 |
commit | b282a4380670e5232e7b6f9a08234d3bdbadb5ff (patch) | |
tree | 9663394d6a8846b0000d11b1b5e554aa6997d77b | |
parent | bf648f77793d4e77ad5038c06b44846fd1901b5c (diff) | |
download | bmcweb-b282a4380670e5232e7b6f9a08234d3bdbadb5ff.tar.xz |
Remove the Node class
Fixes #181
Lots of specific details around why the node class have been removed are
in the previous patchsets. This commit actually does the deed and makes
it go away entirely.
Now that this is finally done, we can compare binary size. Surprisingly
enough, this series saves a full 72KB of compressed binary size, which
amounts to about 6.4% of the total code size.
Before: 1197632 bytes
After: 1124688 bytes
This IMO makes it worth it, considering we've significantly reduced the
amount of code at the same time.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I3c8688715f933b381cad0be75a079ccfd72c3130
-rw-r--r-- | redfish-core/include/event_service_manager.hpp | 1 | ||||
-rw-r--r-- | redfish-core/include/node.hpp | 223 | ||||
-rw-r--r-- | redfish-core/include/redfish.hpp | 8 | ||||
-rw-r--r-- | redfish-core/include/server_sent_events.hpp | 1 | ||||
-rw-r--r-- | redfish-core/lib/account_service.hpp | 1 | ||||
-rw-r--r-- | redfish-core/lib/ethernet.hpp | 1 | ||||
-rw-r--r-- | redfish-core/lib/hypervisor_system.hpp | 1 | ||||
-rw-r--r-- | redfish-core/lib/redfish_sessions.hpp | 1 | ||||
-rw-r--r-- | redfish-core/lib/virtual_media.hpp | 1 |
9 files changed, 0 insertions, 238 deletions
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index a1761bb2c1..11190ef100 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -14,7 +14,6 @@ // limitations under the License. */ #pragma once -#include "node.hpp" #include "registries.hpp" #include "registries/base_message_registry.hpp" #include "registries/openbmc_message_registry.hpp" diff --git a/redfish-core/include/node.hpp b/redfish-core/include/node.hpp deleted file mode 100644 index a1b7d72760..0000000000 --- a/redfish-core/include/node.hpp +++ /dev/null @@ -1,223 +0,0 @@ -/* -// Copyright (c) 2018 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -*/ -#pragma once - -#include "async_resp.hpp" -#include "http_request.hpp" -#include "http_response.hpp" -#include "privileges.hpp" -#include "redfish_v1.hpp" - -#include <error_messages.hpp> -#include <rf_async_resp.hpp> - -#include <vector> - -namespace redfish -{ - -/** - * @brief Abstract class used for implementing Redfish nodes. - * - */ -class Node -{ - private: - bool redfishPreChecks(const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) - { - std::string_view odataHeader = req.getHeaderValue("OData-Version"); - if (odataHeader.empty()) - { - // Clients aren't required to provide odata version - return true; - } - if (odataHeader != "4.0") - { - redfish::messages::preconditionFailed(asyncResp->res); - return false; - } - - asyncResp->res.addHeader("OData-Version", "4.0"); - return true; - } - - public: - template <typename... Params> - Node(App& app, std::string&& entityUrl, - [[maybe_unused]] Params... paramsIn) : - app(app) - { - crow::DynamicRule& get = app.routeDynamic(entityUrl.c_str()); - getRule = &get; - get.methods(boost::beast::http::verb::get)( - [this](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - Params... params) { - if (!redfishPreChecks(req, asyncResp)) - { - return; - } - std::vector<std::string> paramVec = {params...}; - doGet(asyncResp, req, paramVec); - }); - - crow::DynamicRule& patch = app.routeDynamic(entityUrl.c_str()); - patchRule = &patch; - patch.methods(boost::beast::http::verb::patch)( - [this](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - Params... params) { - if (!redfishPreChecks(req, asyncResp)) - { - return; - } - std::vector<std::string> paramVec = {params...}; - doPatch(asyncResp, req, paramVec); - }); - - crow::DynamicRule& post = app.routeDynamic(entityUrl.c_str()); - postRule = &post; - post.methods(boost::beast::http::verb::post)( - [this](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - Params... params) { - if (!redfishPreChecks(req, asyncResp)) - { - return; - } - std::vector<std::string> paramVec = {params...}; - doPost(asyncResp, req, paramVec); - }); - - crow::DynamicRule& put = app.routeDynamic(entityUrl.c_str()); - putRule = &put; - put.methods(boost::beast::http::verb::put)( - [this](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - Params... params) { - if (!redfishPreChecks(req, asyncResp)) - { - return; - } - std::vector<std::string> paramVec = {params...}; - doPut(asyncResp, req, paramVec); - }); - - crow::DynamicRule& deleteR = app.routeDynamic(entityUrl.c_str()); - deleteRule = &deleteR; - deleteR.methods(boost::beast::http::verb::delete_)( - [this](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - Params... params) { - if (!redfishPreChecks(req, asyncResp)) - { - return; - } - std::vector<std::string> paramVec = {params...}; - doDelete(asyncResp, req, paramVec); - }); - } - - void initPrivileges() - { - auto it = entityPrivileges.find(boost::beast::http::verb::get); - if (it != entityPrivileges.end()) - { - if (getRule != nullptr) - { - getRule->privileges(it->second); - } - } - it = entityPrivileges.find(boost::beast::http::verb::post); - if (it != entityPrivileges.end()) - { - if (postRule != nullptr) - { - postRule->privileges(it->second); - } - } - it = entityPrivileges.find(boost::beast::http::verb::patch); - if (it != entityPrivileges.end()) - { - if (patchRule != nullptr) - { - patchRule->privileges(it->second); - } - } - it = entityPrivileges.find(boost::beast::http::verb::put); - if (it != entityPrivileges.end()) - { - if (putRule != nullptr) - { - putRule->privileges(it->second); - } - } - it = entityPrivileges.find(boost::beast::http::verb::delete_); - if (it != entityPrivileges.end()) - { - if (deleteRule != nullptr) - { - deleteRule->privileges(it->second); - } - } - } - - virtual ~Node() = default; - - OperationMap entityPrivileges; - - crow::DynamicRule* getRule = nullptr; - crow::DynamicRule* postRule = nullptr; - crow::DynamicRule* patchRule = nullptr; - crow::DynamicRule* putRule = nullptr; - crow::DynamicRule* deleteRule = nullptr; - - protected: - App& app; - // Node is designed to be an abstract class, so doGet is pure virtual - virtual void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const crow::Request&, const std::vector<std::string>&) - { - asyncResp->res.result(boost::beast::http::status::method_not_allowed); - } - - virtual void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const crow::Request&, const std::vector<std::string>&) - { - asyncResp->res.result(boost::beast::http::status::method_not_allowed); - } - - virtual void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const crow::Request&, const std::vector<std::string>&) - { - asyncResp->res.result(boost::beast::http::status::method_not_allowed); - } - - virtual void doPut(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const crow::Request&, const std::vector<std::string>&) - { - asyncResp->res.result(boost::beast::http::status::method_not_allowed); - } - - virtual void doDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const crow::Request&, const std::vector<std::string>&) - { - asyncResp->res.result(boost::beast::http::status::method_not_allowed); - } -}; - -} // namespace redfish diff --git a/redfish-core/include/redfish.hpp b/redfish-core/include/redfish.hpp index 0f43a36c35..47d484864d 100644 --- a/redfish-core/include/redfish.hpp +++ b/redfish-core/include/redfish.hpp @@ -201,15 +201,7 @@ class RedfishService requestRoutesMetricReportDefinition(app); requestRoutesMetricReportCollection(app); requestRoutesMetricReport(app); - - for (const auto& node : nodes) - { - node->initPrivileges(); - } } - - private: - std::vector<std::unique_ptr<Node>> nodes; }; } // namespace redfish diff --git a/redfish-core/include/server_sent_events.hpp b/redfish-core/include/server_sent_events.hpp index 578fa19597..7613d7ba64 100644 --- a/redfish-core/include/server_sent_events.hpp +++ b/redfish-core/include/server_sent_events.hpp @@ -15,7 +15,6 @@ // limitations under the License. */ #pragma once -#include "node.hpp" #include <boost/asio/strand.hpp> #include <boost/beast/core/span.hpp> diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index 582f781868..835fae39d6 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -14,7 +14,6 @@ // limitations under the License. */ #pragma once -#include "node.hpp" #include <app.hpp> #include <dbus_utility.hpp> diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index d78cb58703..5040f9edbb 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -20,7 +20,6 @@ #include <boost/container/flat_set.hpp> #include <dbus_singleton.hpp> #include <error_messages.hpp> -#include <node.hpp> #include <utils/json_utils.hpp> #include <optional> diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp index 0e0629d153..e7850382c9 100644 --- a/redfish-core/lib/hypervisor_system.hpp +++ b/redfish-core/lib/hypervisor_system.hpp @@ -5,7 +5,6 @@ #include <boost/container/flat_set.hpp> #include <dbus_singleton.hpp> #include <error_messages.hpp> -#include <node.hpp> #include <utils/json_utils.hpp> #include <optional> diff --git a/redfish-core/lib/redfish_sessions.hpp b/redfish-core/lib/redfish_sessions.hpp index 75902681a0..53ec7d07c3 100644 --- a/redfish-core/lib/redfish_sessions.hpp +++ b/redfish-core/lib/redfish_sessions.hpp @@ -16,7 +16,6 @@ #pragma once #include "error_messages.hpp" -#include "node.hpp" #include "persistent_data.hpp" #include <app.hpp> diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp index ce40f67b65..cdb6a51072 100644 --- a/redfish-core/lib/virtual_media.hpp +++ b/redfish-core/lib/virtual_media.hpp @@ -19,7 +19,6 @@ #include <boost/container/flat_map.hpp> #include <boost/process/async_pipe.hpp> #include <boost/type_traits/has_dereference.hpp> -#include <node.hpp> #include <utils/json_utils.hpp> // for GetObjectType and ManagedObjectType #include <account_service.hpp> |