blob: f1a1c61b84ce7f25a933b3503f5b49c29f2f03d5 [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 Roles(CrowApp& app)
41 : Node(app, EntityPrivileges(std::move(roleOpMap)),
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010042 "/redfish/v1/AccountService/Roles/Administrator/") {
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010043 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, Dawid4e49bd42018-01-25 11:30:19 +010054 }
55
56 private:
57 void doGet(crow::response& res, const crow::request& req,
58 const std::vector<std::string>& params) override {
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010059 res.json_value = Node::json;
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010060 res.end();
61 }
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010062};
63
64class RoleCollection : public Node {
65 public:
Borawski.Lukasz43a095a2018-02-19 15:39:01 +010066 RoleCollection(CrowApp& app)
67 : Node(app, EntityPrivileges(std::move(roleCollectionOpMap)),
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010068 "/redfish/v1/AccountService/Roles/") {
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010069 Node::json["@odata.id"] = "/redfish/v1/AccountService/Roles";
70 Node::json["@odata.type"] = "#RoleCollection.RoleCollection";
71 Node::json["@odata.context"] =
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010072 "/redfish/v1/$metadata#RoleCollection.RoleCollection";
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010073 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, Dawid4e49bd42018-01-25 11:30:19 +010078 }
79
80 private:
81 void doGet(crow::response& res, const crow::request& req,
82 const std::vector<std::string>& params) override {
Borawski.Lukaszc1a46bd2018-02-08 13:31:59 +010083 res.json_value = Node::json;
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010084 res.end();
85 }
Lewanczyk, Dawid4e49bd42018-01-25 11:30:19 +010086};
87
88} // namespace redfish