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 | |
Borawski.Lukasz | 43a095a | 2018-02-19 15:39:01 +0100 | [diff] [blame] | 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 | |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 38 | class Roles : public Node { |
| 39 | public: |
Borawski.Lukasz | 43a095a | 2018-02-19 15:39:01 +0100 | [diff] [blame] | 40 | Roles(CrowApp& app) |
| 41 | : Node(app, EntityPrivileges(std::move(roleOpMap)), |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 42 | "/redfish/v1/AccountService/Roles/Administrator/") { |
Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 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(); |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | private: |
| 57 | void doGet(crow::response& res, const crow::request& req, |
| 58 | const std::vector<std::string>& params) override { |
Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 59 | res.json_value = Node::json; |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 60 | res.end(); |
| 61 | } |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | class RoleCollection : public Node { |
| 65 | public: |
Borawski.Lukasz | 43a095a | 2018-02-19 15:39:01 +0100 | [diff] [blame] | 66 | RoleCollection(CrowApp& app) |
| 67 | : Node(app, EntityPrivileges(std::move(roleCollectionOpMap)), |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 68 | "/redfish/v1/AccountService/Roles/") { |
Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 69 | Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles"; |
| 70 | Node::json["@odata.type"] = "#RoleCollection.RoleCollection"; |
| 71 | Node::json["@odata.context"] = |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 72 | "/redfish/v1/$metadata#RoleCollection.RoleCollection"; |
Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 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"}}; |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | private: |
| 81 | void doGet(crow::response& res, const crow::request& req, |
| 82 | const std::vector<std::string>& params) override { |
Borawski.Lukasz | c1a46bd | 2018-02-08 13:31:59 +0100 | [diff] [blame] | 83 | res.json_value = Node::json; |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 84 | res.end(); |
| 85 | } |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | } // namespace redfish |