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 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 29 | entityPrivileges = { |
| 30 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 31 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 32 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 33 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 34 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 35 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
| 36 | } |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 37 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 38 | private: |
| 39 | void doGet(crow::Response& res, const crow::Request& req, |
| 40 | const std::vector<std::string>& params) override |
| 41 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame^] | 42 | res.jsonValue["@odata.id"] = |
| 43 | "/redfish/v1/AccountService/Roles/Administrator"; |
| 44 | res.jsonValue["@odata.type"] = "#Role.v1_0_2.Role"; |
| 45 | res.jsonValue["@odata.context"] = "/redfish/v1/$metadata#Role.Role"; |
| 46 | res.jsonValue["Id"] = "Administrator"; |
| 47 | res.jsonValue["Name"] = "User Role"; |
| 48 | res.jsonValue["Description"] = "Administrator User Role"; |
| 49 | res.jsonValue["IsPredefined"] = true; |
| 50 | res.jsonValue["AssignedPrivileges"] = { |
| 51 | "Login", "ConfigureManager", "ConfigureUsers", "ConfigureSelf", |
| 52 | "ConfigureComponents"}; |
| 53 | res.jsonValue["OemPrivileges"] = nlohmann::json::array(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 54 | res.end(); |
| 55 | } |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 58 | class RoleCollection : public Node |
| 59 | { |
| 60 | public: |
| 61 | RoleCollection(CrowApp& app) : |
| 62 | Node(app, "/redfish/v1/AccountService/Roles/") |
| 63 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 64 | entityPrivileges = { |
| 65 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 66 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 67 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 68 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 69 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 70 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
| 71 | } |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 72 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 73 | private: |
| 74 | void doGet(crow::Response& res, const crow::Request& req, |
| 75 | const std::vector<std::string>& params) override |
| 76 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame^] | 77 | res.jsonValue["@odata.id"] = "/redfish/v1/AccountService/Roles"; |
| 78 | res.jsonValue["@odata.type"] = "#RoleCollection.RoleCollection"; |
| 79 | res.jsonValue["@odata.context"] = |
| 80 | "/redfish/v1/$metadata#RoleCollection.RoleCollection"; |
| 81 | res.jsonValue["Name"] = "Roles Collection"; |
| 82 | res.jsonValue["Description"] = "BMC User Roles"; |
| 83 | res.jsonValue["Members@odata.count"] = 1; |
| 84 | res.jsonValue["Members"] = { |
| 85 | {{"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}}}; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 86 | res.end(); |
| 87 | } |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 90 | } // namespace redfish |