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