xref: /openbmc/bmcweb/features/redfish/lib/roles.hpp (revision 3ebd75f75e769532bb5bfa53d1acc81655a26ef0)
14e49bd4bSLewanczyk, Dawid /*
24e49bd4bSLewanczyk, Dawid // Copyright (c) 2018 Intel Corporation
34e49bd4bSLewanczyk, Dawid //
44e49bd4bSLewanczyk, Dawid // Licensed under the Apache License, Version 2.0 (the "License");
54e49bd4bSLewanczyk, Dawid // you may not use this file except in compliance with the License.
64e49bd4bSLewanczyk, Dawid // You may obtain a copy of the License at
74e49bd4bSLewanczyk, Dawid //
84e49bd4bSLewanczyk, Dawid //      http://www.apache.org/licenses/LICENSE-2.0
94e49bd4bSLewanczyk, Dawid //
104e49bd4bSLewanczyk, Dawid // Unless required by applicable law or agreed to in writing, software
114e49bd4bSLewanczyk, Dawid // distributed under the License is distributed on an "AS IS" BASIS,
124e49bd4bSLewanczyk, Dawid // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134e49bd4bSLewanczyk, Dawid // See the License for the specific language governing permissions and
144e49bd4bSLewanczyk, Dawid // limitations under the License.
154e49bd4bSLewanczyk, Dawid */
164e49bd4bSLewanczyk, Dawid #pragma once
174e49bd4bSLewanczyk, Dawid 
184e49bd4bSLewanczyk, Dawid #include "node.hpp"
194e49bd4bSLewanczyk, Dawid 
204e49bd4bSLewanczyk, Dawid namespace redfish {
214e49bd4bSLewanczyk, Dawid 
224e49bd4bSLewanczyk, Dawid class Roles : public Node {
234e49bd4bSLewanczyk, Dawid  public:
2443a095abSBorawski.Lukasz   Roles(CrowApp& app)
25*3ebd75f7SEd Tanous       : Node(app, "/redfish/v1/AccountService/Roles/Administrator/") {
26c1a46bd2SBorawski.Lukasz     Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles/Administrator";
27c1a46bd2SBorawski.Lukasz     Node::json["@odata.type"] = "#Role.v1_0_2.Role";
28c1a46bd2SBorawski.Lukasz     Node::json["@odata.context"] = "/redfish/v1/$metadata#Role.Role";
29c1a46bd2SBorawski.Lukasz     Node::json["Id"] = "Administrator";
30c1a46bd2SBorawski.Lukasz     Node::json["Name"] = "User Role";
31c1a46bd2SBorawski.Lukasz     Node::json["Description"] = "Administrator User Role";
32c1a46bd2SBorawski.Lukasz     Node::json["IsPredefined"] = true;
33c1a46bd2SBorawski.Lukasz     Node::json["AssignedPrivileges"] = {"Login", "ConfigureManager",
344e49bd4bSLewanczyk, Dawid                                         "ConfigureUsers", "ConfigureSelf",
354e49bd4bSLewanczyk, Dawid                                         "ConfigureComponents"};
36c1a46bd2SBorawski.Lukasz     Node::json["OemPrivileges"] = nlohmann::json::array();
37*3ebd75f7SEd Tanous     entityPrivileges = {{crow::HTTPMethod::GET, {{"Login"}}},
38*3ebd75f7SEd Tanous                         {crow::HTTPMethod::HEAD, {{"Login"}}},
39*3ebd75f7SEd Tanous                         {crow::HTTPMethod::PATCH, {{"ConfigureManager"}}},
40*3ebd75f7SEd Tanous                         {crow::HTTPMethod::PUT, {{"ConfigureManager"}}},
41*3ebd75f7SEd Tanous                         {crow::HTTPMethod::DELETE, {{"ConfigureManager"}}},
42*3ebd75f7SEd Tanous                         {crow::HTTPMethod::POST, {{"ConfigureManager"}}}};
434e49bd4bSLewanczyk, Dawid   }
444e49bd4bSLewanczyk, Dawid 
454e49bd4bSLewanczyk, Dawid  private:
464e49bd4bSLewanczyk, Dawid   void doGet(crow::response& res, const crow::request& req,
474e49bd4bSLewanczyk, Dawid              const std::vector<std::string>& params) override {
48c1a46bd2SBorawski.Lukasz     res.json_value = Node::json;
494e49bd4bSLewanczyk, Dawid     res.end();
504e49bd4bSLewanczyk, Dawid   }
514e49bd4bSLewanczyk, Dawid };
524e49bd4bSLewanczyk, Dawid 
534e49bd4bSLewanczyk, Dawid class RoleCollection : public Node {
544e49bd4bSLewanczyk, Dawid  public:
5543a095abSBorawski.Lukasz   RoleCollection(CrowApp& app)
56*3ebd75f7SEd Tanous       : Node(app, "/redfish/v1/AccountService/Roles/") {
57c1a46bd2SBorawski.Lukasz     Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles";
58c1a46bd2SBorawski.Lukasz     Node::json["@odata.type"] = "#RoleCollection.RoleCollection";
59c1a46bd2SBorawski.Lukasz     Node::json["@odata.context"] =
604e49bd4bSLewanczyk, Dawid         "/redfish/v1/$metadata#RoleCollection.RoleCollection";
61c1a46bd2SBorawski.Lukasz     Node::json["Name"] = "Roles Collection";
62c1a46bd2SBorawski.Lukasz     Node::json["Description"] = "BMC User Roles";
63c1a46bd2SBorawski.Lukasz     Node::json["Members@odata.count"] = 1;
64c1a46bd2SBorawski.Lukasz     Node::json["Members"] = {
65c1a46bd2SBorawski.Lukasz         {"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}};
66*3ebd75f7SEd Tanous 
67*3ebd75f7SEd Tanous     entityPrivileges = {{crow::HTTPMethod::GET, {{"Login"}}},
68*3ebd75f7SEd Tanous                         {crow::HTTPMethod::HEAD, {{"Login"}}},
69*3ebd75f7SEd Tanous                         {crow::HTTPMethod::PATCH, {{"ConfigureManager"}}},
70*3ebd75f7SEd Tanous                         {crow::HTTPMethod::PUT, {{"ConfigureManager"}}},
71*3ebd75f7SEd Tanous                         {crow::HTTPMethod::DELETE, {{"ConfigureManager"}}},
72*3ebd75f7SEd Tanous                         {crow::HTTPMethod::POST, {{"ConfigureManager"}}}};
734e49bd4bSLewanczyk, Dawid   }
744e49bd4bSLewanczyk, Dawid 
754e49bd4bSLewanczyk, Dawid  private:
764e49bd4bSLewanczyk, Dawid   void doGet(crow::response& res, const crow::request& req,
774e49bd4bSLewanczyk, Dawid              const std::vector<std::string>& params) override {
78c1a46bd2SBorawski.Lukasz     res.json_value = Node::json;
794e49bd4bSLewanczyk, Dawid     res.end();
804e49bd4bSLewanczyk, Dawid   }
814e49bd4bSLewanczyk, Dawid };
824e49bd4bSLewanczyk, Dawid 
834e49bd4bSLewanczyk, Dawid }  // namespace redfish
84