blob: 6a3c0d704e063a8fab95be1383923c9a15c796b3 [file] [log] [blame]
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +01001/*
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, Dawid4e49bd42018-01-25 11:30:19 +010018#include "node.hpp"
19
20namespace redfish {
21
Borawski.Lukasz43a095a2018-02-19 15:39:01 +010022static 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
30static 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, Dawid4e49bd42018-01-25 11:30:19 +010038class Roles : public Node {
39 public:
Borawski.Lukasz43a095a2018-02-19 15:39:01 +010040 template <typename CrowApp>
41 Roles(CrowApp& app)
42 : Node(app, EntityPrivileges(std::move(roleOpMap)),
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010043 "/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
67class RoleCollection : public Node {
68 public:
Borawski.Lukasz43a095a2018-02-19 15:39:01 +010069 template <typename CrowApp>
70 RoleCollection(CrowApp& app)
71 : Node(app, EntityPrivileges(std::move(roleCollectionOpMap)),
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010072 "/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, Dawid88d16c92018-02-02 14:51:09 +010081 {{"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}}};
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010082 }
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