xref: /openbmc/bmcweb/features/redfish/lib/service_root.hpp (revision 43a095ab36b35bcb9192218fd11e0ff86ec63bf9)
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 namespace redfish {
21 
22 static OperationMap serviceRootOpMap = {
23     {crow::HTTPMethod::GET, {{}}},
24     {crow::HTTPMethod::HEAD, {{}}},
25     {crow::HTTPMethod::PATCH, {{"ConfigureComponents"}}},
26     {crow::HTTPMethod::PUT, {{"ConfigureComponents"}}},
27     {crow::HTTPMethod::DELETE, {{"ConfigureComponents"}}},
28     {crow::HTTPMethod::POST, {{"ConfigureComponents"}}}};
29 
30 class ServiceRoot : public Node {
31  public:
32   template <typename CrowApp>
33   ServiceRoot(CrowApp& app)
34       : Node(app, EntityPrivileges(std::move(serviceRootOpMap)),
35              "/redfish/v1/") {
36     nodeJson["@odata.type"] = "#ServiceRoot.v1_1_1.ServiceRoot";
37     nodeJson["@odata.id"] = "/redfish/v1";
38     nodeJson["@odata.context"] =
39         "/redfish/v1/$metadata#ServiceRoot.ServiceRoot";
40     nodeJson["Id"] = "RootService";
41     nodeJson["Name"] = "Root Service";
42     nodeJson["RedfishVersion"] = "1.1.0";
43     nodeJson["Links"]["Sessions"] = {
44         {"@odata.id", "/redfish/v1/SessionService/Sessions/"}};
45     nodeJson["UUID"] =
46         app.template get_middleware<crow::PersistentData::Middleware>()
47             .system_uuid;
48     getRedfishSubRoutes(app, "/redfish/v1/", nodeJson);
49   }
50 
51  private:
52   void doGet(crow::response& res, const crow::request& req,
53              const std::vector<std::string>& params) override {
54     res.add_header("Content-Type", "application/json");
55     res.body = nodeJson.dump();
56     res.end();
57   }
58 
59   nlohmann::json nodeJson;
60 };
61 
62 }  // namespace redfish
63