xref: /openbmc/bmcweb/features/redfish/lib/service_root.hpp (revision e06259064f6f327b26248a614acffafdafbf1947)
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 
18*e0625906SEd Tanous #include <systemd/sd-id128.h>
19b6df6dc7SBorawski.Lukasz #include "node.hpp"
20b6df6dc7SBorawski.Lukasz 
21b6df6dc7SBorawski.Lukasz namespace redfish {
22b6df6dc7SBorawski.Lukasz 
23b6df6dc7SBorawski.Lukasz class ServiceRoot : public Node {
24b6df6dc7SBorawski.Lukasz  public:
253ebd75f7SEd Tanous   ServiceRoot(CrowApp& app) : Node(app, "/redfish/v1/") {
26c1a46bd2SBorawski.Lukasz     Node::json["@odata.type"] = "#ServiceRoot.v1_1_1.ServiceRoot";
27c1a46bd2SBorawski.Lukasz     Node::json["@odata.id"] = "/redfish/v1/";
28c1a46bd2SBorawski.Lukasz     Node::json["@odata.context"] =
29b6df6dc7SBorawski.Lukasz         "/redfish/v1/$metadata#ServiceRoot.ServiceRoot";
30c1a46bd2SBorawski.Lukasz     Node::json["Id"] = "RootService";
31c1a46bd2SBorawski.Lukasz     Node::json["Name"] = "Root Service";
32c1a46bd2SBorawski.Lukasz     Node::json["RedfishVersion"] = "1.1.0";
33c1a46bd2SBorawski.Lukasz     Node::json["Links"]["Sessions"] = {
34c1a46bd2SBorawski.Lukasz         {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
353ebd75f7SEd Tanous 
36*e0625906SEd Tanous     Node::json["UUID"] = get_uuid();
37*e0625906SEd Tanous 
38*e0625906SEd Tanous     entityPrivileges = {
39*e0625906SEd Tanous         {boost::beast::http::verb::get, {}},
40e0d918bcSEd Tanous         {boost::beast::http::verb::head, {}},
41e0d918bcSEd Tanous         {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
42e0d918bcSEd Tanous         {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
43e0d918bcSEd Tanous         {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
44e0d918bcSEd Tanous         {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
45b6df6dc7SBorawski.Lukasz   }
46b6df6dc7SBorawski.Lukasz 
47b6df6dc7SBorawski.Lukasz  private:
48b6df6dc7SBorawski.Lukasz   void doGet(crow::response& res, const crow::request& req,
49b6df6dc7SBorawski.Lukasz              const std::vector<std::string>& params) override {
50c1a46bd2SBorawski.Lukasz     res.json_value = Node::json;
51b6df6dc7SBorawski.Lukasz     res.end();
52b6df6dc7SBorawski.Lukasz   }
53*e0625906SEd Tanous 
54*e0625906SEd Tanous   const std::string get_uuid() {
55*e0625906SEd Tanous   // If we are using a version of systemd that can get the app specific uuid,
56*e0625906SEd Tanous   // use that
57*e0625906SEd Tanous #ifdef sd_id128_get_machine_app_specific
58*e0625906SEd Tanous     std::array<char, SD_ID128_STRING_MAX> string;
59*e0625906SEd Tanous     sd_id128_t id = SD_ID128_NULL;
60*e0625906SEd Tanous 
61*e0625906SEd Tanous     // This ID needs to match the one in ipmid
62*e0625906SEd Tanous     int r = sd_id128_get_machine_app_specific(
63*e0625906SEd Tanous         SD_ID128_MAKE(e0, e1, 73, 76, 64, 61, 47, da, a5, 0c, d0, cc, 64, 12,
64*e0625906SEd Tanous                       45, 78),
65*e0625906SEd Tanous         &id);
66*e0625906SEd Tanous     if (r < 0) {
67*e0625906SEd Tanous       return "00000000-0000-0000-0000-000000000000";
68*e0625906SEd Tanous     }
69*e0625906SEd Tanous     return string.data();
70*e0625906SEd Tanous #else
71*e0625906SEd Tanous     return "00000000-0000-0000-0000-000000000000";
72*e0625906SEd Tanous #endif
73*e0625906SEd Tanous   }
74b6df6dc7SBorawski.Lukasz };
75b6df6dc7SBorawski.Lukasz 
76b6df6dc7SBorawski.Lukasz }  // namespace redfish
77