xref: /openbmc/bmcweb/features/redfish/lib/service_root.hpp (revision 0f74e643ec246c333ef4724af1ecd5adeb1b6658)
1b6df6dc7SBorawski.Lukasz /*
2b6df6dc7SBorawski.Lukasz // Copyright (c) 2018 Intel Corporation
3b6df6dc7SBorawski.Lukasz //
4b6df6dc7SBorawski.Lukasz // Licensed under the Apache License, Version 2.0 (the "License");
5b6df6dc7SBorawski.Lukasz // you may not use this file except in compliance with the License.
6b6df6dc7SBorawski.Lukasz // You may obtain a copy of the License at
7b6df6dc7SBorawski.Lukasz //
8b6df6dc7SBorawski.Lukasz //      http://www.apache.org/licenses/LICENSE-2.0
9b6df6dc7SBorawski.Lukasz //
10b6df6dc7SBorawski.Lukasz // Unless required by applicable law or agreed to in writing, software
11b6df6dc7SBorawski.Lukasz // distributed under the License is distributed on an "AS IS" BASIS,
12b6df6dc7SBorawski.Lukasz // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b6df6dc7SBorawski.Lukasz // See the License for the specific language governing permissions and
14b6df6dc7SBorawski.Lukasz // limitations under the License.
15b6df6dc7SBorawski.Lukasz */
16b6df6dc7SBorawski.Lukasz #pragma once
17b6df6dc7SBorawski.Lukasz 
18b6df6dc7SBorawski.Lukasz #include "node.hpp"
19b6df6dc7SBorawski.Lukasz 
201abe55efSEd Tanous #include <systemd/sd-id128.h>
21b6df6dc7SBorawski.Lukasz 
221abe55efSEd Tanous namespace redfish
231abe55efSEd Tanous {
241abe55efSEd Tanous 
251abe55efSEd Tanous class ServiceRoot : public Node
261abe55efSEd Tanous {
27b6df6dc7SBorawski.Lukasz   public:
281abe55efSEd Tanous     ServiceRoot(CrowApp& app) : Node(app, "/redfish/v1/")
291abe55efSEd Tanous     {
30e0625906SEd Tanous         entityPrivileges = {
31e0625906SEd Tanous             {boost::beast::http::verb::get, {}},
32e0d918bcSEd Tanous             {boost::beast::http::verb::head, {}},
33e0d918bcSEd Tanous             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
34e0d918bcSEd Tanous             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
35e0d918bcSEd Tanous             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
36e0d918bcSEd Tanous             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
37b6df6dc7SBorawski.Lukasz     }
38b6df6dc7SBorawski.Lukasz 
39b6df6dc7SBorawski.Lukasz   private:
4055c7b7a2SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
411abe55efSEd Tanous                const std::vector<std::string>& params) override
421abe55efSEd Tanous     {
43*0f74e643SEd Tanous         res.jsonValue["@odata.type"] = "#ServiceRoot.v1_1_1.ServiceRoot";
44*0f74e643SEd Tanous         res.jsonValue["@odata.id"] = "/redfish/v1/";
45*0f74e643SEd Tanous         res.jsonValue["@odata.context"] =
46*0f74e643SEd Tanous             "/redfish/v1/$metadata#ServiceRoot.ServiceRoot";
47*0f74e643SEd Tanous         res.jsonValue["Id"] = "RootService";
48*0f74e643SEd Tanous         res.jsonValue["Name"] = "Root Service";
49*0f74e643SEd Tanous         res.jsonValue["RedfishVersion"] = "1.1.0";
50*0f74e643SEd Tanous         res.jsonValue["Links"]["Sessions"] = {
51*0f74e643SEd Tanous             {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
52*0f74e643SEd Tanous         res.jsonValue["AccountService"] = {
53*0f74e643SEd Tanous             {"@odata.id", "/redfish/v1/AccountService"}};
54*0f74e643SEd Tanous         res.jsonValue["Chassis"] = {{"@odata.id", "/redfish/v1/Chassis"}};
55*0f74e643SEd Tanous         res.jsonValue["JsonSchemas"] = {
56*0f74e643SEd Tanous             {"@odata.id", "/redfish/v1/JsonSchemas"}};
57*0f74e643SEd Tanous         res.jsonValue["SessionService"] = {
58*0f74e643SEd Tanous             {"@odata.id", "/redfish/v1/UpdateService"}};
59*0f74e643SEd Tanous         res.jsonValue["Systems"] = {{"@odata.id", "/redfish/v1/Systems"}};
60*0f74e643SEd Tanous         res.jsonValue["Registries"] = {{"@odata.id", "/redfish/v1/Registries"}};
61*0f74e643SEd Tanous 
62*0f74e643SEd Tanous         res.jsonValue["UpdateService"] = {
63*0f74e643SEd Tanous             {"@odata.id", "/redfish/v1/UpdateService"}};
64*0f74e643SEd Tanous 
65*0f74e643SEd Tanous         res.jsonValue["UUID"] = getUuid();
66b6df6dc7SBorawski.Lukasz         res.end();
67b6df6dc7SBorawski.Lukasz     }
68e0625906SEd Tanous 
691abe55efSEd Tanous     const std::string getUuid()
701abe55efSEd Tanous     {
7124436516SEd Tanous         std::string ret;
72e0625906SEd Tanous         // This ID needs to match the one in ipmid
7324436516SEd Tanous         sd_id128_t appId = SD_ID128_MAKE(e0, e1, 73, 76, 64, 61, 47, da, a5, 0c,
7424436516SEd Tanous                                          d0, cc, 64, 12, 45, 78);
7524436516SEd Tanous         sd_id128_t machineId = SD_ID128_NULL;
7624436516SEd Tanous 
7724436516SEd Tanous         if (sd_id128_get_machine_app_specific(appId, &machineId) == 0)
781abe55efSEd Tanous         {
7924436516SEd Tanous             std::array<char, SD_ID128_STRING_MAX> str;
8024436516SEd Tanous             ret = sd_id128_to_string(machineId, str.data());
8124436516SEd Tanous             ret.insert(8, 1, '-');
8224436516SEd Tanous             ret.insert(13, 1, '-');
8324436516SEd Tanous             ret.insert(18, 1, '-');
8424436516SEd Tanous             ret.insert(23, 1, '-');
85e0625906SEd Tanous         }
8624436516SEd Tanous 
8724436516SEd Tanous         return ret;
88e0625906SEd Tanous     }
89b6df6dc7SBorawski.Lukasz };
90b6df6dc7SBorawski.Lukasz 
91b6df6dc7SBorawski.Lukasz } // namespace redfish
92