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 20*1abe55efSEd Tanous namespace redfish 21*1abe55efSEd Tanous { 224e49bd4bSLewanczyk, Dawid 23*1abe55efSEd Tanous class Roles : public Node 24*1abe55efSEd Tanous { 254e49bd4bSLewanczyk, Dawid public: 26*1abe55efSEd Tanous Roles(CrowApp& app) : 27*1abe55efSEd Tanous Node(app, "/redfish/v1/AccountService/Roles/Administrator/") 28*1abe55efSEd Tanous { 29*1abe55efSEd Tanous Node::json["@odata.id"] = 30*1abe55efSEd Tanous "/redfish/v1/AccountService/Roles/Administrator"; 31c1a46bd2SBorawski.Lukasz Node::json["@odata.type"] = "#Role.v1_0_2.Role"; 32c1a46bd2SBorawski.Lukasz Node::json["@odata.context"] = "/redfish/v1/$metadata#Role.Role"; 33c1a46bd2SBorawski.Lukasz Node::json["Id"] = "Administrator"; 34c1a46bd2SBorawski.Lukasz Node::json["Name"] = "User Role"; 35c1a46bd2SBorawski.Lukasz Node::json["Description"] = "Administrator User Role"; 36c1a46bd2SBorawski.Lukasz Node::json["IsPredefined"] = true; 37c1a46bd2SBorawski.Lukasz Node::json["AssignedPrivileges"] = {"Login", "ConfigureManager", 384e49bd4bSLewanczyk, Dawid "ConfigureUsers", "ConfigureSelf", 394e49bd4bSLewanczyk, Dawid "ConfigureComponents"}; 40c1a46bd2SBorawski.Lukasz Node::json["OemPrivileges"] = nlohmann::json::array(); 4155c7b7a2SEd Tanous entityPrivileges = { 4255c7b7a2SEd Tanous {boost::beast::http::verb::get, {{"Login"}}}, 43e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 44e0d918bcSEd Tanous {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 45e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 46e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 47e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 484e49bd4bSLewanczyk, Dawid } 494e49bd4bSLewanczyk, Dawid 504e49bd4bSLewanczyk, Dawid private: 5155c7b7a2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 52*1abe55efSEd Tanous const std::vector<std::string>& params) override 53*1abe55efSEd Tanous { 5455c7b7a2SEd Tanous res.jsonValue = Node::json; 554e49bd4bSLewanczyk, Dawid res.end(); 564e49bd4bSLewanczyk, Dawid } 574e49bd4bSLewanczyk, Dawid }; 584e49bd4bSLewanczyk, Dawid 59*1abe55efSEd Tanous class RoleCollection : public Node 60*1abe55efSEd Tanous { 614e49bd4bSLewanczyk, Dawid public: 62*1abe55efSEd Tanous RoleCollection(CrowApp& app) : 63*1abe55efSEd Tanous Node(app, "/redfish/v1/AccountService/Roles/") 64*1abe55efSEd Tanous { 65c1a46bd2SBorawski.Lukasz Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles"; 66c1a46bd2SBorawski.Lukasz Node::json["@odata.type"] = "#RoleCollection.RoleCollection"; 67c1a46bd2SBorawski.Lukasz Node::json["@odata.context"] = 684e49bd4bSLewanczyk, Dawid "/redfish/v1/$metadata#RoleCollection.RoleCollection"; 69c1a46bd2SBorawski.Lukasz Node::json["Name"] = "Roles Collection"; 70c1a46bd2SBorawski.Lukasz Node::json["Description"] = "BMC User Roles"; 71c1a46bd2SBorawski.Lukasz Node::json["Members@odata.count"] = 1; 72c1a46bd2SBorawski.Lukasz Node::json["Members"] = { 736c233015SEd Tanous {{"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}}}; 743ebd75f7SEd Tanous 7555c7b7a2SEd Tanous entityPrivileges = { 7655c7b7a2SEd Tanous {boost::beast::http::verb::get, {{"Login"}}}, 77e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 78e0d918bcSEd Tanous {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 79e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 80e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 81e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 824e49bd4bSLewanczyk, Dawid } 834e49bd4bSLewanczyk, Dawid 844e49bd4bSLewanczyk, Dawid private: 8555c7b7a2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 86*1abe55efSEd Tanous const std::vector<std::string>& params) override 87*1abe55efSEd Tanous { 8855c7b7a2SEd Tanous res.jsonValue = Node::json; 896c233015SEd Tanous // This is a short term solution to work around a bug. GetSubroutes 906c233015SEd Tanous // accidentally recognizes the Roles/Administrator route as a subroute 91*1abe55efSEd Tanous // (because it's hardcoded to a single entity). Remove this line when 92*1abe55efSEd Tanous // that is resolved 9355c7b7a2SEd Tanous res.jsonValue.erase("Administrator"); 944e49bd4bSLewanczyk, Dawid res.end(); 954e49bd4bSLewanczyk, Dawid } 964e49bd4bSLewanczyk, Dawid }; 974e49bd4bSLewanczyk, Dawid 984e49bd4bSLewanczyk, Dawid } // namespace redfish 99