Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 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 | |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 18 | #include "node.hpp" |
| 19 | |
| 20 | namespace redfish { |
| 21 | |
| 22 | class Roles : public Node { |
| 23 | public: |
Borawski.Lukasz | 43a095a | 2018-02-19 15:39:01 +0100 | [diff] [blame] | 24 | Roles(CrowApp& app) |
Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 25 | : Node(app, "/redfish/v1/AccountService/Roles/Administrator/") { |
Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 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(); |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 37 | entityPrivileges = { |
| 38 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 39 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 40 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 41 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 42 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 43 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | private: |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 47 | void doGet(crow::Response& res, const crow::Request& req, |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 48 | const std::vector<std::string>& params) override { |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 49 | res.jsonValue = Node::json; |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 50 | res.end(); |
| 51 | } |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | class RoleCollection : public Node { |
| 55 | public: |
Borawski.Lukasz | 43a095a | 2018-02-19 15:39:01 +0100 | [diff] [blame] | 56 | RoleCollection(CrowApp& app) |
Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 57 | : Node(app, "/redfish/v1/AccountService/Roles/") { |
Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 58 | Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles"; |
| 59 | Node::json["@odata.type"] = "#RoleCollection.RoleCollection"; |
| 60 | Node::json["@odata.context"] = |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 61 | "/redfish/v1/$metadata#RoleCollection.RoleCollection"; |
Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 62 | Node::json["Name"] = "Roles Collection"; |
| 63 | Node::json["Description"] = "BMC User Roles"; |
| 64 | Node::json["Members@odata.count"] = 1; |
| 65 | Node::json["Members"] = { |
Ed Tanous | 6c23301 | 2018-03-15 14:43:56 -0700 | [diff] [blame] | 66 | {{"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}}}; |
Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 67 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 68 | entityPrivileges = { |
| 69 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 70 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 71 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 72 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 73 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 74 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | private: |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 78 | void doGet(crow::Response& res, const crow::Request& req, |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 79 | const std::vector<std::string>& params) override { |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 80 | res.jsonValue = Node::json; |
Ed Tanous | 6c23301 | 2018-03-15 14:43:56 -0700 | [diff] [blame] | 81 | // This is a short term solution to work around a bug. GetSubroutes |
| 82 | // accidentally recognizes the Roles/Administrator route as a subroute |
| 83 | // (because it's hardcoded to a single entity). Remove this line when that |
| 84 | // is resolved |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 85 | res.jsonValue.erase("Administrator"); |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 86 | res.end(); |
| 87 | } |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | } // namespace redfish |