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 class Roles : public Node { 23 public: 24 Roles(CrowApp& app) 25 : Node(app, "/redfish/v1/AccountService/Roles/Administrator/") { 26 Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles/Administrator"; 27 Node::json["@odata.type"] = "#Role.v1_0_2.Role"; 28 Node::json["@odata.context"] = "/redfish/v1/$metadata#Role.Role"; 29 Node::json["Id"] = "Administrator"; 30 Node::json["Name"] = "User Role"; 31 Node::json["Description"] = "Administrator User Role"; 32 Node::json["IsPredefined"] = true; 33 Node::json["AssignedPrivileges"] = {"Login", "ConfigureManager", 34 "ConfigureUsers", "ConfigureSelf", 35 "ConfigureComponents"}; 36 Node::json["OemPrivileges"] = nlohmann::json::array(); 37 entityPrivileges = {{crow::HTTPMethod::GET, {{"Login"}}}, 38 {crow::HTTPMethod::HEAD, {{"Login"}}}, 39 {crow::HTTPMethod::PATCH, {{"ConfigureManager"}}}, 40 {crow::HTTPMethod::PUT, {{"ConfigureManager"}}}, 41 {crow::HTTPMethod::DELETE, {{"ConfigureManager"}}}, 42 {crow::HTTPMethod::POST, {{"ConfigureManager"}}}}; 43 } 44 45 private: 46 void doGet(crow::response& res, const crow::request& req, 47 const std::vector<std::string>& params) override { 48 res.json_value = Node::json; 49 res.end(); 50 } 51 }; 52 53 class RoleCollection : public Node { 54 public: 55 RoleCollection(CrowApp& app) 56 : Node(app, "/redfish/v1/AccountService/Roles/") { 57 Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles"; 58 Node::json["@odata.type"] = "#RoleCollection.RoleCollection"; 59 Node::json["@odata.context"] = 60 "/redfish/v1/$metadata#RoleCollection.RoleCollection"; 61 Node::json["Name"] = "Roles Collection"; 62 Node::json["Description"] = "BMC User Roles"; 63 Node::json["Members@odata.count"] = 1; 64 Node::json["Members"] = { 65 {{"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}}}; 66 67 entityPrivileges = {{crow::HTTPMethod::GET, {{"Login"}}}, 68 {crow::HTTPMethod::HEAD, {{"Login"}}}, 69 {crow::HTTPMethod::PATCH, {{"ConfigureManager"}}}, 70 {crow::HTTPMethod::PUT, {{"ConfigureManager"}}}, 71 {crow::HTTPMethod::DELETE, {{"ConfigureManager"}}}, 72 {crow::HTTPMethod::POST, {{"ConfigureManager"}}}}; 73 } 74 75 private: 76 void doGet(crow::response& res, const crow::request& req, 77 const std::vector<std::string>& params) override { 78 res.json_value = Node::json; 79 // This is a short term solution to work around a bug. GetSubroutes 80 // accidentally recognizes the Roles/Administrator route as a subroute 81 // (because it's hardcoded to a single entity). Remove this line when that 82 // is resolved 83 res.json_value.erase("Administrator"); 84 res.end(); 85 } 86 }; 87 88 } // namespace redfish 89