diff options
author | Ed Tanous <ed.tanous@intel.com> | 2017-08-15 19:37:42 +0300 |
---|---|---|
committer | Ed Tanous <ed.tanous@intel.com> | 2017-10-11 23:34:56 +0300 |
commit | 911ac31759cb7b77a856af8806b4e064d50d7422 (patch) | |
tree | c4b714fabb2b956936ab6dffc18d9ff418756cf4 /include/redfish_v1.hpp | |
parent | 8f0c0481d2280919b38a31656ba21a4347d12620 (diff) | |
download | bmcweb-911ac31759cb7b77a856af8806b4e064d50d7422.tar.xz |
Large updates to webserver
Do not merge yet
Change-Id: I38c56844c1b0e3e8e5493c2705e62e6db7ee2102
Diffstat (limited to 'include/redfish_v1.hpp')
-rw-r--r-- | include/redfish_v1.hpp | 93 |
1 files changed, 75 insertions, 18 deletions
diff --git a/include/redfish_v1.hpp b/include/redfish_v1.hpp index c302a68596..73ed84e1e4 100644 --- a/include/redfish_v1.hpp +++ b/include/redfish_v1.hpp @@ -1,9 +1,24 @@ +#pragma once + #include <crow/app.h> + +#include <dbus/connection.hpp> +#include <dbus/endpoint.hpp> +#include <dbus/filter.hpp> +#include <dbus/match.hpp> +#include <dbus/message.hpp> +#include <fstream> + namespace crow { namespace redfish { template <typename... Middlewares> void request_routes(Crow<Middlewares...>& app) { + + // noop for now + return; + + CROW_ROUTE(app, "/redfish/").methods("GET"_method)([]() { return nlohmann::json{{"v1", "/redfish/v1/"}}; }); @@ -28,6 +43,28 @@ void request_routes(Crow<Middlewares...>& app) { }; }); + CROW_ROUTE(app, "/redfish/v1/Chassis").methods("GET"_method)([]() { + std::vector<std::string> entities; + std::ifstream f("~/system.json"); + nlohmann::json input; + input << f; + for (auto it = input.begin(); it != input.end(); it++) { + auto value = it.value(); + if (value["type"] == "Chassis") { + std::string str = value["name"]; + entities.emplace_back(str); + } + } + auto ret = nlohmann::json{ + {"@odata.context", + "/redfish/v1/$metadata#ChassisCollection.ChassisCollection"}, + {"@odata.id", "/redfish/v1/Chassis"}, + {"@odata.type", "#ChassisCollection.ChassisCollection"}, + {"Name", "Chassis Collection"}, + {"Members@odata.count", entities.size()}}; + return ret; + }); + CROW_ROUTE(app, "/redfish/v1/AccountService").methods("GET"_method)([]() { return nlohmann::json{ {"@odata.context", @@ -38,6 +75,7 @@ void request_routes(Crow<Middlewares...>& app) { {"Name", "Account Service"}, {"Description", "BMC User Accounts"}, {"Status", + // TODO(ed) health rollup {{"State", "Enabled"}, {"Health", "OK"}, {"HealthRollup", "OK"}}}, {"ServiceEnabled", true}, {"MinPasswordLength", 1}, @@ -47,22 +85,41 @@ void request_routes(Crow<Middlewares...>& app) { }; }); - CROW_ROUTE(app, "/redfish/v1/AccountService/Accounts/") - .methods("GET"_method)([]() { - return nlohmann::json{ - {"@odata.context", - "/redfish/v1/" - "$metadata#ManagerAccountCollection.ManagerAccountCollection"}, - {"@odata.id", "/redfish/v1/AccountService/Accounts"}, - {"@odata.type", - "#ManagerAccountCollection.ManagerAccountCollection"}, - {"Name", "Accounts Collection"}, - {"Description", "BMC User Accounts"}, - {"Members@odata.count", 3}, - {"Members", - {{{"@odata.id", "/redfish/v1/AccountService/Accounts/1"}}, - {{"@odata.id", "/redfish/v1/AccountService/Accounts/2"}}, - {{"@odata.id", "/redfish/v1/AccountService/Accounts/3"}}}}}; + CROW_ROUTE(app, "/redfish/v1/AccountService/Accounts") + .methods("GET"_method)([](const crow::request& req, crow::response& res) { + boost::asio::io_service io; + auto bus = std::make_shared<dbus::connection>(io, dbus::bus::session); + dbus::endpoint user_list("org.openbmc.UserManager", + "/org/openbmc/UserManager/Users", + "org.openbmc.Enrol", "UserList"); + bus->async_method_call( + [&](const boost::system::error_code ec, + const std::vector<std::string>& users) { + if (ec) { + res.code = 500; + } else { + nlohmann::json return_json{ + {"@odata.context", + "/redfish/v1/" + "$metadata#ManagerAccountCollection." + "ManagerAccountCollection"}, + {"@odata.id", "/redfish/v1/AccountService/Accounts"}, + {"@odata.type", + "#ManagerAccountCollection.ManagerAccountCollection"}, + {"Name", "Accounts Collection"}, + {"Description", "BMC User Accounts"}, + {"Members@odata.count", users.size()}}; + nlohmann::json member_array; + int user_index = 0; + for (auto& user : users) { + member_array.push_back( + {{"@odata.id", "/redfish/v1/AccountService/Accounts/" + + std::to_string(++user_index)}}); + } + return_json["Members"] = member_array; + } + res.end(); + }, user_list); }); CROW_ROUTE(app, "/redfish/v1/AccountService/Accounts/<int>/") @@ -84,5 +141,5 @@ void request_routes(Crow<Middlewares...>& app) { {{"@odata.id", "/redfish/v1/AccountService/Roles/NoAccess"}}}}}}; }); } -} -}
\ No newline at end of file +} // namespace redfish +} // namespace crow |