blob: e82180722e5345a578573d41a5fded2618a17f21 [file] [log] [blame]
Ed Tanous911ac312017-08-15 09:37:42 -07001#pragma once
2
3#include <dbus_singleton.hpp>
4#include <fstream>
5#include <crow/app.h>
6
7namespace crow {
8namespace intel_oem {
9
10template <typename... Middlewares>
11void request_routes(Crow<Middlewares...>& app) {
12 CROW_ROUTE(app, "/intel/firmwareupload")
13 .methods("POST"_method)([](const crow::request& req) {
14 std::string filepath("/tmp/fw_update_image");
15 std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary |
16 std::ofstream::trunc);
17 out << req.body;
18 out.close();
19
20 auto m = dbus::message::new_call(
21 {"xyz.openbmc_project.fwupdate1.server",
22 "/xyz/openbmc_project/fwupdate1", "xyz.openbmc_project.fwupdate1"},
23 "start");
24
25 m.pack(std::string("file://") + filepath);
26 crow::connections::system_bus->send(m);
27 nlohmann::json j;
28 j["status"] = "Upload Successful";
29 return j;
30 });
31}
32} // namespace redfish
33} // namespace crow