xref: /openbmc/bmcweb/features/redfish/lib/service_root.hpp (revision c1a46bd2bd7c242c5b303ca40165cb19002d63e3)
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   ServiceRoot(CrowApp& app)
33       : Node(app, EntityPrivileges(std::move(serviceRootOpMap)),
34              "/redfish/v1/") {
35     Node::json["@odata.type"] = "#ServiceRoot.v1_1_1.ServiceRoot";
36     Node::json["@odata.id"] = "/redfish/v1/";
37     Node::json["@odata.context"] =
38         "/redfish/v1/$metadata#ServiceRoot.ServiceRoot";
39     Node::json["Id"] = "RootService";
40     Node::json["Name"] = "Root Service";
41     Node::json["RedfishVersion"] = "1.1.0";
42     Node::json["Links"]["Sessions"] = {
43         {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
44     Node::json["UUID"] =
45         app.template get_middleware<crow::PersistentData::Middleware>()
46             .system_uuid;
47   }
48 
49  private:
50   void doGet(crow::response& res, const crow::request& req,
51              const std::vector<std::string>& params) override {
52     res.add_header("Content-Type", "application/json");
53     res.json_value = Node::json;
54     res.end();
55   }
56 };
57 
58 }  // namespace redfish
59