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