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 | template <typename CrowApp> |
| 41 | Roles(CrowApp& app) |
| 42 | : Node(app, EntityPrivileges(std::move(roleOpMap)), |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 43 | "/redfish/v1/AccountService/Roles/Administrator/") { |
| 44 | nodeJson["@odata.id"] = "/redfish/v1/AccountService/Roles/Administrator"; |
| 45 | nodeJson["@odata.type"] = "#Role.v1_0_2.Role"; |
| 46 | nodeJson["@odata.context"] = "/redfish/v1/$metadata#Role.Role"; |
| 47 | nodeJson["Id"] = "Administrator"; |
| 48 | nodeJson["Name"] = "User Role"; |
| 49 | nodeJson["Description"] = "Administrator User Role"; |
| 50 | nodeJson["IsPredefined"] = true; |
| 51 | nodeJson["AssignedPrivileges"] = {"Login", "ConfigureManager", |
| 52 | "ConfigureUsers", "ConfigureSelf", |
| 53 | "ConfigureComponents"}; |
| 54 | nodeJson["OemPrivileges"] = nlohmann::json::array(); |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | void doGet(crow::response& res, const crow::request& req, |
| 59 | const std::vector<std::string>& params) override { |
| 60 | res.json_value = nodeJson; |
| 61 | res.end(); |
| 62 | } |
| 63 | |
| 64 | nlohmann::json nodeJson; |
| 65 | }; |
| 66 | |
| 67 | class RoleCollection : public Node { |
| 68 | public: |
Borawski.Lukasz | 43a095a | 2018-02-19 15:39:01 +0100 | [diff] [blame^] | 69 | template <typename CrowApp> |
| 70 | RoleCollection(CrowApp& app) |
| 71 | : Node(app, EntityPrivileges(std::move(roleCollectionOpMap)), |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 72 | "/redfish/v1/AccountService/Roles/") { |
| 73 | nodeJson["@odata.id"] = "/redfish/v1/AccountService/Roles"; |
| 74 | nodeJson["@odata.type"] = "#RoleCollection.RoleCollection"; |
| 75 | nodeJson["@odata.context"] = |
| 76 | "/redfish/v1/$metadata#RoleCollection.RoleCollection"; |
| 77 | nodeJson["Name"] = "Roles Collection"; |
| 78 | nodeJson["Description"] = "BMC User Roles"; |
| 79 | nodeJson["Members@odata.count"] = 1; |
| 80 | nodeJson["Members"] = { |
Lewanczyk, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 81 | {{"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}}}; |
Lewanczyk, Dawid | 4e49bd4 | 2018-01-25 11:30:19 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | private: |
| 85 | void doGet(crow::response& res, const crow::request& req, |
| 86 | const std::vector<std::string>& params) override { |
| 87 | res.json_value = nodeJson; |
| 88 | res.end(); |
| 89 | } |
| 90 | |
| 91 | nlohmann::json nodeJson; |
| 92 | }; |
| 93 | |
| 94 | } // namespace redfish |