xref: /openbmc/bmcweb/redfish-core/lib/roles.hpp (revision aecb47a427e201f685369cb2eb94dc524358ea19)
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 <vector>
19 #include "node.hpp"
20 
21 namespace redfish {
22 
23 class Roles : public Node {
24  public:
25   template <typename CrowApp, typename PrivilegeProvider>
26   Roles(CrowApp& app, PrivilegeProvider& provider)
27       : Node(app, provider, "#Role.v1_0_2.Role",
28              "/redfish/v1/AccountService/Roles/Administrator/") {
29     nodeJson["@odata.id"] = "/redfish/v1/AccountService/Roles/Administrator";
30     nodeJson["@odata.type"] = "#Role.v1_0_2.Role";
31     nodeJson["@odata.context"] = "/redfish/v1/$metadata#Role.Role";
32     nodeJson["Id"] = "Administrator";
33     nodeJson["Name"] = "User Role";
34     nodeJson["Description"] = "Administrator User Role";
35     nodeJson["IsPredefined"] = true;
36     nodeJson["AssignedPrivileges"] = {"Login", "ConfigureManager",
37                                       "ConfigureUsers", "ConfigureSelf",
38                                       "ConfigureComponents"};
39     nodeJson["OemPrivileges"] = nlohmann::json::array();
40   }
41 
42  private:
43   void doGet(crow::response& res, const crow::request& req,
44              const std::vector<std::string>& params) override {
45     res.json_value = nodeJson;
46     res.end();
47   }
48 
49   nlohmann::json nodeJson;
50 };
51 
52 class RoleCollection : public Node {
53  public:
54   template <typename CrowApp, typename PrivilegeProvider>
55   RoleCollection(CrowApp& app, PrivilegeProvider& provider)
56       : Node(app, provider, "#RoleCollection.RoleCollection",
57              "/redfish/v1/AccountService/Roles/") {
58     nodeJson["@odata.id"] = "/redfish/v1/AccountService/Roles";
59     nodeJson["@odata.type"] = "#RoleCollection.RoleCollection";
60     nodeJson["@odata.context"] =
61         "/redfish/v1/$metadata#RoleCollection.RoleCollection";
62     nodeJson["Name"] = "Roles Collection";
63     nodeJson["Description"] = "BMC User Roles";
64     nodeJson["Members@odata.count"] = 1;
65     nodeJson["Members"] = {
66         {"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}};
67   }
68 
69  private:
70   void doGet(crow::response& res, const crow::request& req,
71              const std::vector<std::string>& params) override {
72     res.json_value = nodeJson;
73     res.end();
74   }
75 
76   nlohmann::json nodeJson;
77 };
78 
79 }  // namespace redfish
80