blob: 258eed31b23728dbd3bd742ae46832eafc628d93 [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
Ed Tanous1abe55e2018-09-05 08:30:59 -070020namespace redfish
21{
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010022
Ed Tanous1abe55e2018-09-05 08:30:59 -070023class Roles : public Node
24{
25 public:
26 Roles(CrowApp& app) :
27 Node(app, "/redfish/v1/AccountService/Roles/Administrator/")
28 {
29 Node::json["@odata.id"] =
30 "/redfish/v1/AccountService/Roles/Administrator";
31 Node::json["@odata.type"] = "#Role.v1_0_2.Role";
32 Node::json["@odata.context"] = "/redfish/v1/$metadata#Role.Role";
33 Node::json["Id"] = "Administrator";
34 Node::json["Name"] = "User Role";
35 Node::json["Description"] = "Administrator User Role";
36 Node::json["IsPredefined"] = true;
37 Node::json["AssignedPrivileges"] = {"Login", "ConfigureManager",
38 "ConfigureUsers", "ConfigureSelf",
39 "ConfigureComponents"};
40 Node::json["OemPrivileges"] = nlohmann::json::array();
41 entityPrivileges = {
42 {boost::beast::http::verb::get, {{"Login"}}},
43 {boost::beast::http::verb::head, {{"Login"}}},
44 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
45 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
46 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
47 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
48 }
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010049
Ed Tanous1abe55e2018-09-05 08:30:59 -070050 private:
51 void doGet(crow::Response& res, const crow::Request& req,
52 const std::vector<std::string>& params) override
53 {
54 res.jsonValue = Node::json;
55 res.end();
56 }
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010057};
58
Ed Tanous1abe55e2018-09-05 08:30:59 -070059class RoleCollection : public Node
60{
61 public:
62 RoleCollection(CrowApp& app) :
63 Node(app, "/redfish/v1/AccountService/Roles/")
64 {
65 Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles";
66 Node::json["@odata.type"] = "#RoleCollection.RoleCollection";
67 Node::json["@odata.context"] =
68 "/redfish/v1/$metadata#RoleCollection.RoleCollection";
69 Node::json["Name"] = "Roles Collection";
70 Node::json["Description"] = "BMC User Roles";
71 Node::json["Members@odata.count"] = 1;
72 Node::json["Members"] = {
73 {{"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}}};
Ed Tanous3ebd75f2018-03-05 18:20:01 -080074
Ed Tanous1abe55e2018-09-05 08:30:59 -070075 entityPrivileges = {
76 {boost::beast::http::verb::get, {{"Login"}}},
77 {boost::beast::http::verb::head, {{"Login"}}},
78 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
79 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
80 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
81 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
82 }
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010083
Ed Tanous1abe55e2018-09-05 08:30:59 -070084 private:
85 void doGet(crow::Response& res, const crow::Request& req,
86 const std::vector<std::string>& params) override
87 {
88 res.jsonValue = Node::json;
89 // This is a short term solution to work around a bug. GetSubroutes
90 // accidentally recognizes the Roles/Administrator route as a subroute
91 // (because it's hardcoded to a single entity). Remove this line when
92 // that is resolved
93 res.jsonValue.erase("Administrator");
94 res.end();
95 }
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010096};
97
Ed Tanous1abe55e2018-09-05 08:30:59 -070098} // namespace redfish