xref: /openbmc/bmcweb/features/redfish/lib/service_root.hpp (revision a32d8996ae54fd4efc920269604be45f48f53223)
1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 #pragma once
17 
18 #include "node.hpp"
19 
20 #include <systemd/sd-id128.h>
21 
22 namespace redfish
23 {
24 
25 class ServiceRoot : public Node
26 {
27   public:
28     ServiceRoot(CrowApp& app) : Node(app, "/redfish/v1/")
29     {
30         Node::json["@odata.type"] = "#ServiceRoot.v1_1_1.ServiceRoot";
31         Node::json["@odata.id"] = "/redfish/v1/";
32         Node::json["@odata.context"] =
33             "/redfish/v1/$metadata#ServiceRoot.ServiceRoot";
34         Node::json["Id"] = "RootService";
35         Node::json["Name"] = "Root Service";
36         Node::json["RedfishVersion"] = "1.1.0";
37         Node::json["Links"]["Sessions"] = {
38             {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
39         Node::json["JsonSchemas"] = {{"@odata.id", "/redfish/v1/JsonSchemas"}};
40         Node::json["Registries"] = {{"@odata.id", "/redfish/v1/Registries"}};
41 
42         Node::json["UUID"] = getUuid();
43 
44         entityPrivileges = {
45             {boost::beast::http::verb::get, {}},
46             {boost::beast::http::verb::head, {}},
47             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
48             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
49             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
50             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
51     }
52 
53   private:
54     void doGet(crow::Response& res, const crow::Request& req,
55                const std::vector<std::string>& params) override
56     {
57         res.jsonValue = Node::json;
58         res.end();
59     }
60 
61     const std::string getUuid()
62     {
63         // If we are using a version of systemd that can get the app specific
64         // uuid, use that
65 #ifdef sd_id128_get_machine_app_specific
66         std::array<char, SD_ID128_STRING_MAX> string;
67         sd_id128_t id = SD_ID128_NULL;
68 
69         // This ID needs to match the one in ipmid
70         int r = sd_id128_get_machine_app_specific(
71             SD_ID128_MAKE(e0, e1, 73, 76, 64, 61, 47, da, a5, 0c, d0, cc, 64,
72                           12, 45, 78),
73             &id);
74         if (r < 0)
75         {
76             return "00000000-0000-0000-0000-000000000000";
77         }
78         return string.data();
79 #else
80         return "00000000-0000-0000-0000-000000000000";
81 #endif
82     }
83 };
84 
85 } // namespace redfish
86