xref: /openbmc/bmcweb/features/redfish/lib/service_root.hpp (revision a32d8996ae54fd4efc920269604be45f48f53223)
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     {
30c1a46bd2SBorawski.Lukasz         Node::json["@odata.type"] = "#ServiceRoot.v1_1_1.ServiceRoot";
31c1a46bd2SBorawski.Lukasz         Node::json["@odata.id"] = "/redfish/v1/";
32c1a46bd2SBorawski.Lukasz         Node::json["@odata.context"] =
33b6df6dc7SBorawski.Lukasz             "/redfish/v1/$metadata#ServiceRoot.ServiceRoot";
34c1a46bd2SBorawski.Lukasz         Node::json["Id"] = "RootService";
35c1a46bd2SBorawski.Lukasz         Node::json["Name"] = "Root Service";
36c1a46bd2SBorawski.Lukasz         Node::json["RedfishVersion"] = "1.1.0";
37c1a46bd2SBorawski.Lukasz         Node::json["Links"]["Sessions"] = {
38c1a46bd2SBorawski.Lukasz             {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
39683f7276SEd Tanous         Node::json["JsonSchemas"] = {{"@odata.id", "/redfish/v1/JsonSchemas"}};
40*a32d8996SJason M. Bills         Node::json["Registries"] = {{"@odata.id", "/redfish/v1/Registries"}};
413ebd75f7SEd Tanous 
4255c7b7a2SEd Tanous         Node::json["UUID"] = getUuid();
43e0625906SEd Tanous 
44e0625906SEd Tanous         entityPrivileges = {
45e0625906SEd Tanous             {boost::beast::http::verb::get, {}},
46e0d918bcSEd Tanous             {boost::beast::http::verb::head, {}},
47e0d918bcSEd Tanous             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
48e0d918bcSEd Tanous             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
49e0d918bcSEd Tanous             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
50e0d918bcSEd Tanous             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
51b6df6dc7SBorawski.Lukasz     }
52b6df6dc7SBorawski.Lukasz 
53b6df6dc7SBorawski.Lukasz   private:
5455c7b7a2SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
551abe55efSEd Tanous                const std::vector<std::string>& params) override
561abe55efSEd Tanous     {
5755c7b7a2SEd Tanous         res.jsonValue = Node::json;
58b6df6dc7SBorawski.Lukasz         res.end();
59b6df6dc7SBorawski.Lukasz     }
60e0625906SEd Tanous 
611abe55efSEd Tanous     const std::string getUuid()
621abe55efSEd Tanous     {
631abe55efSEd Tanous         // If we are using a version of systemd that can get the app specific
641abe55efSEd Tanous         // uuid, use that
65e0625906SEd Tanous #ifdef sd_id128_get_machine_app_specific
66e0625906SEd Tanous         std::array<char, SD_ID128_STRING_MAX> string;
67e0625906SEd Tanous         sd_id128_t id = SD_ID128_NULL;
68e0625906SEd Tanous 
69e0625906SEd Tanous         // This ID needs to match the one in ipmid
70e0625906SEd Tanous         int r = sd_id128_get_machine_app_specific(
711abe55efSEd Tanous             SD_ID128_MAKE(e0, e1, 73, 76, 64, 61, 47, da, a5, 0c, d0, cc, 64,
721abe55efSEd Tanous                           12, 45, 78),
73e0625906SEd Tanous             &id);
741abe55efSEd Tanous         if (r < 0)
751abe55efSEd Tanous         {
76e0625906SEd Tanous             return "00000000-0000-0000-0000-000000000000";
77e0625906SEd Tanous         }
78e0625906SEd Tanous         return string.data();
79e0625906SEd Tanous #else
80e0625906SEd Tanous         return "00000000-0000-0000-0000-000000000000";
81e0625906SEd Tanous #endif
82e0625906SEd Tanous     }
83b6df6dc7SBorawski.Lukasz };
84b6df6dc7SBorawski.Lukasz 
85b6df6dc7SBorawski.Lukasz } // namespace redfish
86