diff options
| author | Ed Tanous <etanous@nvidia.com> | 2024-09-24 00:51:55 +0300 |
|---|---|---|
| committer | Ed Tanous <ed@tanous.net> | 2025-06-27 23:20:39 +0300 |
| commit | 3b28fa2b201513be89807dfb76b47b3ca7ee3f9b (patch) | |
| tree | 2233d014600a7c6b0ff597fc24bd7a28111a289c /include/image_upload.hpp | |
| parent | 8f1a35b9f9046b4c84a5002d0a16b93624a76f22 (diff) | |
| download | bmcweb-3b28fa2b201513be89807dfb76b47b3ca7ee3f9b.tar.xz | |
Rearrange features
The backends are different things compared to generic code. Today,
these are all included in the /include folder, but it's not very clear
what options control which backends, or how things map together. This
also means that we can't separate ownership between the various
companies.
This commit is a proposal to try to create a features folder,
separated by the code for the various backends, to make interacting
with this easier. It takes the form
features/<option name>/files.hpp
features/<option name>/files_test.hpp
Note, redfish-core was already at top level, and contains lots of code,
so to prevent lots of conflicts, it's simply symlinked into that folder
to make clear that it is a backend, but not to move the implementation
and cause code conflicts.
Tested: Unit tests pass. Code compiles.
Change-Id: Idcc80ffcfd99c876734ee41d53f894ca5583fed5
Signed-off-by: Ed Tanous <etanous@nvidia.com>
Diffstat (limited to 'include/image_upload.hpp')
| -rw-r--r-- | include/image_upload.hpp | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/include/image_upload.hpp b/include/image_upload.hpp deleted file mode 100644 index f6a0dfc49e..0000000000 --- a/include/image_upload.hpp +++ /dev/null @@ -1,137 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: Copyright OpenBMC Authors -#pragma once - -#include "app.hpp" -#include "async_resp.hpp" -#include "dbus_singleton.hpp" -#include "dbus_utility.hpp" -#include "http_request.hpp" -#include "io_context_singleton.hpp" -#include "logging.hpp" -#include "ossl_random.hpp" - -#include <boost/asio/error.hpp> -#include <boost/asio/steady_timer.hpp> -#include <boost/beast/http/status.hpp> -#include <boost/beast/http/verb.hpp> -#include <sdbusplus/bus/match.hpp> -#include <sdbusplus/message.hpp> -#include <sdbusplus/message/native_types.hpp> - -#include <algorithm> -#include <chrono> -#include <cstdio> -#include <fstream> -#include <functional> -#include <memory> -#include <ranges> -#include <string> - -namespace crow -{ -namespace image_upload -{ - -// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -static std::unique_ptr<sdbusplus::bus::match_t> fwUpdateMatcher; - -inline void uploadImageHandler( - const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) -{ - // Only allow one FW update at a time - if (fwUpdateMatcher != nullptr) - { - asyncResp->res.addHeader("Retry-After", "30"); - asyncResp->res.result(boost::beast::http::status::service_unavailable); - return; - } - // Make this const static so it survives outside this method - static boost::asio::steady_timer timeout(getIoContext(), - std::chrono::seconds(5)); - - timeout.expires_after(std::chrono::seconds(15)); - - auto timeoutHandler = [asyncResp](const boost::system::error_code& ec) { - fwUpdateMatcher = nullptr; - if (ec == boost::asio::error::operation_aborted) - { - // expected, we were canceled before the timer completed. - return; - } - BMCWEB_LOG_ERROR("Timed out waiting for Version interface"); - - if (ec) - { - BMCWEB_LOG_ERROR("Async_wait failed {}", ec); - return; - } - - asyncResp->res.result(boost::beast::http::status::bad_request); - asyncResp->res.jsonValue["data"]["description"] = - "Version already exists or failed to be extracted"; - asyncResp->res.jsonValue["message"] = "400 Bad Request"; - asyncResp->res.jsonValue["status"] = "error"; - }; - - std::function<void(sdbusplus::message_t&)> callback = - [asyncResp](sdbusplus::message_t& m) { - BMCWEB_LOG_DEBUG("Match fired"); - - sdbusplus::message::object_path path; - dbus::utility::DBusInterfacesMap interfaces; - m.read(path, interfaces); - - if (std::ranges::find_if(interfaces, [](const auto& i) { - return i.first == "xyz.openbmc_project.Software.Version"; - }) != interfaces.end()) - { - timeout.cancel(); - std::string leaf = path.filename(); - if (leaf.empty()) - { - leaf = path.str; - } - - asyncResp->res.jsonValue["data"] = leaf; - asyncResp->res.jsonValue["message"] = "200 OK"; - asyncResp->res.jsonValue["status"] = "ok"; - BMCWEB_LOG_DEBUG("ending response"); - fwUpdateMatcher = nullptr; - } - }; - fwUpdateMatcher = std::make_unique<sdbusplus::bus::match_t>( - *crow::connections::systemBus, - "interface='org.freedesktop.DBus.ObjectManager',type='signal'," - "member='InterfacesAdded',path='/xyz/openbmc_project/software'", - callback); - - std::string filepath("/tmp/images/" + bmcweb::getRandomUUID()); - BMCWEB_LOG_DEBUG("Writing file to {}", filepath); - std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary | - std::ofstream::trunc); - out << req.body(); - out.close(); - timeout.async_wait(timeoutHandler); -} - -inline void requestRoutes(App& app) -{ - BMCWEB_ROUTE(app, "/upload/image/<str>") - .privileges({{"ConfigureComponents", "ConfigureManager"}}) - .methods(boost::beast::http::verb::post, boost::beast::http::verb::put)( - [](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string&) { uploadImageHandler(req, asyncResp); }); - - BMCWEB_ROUTE(app, "/upload/image") - .privileges({{"ConfigureComponents", "ConfigureManager"}}) - .methods(boost::beast::http::verb::post, boost::beast::http::verb::put)( - [](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { - uploadImageHandler(req, asyncResp); - }); -} -} // namespace image_upload -} // namespace crow |
