Refactor callback to free function: Service root
This change will allow for unit testing of the free function.
There are no changes to logic in the service root response.
This is a demo change, if it looks good similar changes can be made to
all the redfish responses.
Also adds missing include (persistent_data.hpp).
Tested: ran curl against qemu machine, looked good.
$ curl -vvvv --insecure "https://192.168.7.2:18080/redfish/v1"
Signed-off-by: John Edward Broadbent <jebr@google.com>
Change-Id: Ie056c64e841a2708d3189a55036385b8c905a7f4
diff --git a/redfish-core/lib/service_root.hpp b/redfish-core/lib/service_root.hpp
index 6778141..63cc210 100644
--- a/redfish-core/lib/service_root.hpp
+++ b/redfish-core/lib/service_root.hpp
@@ -16,55 +16,59 @@
#pragma once
#include <app.hpp>
+#include <persistent_data.hpp>
#include <registries/privilege_registry.hpp>
#include <utils/systemd_utils.hpp>
namespace redfish
{
+inline void
+ handleServiceRootGet(const crow::Request&,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+{
+
+ std::string uuid = persistent_data::getConfig().systemUuid;
+ asyncResp->res.jsonValue["@odata.type"] = "#ServiceRoot.v1_5_0.ServiceRoot";
+ asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
+ asyncResp->res.jsonValue["Id"] = "RootService";
+ asyncResp->res.jsonValue["Name"] = "Root Service";
+ asyncResp->res.jsonValue["RedfishVersion"] = "1.9.0";
+ asyncResp->res.jsonValue["Links"]["Sessions"] = {
+ {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
+ asyncResp->res.jsonValue["AccountService"] = {
+ {"@odata.id", "/redfish/v1/AccountService"}};
+ asyncResp->res.jsonValue["Chassis"] = {
+ {"@odata.id", "/redfish/v1/Chassis"}};
+ asyncResp->res.jsonValue["JsonSchemas"] = {
+ {"@odata.id", "/redfish/v1/JsonSchemas"}};
+ asyncResp->res.jsonValue["Managers"] = {
+ {"@odata.id", "/redfish/v1/Managers"}};
+ asyncResp->res.jsonValue["SessionService"] = {
+ {"@odata.id", "/redfish/v1/SessionService"}};
+ asyncResp->res.jsonValue["Systems"] = {
+ {"@odata.id", "/redfish/v1/Systems"}};
+ asyncResp->res.jsonValue["Registries"] = {
+ {"@odata.id", "/redfish/v1/Registries"}};
+
+ asyncResp->res.jsonValue["UpdateService"] = {
+ {"@odata.id", "/redfish/v1/UpdateService"}};
+ asyncResp->res.jsonValue["UUID"] = uuid;
+ asyncResp->res.jsonValue["CertificateService"] = {
+ {"@odata.id", "/redfish/v1/CertificateService"}};
+ asyncResp->res.jsonValue["Tasks"] = {
+ {"@odata.id", "/redfish/v1/TaskService"}};
+ asyncResp->res.jsonValue["EventService"] = {
+ {"@odata.id", "/redfish/v1/EventService"}};
+ asyncResp->res.jsonValue["TelemetryService"] = {
+ {"@odata.id", "/redfish/v1/TelemetryService"}};
+}
+
inline void requestRoutesServiceRoot(App& app)
{
- std::string uuid = persistent_data::getConfig().systemUuid;
BMCWEB_ROUTE(app, "/redfish/v1/")
.privileges(redfish::privileges::getServiceRoot)
- .methods(boost::beast::http::verb::get)(
- [uuid](const crow::Request&,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- asyncResp->res.jsonValue["@odata.type"] =
- "#ServiceRoot.v1_5_0.ServiceRoot";
- asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
- asyncResp->res.jsonValue["Id"] = "RootService";
- asyncResp->res.jsonValue["Name"] = "Root Service";
- asyncResp->res.jsonValue["RedfishVersion"] = "1.9.0";
- asyncResp->res.jsonValue["Links"]["Sessions"] = {
- {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
- asyncResp->res.jsonValue["AccountService"] = {
- {"@odata.id", "/redfish/v1/AccountService"}};
- asyncResp->res.jsonValue["Chassis"] = {
- {"@odata.id", "/redfish/v1/Chassis"}};
- asyncResp->res.jsonValue["JsonSchemas"] = {
- {"@odata.id", "/redfish/v1/JsonSchemas"}};
- asyncResp->res.jsonValue["Managers"] = {
- {"@odata.id", "/redfish/v1/Managers"}};
- asyncResp->res.jsonValue["SessionService"] = {
- {"@odata.id", "/redfish/v1/SessionService"}};
- asyncResp->res.jsonValue["Systems"] = {
- {"@odata.id", "/redfish/v1/Systems"}};
- asyncResp->res.jsonValue["Registries"] = {
- {"@odata.id", "/redfish/v1/Registries"}};
-
- asyncResp->res.jsonValue["UpdateService"] = {
- {"@odata.id", "/redfish/v1/UpdateService"}};
- asyncResp->res.jsonValue["UUID"] = uuid;
- asyncResp->res.jsonValue["CertificateService"] = {
- {"@odata.id", "/redfish/v1/CertificateService"}};
- asyncResp->res.jsonValue["Tasks"] = {
- {"@odata.id", "/redfish/v1/TaskService"}};
- asyncResp->res.jsonValue["EventService"] = {
- {"@odata.id", "/redfish/v1/EventService"}};
- asyncResp->res.jsonValue["TelemetryService"] = {
- {"@odata.id", "/redfish/v1/TelemetryService"}};
- });
+ .methods(boost::beast::http::verb::get)(handleServiceRootGet);
}
} // namespace redfish