blob: 97e5f6430a0b9699d823c53d0b4166c274d40e17 [file] [log] [blame]
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +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
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +010017#include "node.hpp"
18
Ed Tanous65b0dc32018-09-19 16:04:03 -070019#include <error_messages.hpp>
Ed Tanousb9b2e0b2018-09-13 13:47:50 -070020#include <openbmc_dbus_rest.hpp>
Ed Tanousa8408792018-09-05 16:08:38 -070021#include <utils/json_utils.hpp>
Ed Tanousb9b2e0b2018-09-13 13:47:50 -070022
Ed Tanous1abe55e2018-09-05 08:30:59 -070023namespace redfish
24{
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +010025
Ed Tanousb9b2e0b2018-09-13 13:47:50 -070026using ManagedObjectType = std::vector<std::pair<
27 sdbusplus::message::object_path,
28 boost::container::flat_map<
AppaRao Puli84e12cb2018-10-11 01:28:15 +053029 std::string,
30 boost::container::flat_map<
31 std::string, sdbusplus::message::variant<bool, std::string>>>>>;
32
33inline std::string getPrivilegeFromRoleId(boost::beast::string_view role)
34{
35 if (role == "priv-admin")
36 {
37 return "Administrator";
38 }
39 else if (role == "priv-callback")
40 {
41 return "Callback";
42 }
43 else if (role == "priv-user")
44 {
45 return "User";
46 }
47 else if (role == "priv-operator")
48 {
49 return "Operator";
50 }
51 return "";
52}
53inline std::string getRoleIdFromPrivilege(boost::beast::string_view role)
54{
55 if (role == "Administrator")
56 {
57 return "priv-admin";
58 }
59 else if (role == "Callback")
60 {
61 return "priv-callback";
62 }
63 else if (role == "User")
64 {
65 return "priv-user";
66 }
67 else if (role == "Operator")
68 {
69 return "priv-operator";
70 }
71 return "";
72}
Ed Tanousb9b2e0b2018-09-13 13:47:50 -070073
Ed Tanous1abe55e2018-09-05 08:30:59 -070074class AccountService : public Node
75{
76 public:
77 AccountService(CrowApp& app) : Node(app, "/redfish/v1/AccountService/")
78 {
Ed Tanous1abe55e2018-09-05 08:30:59 -070079 entityPrivileges = {
80 {boost::beast::http::verb::get,
81 {{"ConfigureUsers"}, {"ConfigureManager"}}},
82 {boost::beast::http::verb::head, {{"Login"}}},
83 {boost::beast::http::verb::patch, {{"ConfigureUsers"}}},
84 {boost::beast::http::verb::put, {{"ConfigureUsers"}}},
85 {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}},
86 {boost::beast::http::verb::post, {{"ConfigureUsers"}}}};
87 }
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +010088
Ed Tanous1abe55e2018-09-05 08:30:59 -070089 private:
90 void doGet(crow::Response& res, const crow::Request& req,
91 const std::vector<std::string>& params) override
92 {
Ed Tanous0f74e642018-11-12 15:17:05 -080093 res.jsonValue["@odata.id"] = "/redfish/v1/AccountService";
94 res.jsonValue["@odata.type"] = "#AccountService.v1_1_0.AccountService";
95 res.jsonValue["@odata.context"] =
96 "/redfish/v1/$metadata#AccountService.AccountService";
97 res.jsonValue["Id"] = "AccountService";
98 res.jsonValue["Description"] = "BMC User Accounts";
99 res.jsonValue["Name"] = "Account Service";
100 res.jsonValue["ServiceEnabled"] = true;
101 res.jsonValue["MinPasswordLength"] = 1;
102 res.jsonValue["MaxPasswordLength"] = 20;
103 res.jsonValue["Accounts"]["@odata.id"] =
104 "/redfish/v1/AccountService/Accounts";
105 res.jsonValue["Roles"]["@odata.id"] =
106 "/redfish/v1/AccountService/Roles";
107
Ed Tanous1abe55e2018-09-05 08:30:59 -0700108 res.end();
109 }
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +0100110};
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700111class AccountsCollection : public Node
112{
113 public:
114 AccountsCollection(CrowApp& app) :
115 Node(app, "/redfish/v1/AccountService/Accounts/")
116 {
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700117 entityPrivileges = {
118 {boost::beast::http::verb::get,
119 {{"ConfigureUsers"}, {"ConfigureManager"}}},
120 {boost::beast::http::verb::head, {{"Login"}}},
121 {boost::beast::http::verb::patch, {{"ConfigureUsers"}}},
122 {boost::beast::http::verb::put, {{"ConfigureUsers"}}},
123 {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}},
124 {boost::beast::http::verb::post, {{"ConfigureUsers"}}}};
125 }
126
127 private:
128 void doGet(crow::Response& res, const crow::Request& req,
129 const std::vector<std::string>& params) override
130 {
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700131 auto asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous0f74e642018-11-12 15:17:05 -0800132 res.jsonValue = {{"@odata.context",
133 "/redfish/v1/"
134 "$metadata#ManagerAccountCollection."
135 "ManagerAccountCollection"},
136 {"@odata.id", "/redfish/v1/AccountService/Accounts"},
137 {"@odata.type", "#ManagerAccountCollection."
138 "ManagerAccountCollection"},
139 {"Name", "Accounts Collection"},
140 {"Description", "BMC User Accounts"}};
141
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700142 crow::connections::systemBus->async_method_call(
143 [asyncResp](const boost::system::error_code ec,
144 const ManagedObjectType& users) {
145 if (ec)
146 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700147 messages::internalError(asyncResp->res);
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700148 return;
149 }
150
151 nlohmann::json& memberArray =
152 asyncResp->res.jsonValue["Members"];
153 memberArray = nlohmann::json::array();
154
155 asyncResp->res.jsonValue["Members@odata.count"] = users.size();
156 for (auto& user : users)
157 {
158 const std::string& path =
159 static_cast<const std::string&>(user.first);
160 std::size_t lastIndex = path.rfind("/");
161 if (lastIndex == std::string::npos)
162 {
163 lastIndex = 0;
164 }
165 else
166 {
167 lastIndex += 1;
168 }
169 memberArray.push_back(
170 {{"@odata.id", "/redfish/v1/AccountService/Accounts/" +
171 path.substr(lastIndex)}});
172 }
173 },
174 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
175 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
176 }
Ed Tanous04ae99e2018-09-20 15:54:36 -0700177 void doPost(crow::Response& res, const crow::Request& req,
178 const std::vector<std::string>& params) override
179 {
180 auto asyncResp = std::make_shared<AsyncResp>(res);
181
Ed Tanous9712f8a2018-09-21 13:38:49 -0700182 std::string username;
183 std::string password;
184 boost::optional<std::string> roleId("User");
185 boost::optional<bool> enabled = true;
186 if (!json_util::readJson(req, res, "UserName", username, "Password",
187 password, "RoleId", roleId, "Enabled",
188 enabled))
Ed Tanous04ae99e2018-09-20 15:54:36 -0700189 {
190 return;
191 }
192
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530193 std::string priv = getRoleIdFromPrivilege(*roleId);
194 if (priv.empty())
Ed Tanous04ae99e2018-09-20 15:54:36 -0700195 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700196 messages::propertyValueNotInList(asyncResp->res, *roleId, "RoleId");
Ed Tanous04ae99e2018-09-20 15:54:36 -0700197 return;
198 }
Ed Tanous9712f8a2018-09-21 13:38:49 -0700199 roleId = priv;
Ed Tanous04ae99e2018-09-20 15:54:36 -0700200
201 crow::connections::systemBus->async_method_call(
Ed Tanous9712f8a2018-09-21 13:38:49 -0700202 [asyncResp, username, password{std::move(password)}](
Ed Tanous04ae99e2018-09-20 15:54:36 -0700203 const boost::system::error_code ec) {
204 if (ec)
205 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700206 messages::resourceAlreadyExists(
207 asyncResp->res, "#ManagerAccount.v1_0_3.ManagerAccount",
208 "UserName", username);
Ed Tanous04ae99e2018-09-20 15:54:36 -0700209 return;
210 }
211
212 if (!pamUpdatePassword(username, password))
213 {
214 // At this point we have a user that's been created, but the
215 // password set failed. Something is wrong, so delete the
216 // user that we've already created
217 crow::connections::systemBus->async_method_call(
218 [asyncResp](const boost::system::error_code ec) {
219 if (ec)
220 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700221 messages::internalError(asyncResp->res);
Ed Tanous04ae99e2018-09-20 15:54:36 -0700222 return;
223 }
224
Jason M. Billsf12894f2018-10-09 12:45:45 -0700225 messages::invalidObject(asyncResp->res, "Password");
Ed Tanous04ae99e2018-09-20 15:54:36 -0700226 },
227 "xyz.openbmc_project.User.Manager",
228 "/xyz/openbmc_project/user/" + username,
229 "xyz.openbmc_project.Object.Delete", "Delete");
230
231 BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
232 return;
233 }
234
Jason M. Billsf12894f2018-10-09 12:45:45 -0700235 messages::created(asyncResp->res);
Ed Tanous04ae99e2018-09-20 15:54:36 -0700236 asyncResp->res.addHeader(
237 "Location",
238 "/redfish/v1/AccountService/Accounts/" + username);
239 },
240 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
Ed Tanous9712f8a2018-09-21 13:38:49 -0700241 "xyz.openbmc_project.User.Manager", "CreateUser", username,
Ed Tanous04ae99e2018-09-20 15:54:36 -0700242 std::array<const char*, 4>{"ipmi", "redfish", "ssh", "web"},
Ed Tanous9712f8a2018-09-21 13:38:49 -0700243 *roleId, *enabled);
Ed Tanous04ae99e2018-09-20 15:54:36 -0700244 }
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700245};
246
Ed Tanousa8408792018-09-05 16:08:38 -0700247template <typename Callback>
248inline void checkDbusPathExists(const std::string& path, Callback&& callback)
249{
250 using GetObjectType =
251 std::vector<std::pair<std::string, std::vector<std::string>>>;
252
253 crow::connections::systemBus->async_method_call(
254 [callback{std::move(callback)}](const boost::system::error_code ec,
255 const GetObjectType& object_names) {
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530256 callback(!ec && object_names.size() != 0);
Ed Tanousa8408792018-09-05 16:08:38 -0700257 },
258 "xyz.openbmc_project.ObjectMapper",
259 "/xyz/openbmc_project/object_mapper",
260 "xyz.openbmc_project.ObjectMapper", "GetObject", path,
261 std::array<std::string, 0>());
262}
263
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700264class ManagerAccount : public Node
265{
266 public:
267 ManagerAccount(CrowApp& app) :
268 Node(app, "/redfish/v1/AccountService/Accounts/<str>/", std::string())
269 {
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700270 entityPrivileges = {
271 {boost::beast::http::verb::get,
272 {{"ConfigureUsers"}, {"ConfigureManager"}, {"ConfigureSelf"}}},
273 {boost::beast::http::verb::head, {{"Login"}}},
274 {boost::beast::http::verb::patch, {{"ConfigureUsers"}}},
275 {boost::beast::http::verb::put, {{"ConfigureUsers"}}},
276 {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}},
277 {boost::beast::http::verb::post, {{"ConfigureUsers"}}}};
278 }
279
280 private:
281 void doGet(crow::Response& res, const crow::Request& req,
282 const std::vector<std::string>& params) override
283 {
Ed Tanous0f74e642018-11-12 15:17:05 -0800284 res.jsonValue = {
285 {"@odata.context",
286 "/redfish/v1/$metadata#ManagerAccount.ManagerAccount"},
287 {"@odata.type", "#ManagerAccount.v1_0_3.ManagerAccount"},
Ed Tanous0f74e642018-11-12 15:17:05 -0800288 {"Name", "User Account"},
289 {"Description", "User Account"},
290 {"Password", nullptr},
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530291 {"RoleId", "Administrator"}};
Ed Tanous0f74e642018-11-12 15:17:05 -0800292
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700293 auto asyncResp = std::make_shared<AsyncResp>(res);
294
295 if (params.size() != 1)
296 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700297 messages::internalError(asyncResp->res);
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700298 return;
299 }
300
301 crow::connections::systemBus->async_method_call(
302 [asyncResp, accountName{std::string(params[0])}](
303 const boost::system::error_code ec,
304 const ManagedObjectType& users) {
305 if (ec)
306 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700307 messages::internalError(asyncResp->res);
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700308 return;
309 }
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530310 auto userIt = users.begin();
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700311
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530312 for (; userIt != users.end(); userIt++)
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700313 {
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530314 if (boost::ends_with(userIt->first.str, "/" + accountName))
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700315 {
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530316 break;
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700317 }
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530318 }
319 if (userIt == users.end())
320 {
321 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
322 accountName);
323 return;
324 }
325 for (const auto& interface : userIt->second)
326 {
327 if (interface.first ==
328 "xyz.openbmc_project.User.Attributes")
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700329 {
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530330 for (const auto& property : interface.second)
Ed Tanous65b0dc32018-09-19 16:04:03 -0700331 {
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530332 if (property.first == "UserEnabled")
Ed Tanous65b0dc32018-09-19 16:04:03 -0700333 {
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530334 const bool* userEnabled =
335 sdbusplus::message::variant_ns::get_if<
336 bool>(&property.second);
337 if (userEnabled == nullptr)
Ed Tanous65b0dc32018-09-19 16:04:03 -0700338 {
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530339 BMCWEB_LOG_ERROR
340 << "UserEnabled wasn't a bool";
341 messages::internalError(asyncResp->res);
342 return;
Ed Tanous65b0dc32018-09-19 16:04:03 -0700343 }
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530344 asyncResp->res.jsonValue["Enabled"] =
345 *userEnabled;
346 }
347 else if (property.first ==
348 "UserLockedForFailedAttempt")
349 {
350 const bool* userLocked =
351 sdbusplus::message::variant_ns::get_if<
352 bool>(&property.second);
353 if (userLocked == nullptr)
354 {
355 BMCWEB_LOG_ERROR << "UserLockedForF"
356 "ailedAttempt "
357 "wasn't a bool";
358 messages::internalError(asyncResp->res);
359 return;
360 }
361 asyncResp->res.jsonValue["Locked"] =
362 *userLocked;
363 }
364 else if (property.first == "UserPrivilege")
365 {
366 const std::string* userRolePtr =
367 sdbusplus::message::variant_ns::get_if<
368 std::string>(&property.second);
369 if (userRolePtr == nullptr)
370 {
371 BMCWEB_LOG_ERROR
372 << "UserPrivilege wasn't a "
373 "string";
374 messages::internalError(asyncResp->res);
375 return;
376 }
377 std::string priv =
378 getPrivilegeFromRoleId(*userRolePtr);
379 if (priv.empty())
380 {
381 BMCWEB_LOG_ERROR << "Invalid user role";
382 messages::internalError(asyncResp->res);
383 return;
384 }
385 asyncResp->res.jsonValue["RoleId"] = priv;
386
387 asyncResp->res.jsonValue["Links"]["Role"] = {
388 {"@odata.id", "/redfish/v1/AccountService/"
389 "Roles/" +
390 priv}};
Ed Tanous65b0dc32018-09-19 16:04:03 -0700391 }
392 }
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700393 }
394 }
395
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530396 asyncResp->res.jsonValue["@odata.id"] =
397 "/redfish/v1/AccountService/Accounts/" + accountName;
398 asyncResp->res.jsonValue["Id"] = accountName;
399 asyncResp->res.jsonValue["UserName"] = accountName;
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700400 },
401 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
402 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
403 }
Ed Tanousa8408792018-09-05 16:08:38 -0700404
405 void doPatch(crow::Response& res, const crow::Request& req,
406 const std::vector<std::string>& params) override
407 {
408 auto asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanousa8408792018-09-05 16:08:38 -0700409 if (params.size() != 1)
410 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700411 messages::internalError(asyncResp->res);
Ed Tanousa8408792018-09-05 16:08:38 -0700412 return;
413 }
414
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530415 boost::optional<std::string> newUserName;
Ed Tanous9712f8a2018-09-21 13:38:49 -0700416 boost::optional<std::string> password;
417 boost::optional<bool> enabled;
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530418 boost::optional<std::string> roleId;
419 if (!json_util::readJson(req, res, "UserName", newUserName, "Password",
420 password, "RoleId", roleId, "Enabled",
Ed Tanous9712f8a2018-09-21 13:38:49 -0700421 enabled))
Ed Tanousa8408792018-09-05 16:08:38 -0700422 {
423 return;
424 }
425
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530426 const std::string& username = params[0];
Ed Tanousa8408792018-09-05 16:08:38 -0700427
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530428 if (!newUserName)
429 {
430 // If the username isn't being updated, we can update the properties
431 // directly
432 updateUserProperties(asyncResp, username, password, enabled,
433 roleId);
434 return;
435 }
436 else
437 {
438 crow::connections::systemBus->async_method_call(
439 [this, asyncResp, username, password(std::move(password)),
440 roleId(std::move(roleId)), enabled(std::move(enabled)),
441 newUser{std::string(*newUserName)}](
442 const boost::system::error_code ec) {
443 if (ec)
Ed Tanousa8408792018-09-05 16:08:38 -0700444 {
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530445 BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
446 messages::resourceNotFound(
447 asyncResp->res,
448 "#ManagerAccount.v1_0_3.ManagerAccount", username);
449 return;
450 }
451
452 updateUserProperties(asyncResp, newUser, password, enabled,
453 roleId);
454 },
455 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
456 "xyz.openbmc_project.User.Manager", "RenameUser", username,
457 *newUserName);
458 }
459 }
460
461 void updateUserProperties(std::shared_ptr<AsyncResp> asyncResp,
462 const std::string& username,
463 boost::optional<std::string> password,
464 boost::optional<bool> enabled,
465 boost::optional<std::string> roleId)
466 {
467 if (password)
468 {
469 if (!pamUpdatePassword(username, *password))
470 {
471 BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
472 messages::internalError(asyncResp->res);
473 return;
474 }
475 }
476
477 if (enabled)
478 {
479 crow::connections::systemBus->async_method_call(
480 [asyncResp](const boost::system::error_code ec) {
481 if (ec)
482 {
483 BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
Jason M. Billsf12894f2018-10-09 12:45:45 -0700484 messages::internalError(asyncResp->res);
Ed Tanousa8408792018-09-05 16:08:38 -0700485 return;
486 }
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530487 messages::success(asyncResp->res);
488 return;
489 },
490 "xyz.openbmc_project.User.Manager",
491 "/xyz/openbmc_project/user/" + username,
492 "org.freedesktop.DBus.Properties", "Set",
493 "xyz.openbmc_project.User.Attributes", "UserEnabled",
494 sdbusplus::message::variant<bool>{*enabled});
495 }
Ed Tanous9712f8a2018-09-21 13:38:49 -0700496
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530497 if (roleId)
498 {
499 std::string priv = getRoleIdFromPrivilege(*roleId);
500 if (priv.empty())
501 {
502 messages::propertyValueNotInList(asyncResp->res, *roleId,
503 "RoleId");
504 return;
505 }
506
507 crow::connections::systemBus->async_method_call(
508 [asyncResp](const boost::system::error_code ec) {
509 if (ec)
510 {
511 BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
512 messages::internalError(asyncResp->res);
513 return;
514 }
515 messages::success(asyncResp->res);
516 },
517 "xyz.openbmc_project.User.Manager",
518 "/xyz/openbmc_project/user/" + username,
519 "org.freedesktop.DBus.Properties", "Set",
520 "xyz.openbmc_project.User.Attributes", "UserPrivilege",
521 sdbusplus::message::variant<std::string>{priv});
522 }
Ed Tanousa8408792018-09-05 16:08:38 -0700523 }
Ed Tanous06e086d2018-09-19 17:19:52 -0700524
525 void doDelete(crow::Response& res, const crow::Request& req,
526 const std::vector<std::string>& params) override
527 {
528 auto asyncResp = std::make_shared<AsyncResp>(res);
529
530 if (params.size() != 1)
531 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700532 messages::internalError(asyncResp->res);
Ed Tanous06e086d2018-09-19 17:19:52 -0700533 return;
534 }
535
536 const std::string userPath = "/xyz/openbmc_project/user/" + params[0];
537
538 crow::connections::systemBus->async_method_call(
539 [asyncResp, username{std::move(params[0])}](
540 const boost::system::error_code ec) {
541 if (ec)
542 {
Jason M. Billsf12894f2018-10-09 12:45:45 -0700543 messages::resourceNotFound(
544 asyncResp->res, "#ManagerAccount.v1_0_3.ManagerAccount",
545 username);
Ed Tanous06e086d2018-09-19 17:19:52 -0700546 return;
547 }
548
Jason M. Billsf12894f2018-10-09 12:45:45 -0700549 messages::accountRemoved(asyncResp->res);
Ed Tanous06e086d2018-09-19 17:19:52 -0700550 },
551 "xyz.openbmc_project.User.Manager", userPath,
552 "xyz.openbmc_project.Object.Delete", "Delete");
553 }
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530554};
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +0100555
Ed Tanous1abe55e2018-09-05 08:30:59 -0700556} // namespace redfish