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