diff options
author | Ed Tanous <edtanous@google.com> | 2022-05-11 22:21:55 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-05-17 16:41:46 +0300 |
commit | c2051d11f5b28ea7c8ea302c54243d58de1cebc1 (patch) | |
tree | 811767bc0ab5560a3c918e03eb0121db7b174d39 | |
parent | b2c7e20813074bf498fb0030ee800d1424fcf460 (diff) | |
download | bmcweb-c2051d11f5b28ea7c8ea302c54243d58de1cebc1.tar.xz |
Move update service post to free method
Refactor the update service post method in a similar way to how we've
done elsewhere. This is done to enable a refactor later.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Iaa16b5f07fbdbbd1ffc244d5f3e94aa5efa39ad0
-rw-r--r-- | redfish-core/lib/update_service.hpp | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp index b5108ae3e6..716904c2dc 100644 --- a/redfish-core/lib/update_service.hpp +++ b/redfish-core/lib/update_service.hpp @@ -537,6 +537,30 @@ inline void requestRoutesUpdateServiceActionsSimpleUpdate(App& app) }); } +inline void + handleUpdateServicePost(App& 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 + monitorForSoftwareAvailable(asyncResp, req, "/redfish/v1/UpdateService"); + + std::string filepath( + "/tmp/images/" + + boost::uuids::to_string(boost::uuids::random_generator()())); + 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(); + BMCWEB_LOG_DEBUG << "file upload complete!!"; +} + inline void requestRoutesUpdateService(App& app) { BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/") @@ -693,32 +717,11 @@ inline void requestRoutesUpdateService(App& app) } } }); + BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/") .privileges(redfish::privileges::postUpdateService) .methods(boost::beast::http::verb::post)( - [&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 - monitorForSoftwareAvailable(asyncResp, req, - "/redfish/v1/UpdateService"); - - std::string filepath("/tmp/images/" + - boost::uuids::to_string( - boost::uuids::random_generator()())); - 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(); - BMCWEB_LOG_DEBUG << "file upload complete!!"; - }); + std::bind_front(handleUpdateServicePost, std::ref(app))); } inline void requestRoutesSoftwareInventoryCollection(App& app) |