blob: f538c834f5e614a8bfe584b130f4aed0784c5ce6 [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
22class Roles : public Node {
23 public:
Borawski.Lukasz43a095a2018-02-19 15:39:01 +010024 Roles(CrowApp& app)
Ed Tanous3ebd75f2018-03-05 18:20:01 -080025 : Node(app, "/redfish/v1/AccountService/Roles/Administrator/") {
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010026 Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles/Administrator";
27 Node::json["@odata.type"] = "#Role.v1_0_2.Role";
28 Node::json["@odata.context"] = "/redfish/v1/$metadata#Role.Role";
29 Node::json["Id"] = "Administrator";
30 Node::json["Name"] = "User Role";
31 Node::json["Description"] = "Administrator User Role";
32 Node::json["IsPredefined"] = true;
33 Node::json["AssignedPrivileges"] = {"Login", "ConfigureManager",
34 "ConfigureUsers", "ConfigureSelf",
35 "ConfigureComponents"};
36 Node::json["OemPrivileges"] = nlohmann::json::array();
Ed Tanouse0d918b2018-03-27 17:41:04 -070037 entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}},
38 {boost::beast::http::verb::head, {{"Login"}}},
39 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
40 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
41 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
42 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010043 }
44
45 private:
46 void doGet(crow::response& res, const crow::request& req,
47 const std::vector<std::string>& params) override {
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010048 res.json_value = Node::json;
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010049 res.end();
50 }
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010051};
52
53class RoleCollection : public Node {
54 public:
Borawski.Lukasz43a095a2018-02-19 15:39:01 +010055 RoleCollection(CrowApp& app)
Ed Tanous3ebd75f2018-03-05 18:20:01 -080056 : Node(app, "/redfish/v1/AccountService/Roles/") {
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010057 Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles";
58 Node::json["@odata.type"] = "#RoleCollection.RoleCollection";
59 Node::json["@odata.context"] =
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010060 "/redfish/v1/$metadata#RoleCollection.RoleCollection";
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010061 Node::json["Name"] = "Roles Collection";
62 Node::json["Description"] = "BMC User Roles";
63 Node::json["Members@odata.count"] = 1;
64 Node::json["Members"] = {
Ed Tanous6c233012018-03-15 14:43:56 -070065 {{"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}}};
Ed Tanous3ebd75f2018-03-05 18:20:01 -080066
Ed Tanouse0d918b2018-03-27 17:41:04 -070067 entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}},
68 {boost::beast::http::verb::head, {{"Login"}}},
69 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
70 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
71 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
72 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010073 }
74
75 private:
76 void doGet(crow::response& res, const crow::request& req,
77 const std::vector<std::string>& params) override {
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010078 res.json_value = Node::json;
Ed Tanous6c233012018-03-15 14:43:56 -070079 // This is a short term solution to work around a bug. GetSubroutes
80 // accidentally recognizes the Roles/Administrator route as a subroute
81 // (because it's hardcoded to a single entity). Remove this line when that
82 // is resolved
83 res.json_value.erase("Administrator");
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010084 res.end();
85 }
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010086};
87
88} // namespace redfish