Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 1 | #pragma once |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 2 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 3 | #include "app.hpp" |
| 4 | #include "async_resp.hpp" |
| 5 | #include "error_messages.hpp" |
| 6 | #include "event_service_manager.hpp" |
| 7 | #include "ibm/locks.hpp" |
| 8 | #include "resource_messages.hpp" |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame^] | 9 | #include "str_utility.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 10 | #include "utils/json_utils.hpp" |
| 11 | |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 12 | #include <boost/container/flat_set.hpp> |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 13 | #include <nlohmann/json.hpp> |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 14 | #include <sdbusplus/message/types.hpp> |
| 15 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 16 | #include <filesystem> |
| 17 | #include <fstream> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 18 | |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 19 | using SType = std::string; |
| 20 | using SegmentFlags = std::vector<std::pair<std::string, uint32_t>>; |
| 21 | using LockRequest = std::tuple<SType, SType, SType, uint64_t, SegmentFlags>; |
| 22 | using LockRequests = std::vector<LockRequest>; |
| 23 | using Rc = std::pair<bool, std::variant<uint32_t, LockRequest>>; |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 24 | using RcGetLockList = |
| 25 | std::variant<std::string, std::vector<std::pair<uint32_t, LockRequests>>>; |
| 26 | using ListOfSessionIds = std::vector<std::string>; |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 27 | namespace crow |
| 28 | { |
| 29 | namespace ibm_mc |
| 30 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 31 | constexpr const char* methodNotAllowedMsg = "Method Not Allowed"; |
| 32 | constexpr const char* resourceNotFoundMsg = "Resource Not Found"; |
| 33 | constexpr const char* contentNotAcceptableMsg = "Content Not Acceptable"; |
| 34 | constexpr const char* internalServerError = "Internal Server Error"; |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 35 | |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 36 | constexpr size_t maxSaveareaDirSize = |
Sunitha Harish | f8a4347 | 2022-08-08 02:07:12 -0500 | [diff] [blame] | 37 | 25000000; // Allow save area dir size to be max 25MB |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 38 | constexpr size_t minSaveareaFileSize = |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 39 | 100; // Allow save area file size of minimum 100B |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 40 | constexpr size_t maxSaveareaFileSize = |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 41 | 500000; // Allow save area file size upto 500KB |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 42 | constexpr size_t maxBroadcastMsgSize = |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 43 | 1000; // Allow Broadcast message size upto 1KB |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 44 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 45 | inline void handleFilePut(const crow::Request& req, |
| 46 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 47 | const std::string& fileID) |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 48 | { |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 49 | std::error_code ec; |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 50 | // Check the content-type of the request |
Sunitha Harish | 086d32c | 2021-02-01 02:11:49 -0600 | [diff] [blame] | 51 | boost::beast::string_view contentType = req.getHeaderValue("content-type"); |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame^] | 52 | if (!bmcweb::asciiIEquals(contentType, "application/octet-stream")) |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 53 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 54 | asyncResp->res.result(boost::beast::http::status::not_acceptable); |
| 55 | asyncResp->res.jsonValue["Description"] = contentNotAcceptableMsg; |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 56 | return; |
| 57 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 58 | BMCWEB_LOG_DEBUG( |
| 59 | "File upload in application/octet-stream format. Continue.."); |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 60 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 61 | BMCWEB_LOG_DEBUG( |
| 62 | "handleIbmPut: Request to create/update the save-area file"); |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 63 | std::string_view path = |
| 64 | "/var/lib/bmcweb/ibm-management-console/configfiles"; |
| 65 | if (!crow::ibm_utils::createDirectory(path)) |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 66 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 67 | asyncResp->res.result(boost::beast::http::status::not_found); |
| 68 | asyncResp->res.jsonValue["Description"] = resourceNotFoundMsg; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 69 | return; |
| 70 | } |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 71 | |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 72 | std::ofstream file; |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 73 | std::filesystem::path loc( |
| 74 | "/var/lib/bmcweb/ibm-management-console/configfiles"); |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 75 | |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 76 | // Get the current size of the savearea directory |
| 77 | std::filesystem::recursive_directory_iterator iter(loc, ec); |
| 78 | if (ec) |
| 79 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 80 | asyncResp->res.result( |
| 81 | boost::beast::http::status::internal_server_error); |
| 82 | asyncResp->res.jsonValue["Description"] = internalServerError; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 83 | BMCWEB_LOG_DEBUG("handleIbmPut: Failed to prepare save-area " |
| 84 | "directory iterator. ec : {}", |
| 85 | ec.message()); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 86 | return; |
| 87 | } |
| 88 | std::uintmax_t saveAreaDirSize = 0; |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 89 | for (const auto& it : iter) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 90 | { |
| 91 | if (!std::filesystem::is_directory(it, ec)) |
| 92 | { |
| 93 | if (ec) |
| 94 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 95 | asyncResp->res.result( |
| 96 | boost::beast::http::status::internal_server_error); |
| 97 | asyncResp->res.jsonValue["Description"] = internalServerError; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 98 | BMCWEB_LOG_DEBUG("handleIbmPut: Failed to find save-area " |
| 99 | "directory . ec : {}", |
| 100 | ec.message()); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 101 | return; |
| 102 | } |
| 103 | std::uintmax_t fileSize = std::filesystem::file_size(it, ec); |
| 104 | if (ec) |
| 105 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 106 | asyncResp->res.result( |
| 107 | boost::beast::http::status::internal_server_error); |
| 108 | asyncResp->res.jsonValue["Description"] = internalServerError; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 109 | BMCWEB_LOG_DEBUG("handleIbmPut: Failed to find save-area " |
| 110 | "file size inside the directory . ec : {}", |
| 111 | ec.message()); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 112 | return; |
| 113 | } |
| 114 | saveAreaDirSize += fileSize; |
| 115 | } |
| 116 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 117 | BMCWEB_LOG_DEBUG("saveAreaDirSize: {}", saveAreaDirSize); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 118 | |
| 119 | // Get the file size getting uploaded |
Ed Tanous | 33c6b58 | 2023-02-14 15:05:48 -0800 | [diff] [blame] | 120 | const std::string& data = req.body(); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 121 | BMCWEB_LOG_DEBUG("data length: {}", data.length()); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 122 | |
| 123 | if (data.length() < minSaveareaFileSize) |
| 124 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 125 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 126 | asyncResp->res.jsonValue["Description"] = |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 127 | "File size is less than minimum allowed size[100B]"; |
| 128 | return; |
| 129 | } |
| 130 | if (data.length() > maxSaveareaFileSize) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 131 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 132 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 133 | asyncResp->res.jsonValue["Description"] = |
Ratan Gupta | e46946a | 2020-05-11 13:22:59 +0530 | [diff] [blame] | 134 | "File size exceeds maximum allowed size[500KB]"; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 135 | return; |
| 136 | } |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 137 | |
| 138 | // Form the file path |
| 139 | loc /= fileID; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 140 | BMCWEB_LOG_DEBUG("Writing to the file: {}", loc.string()); |
Asmitha Karunanithi | 10693fa | 2020-07-27 02:27:49 -0500 | [diff] [blame] | 141 | |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 142 | // Check if the same file exists in the directory |
| 143 | bool fileExists = std::filesystem::exists(loc, ec); |
| 144 | if (ec) |
Asmitha Karunanithi | 10693fa | 2020-07-27 02:27:49 -0500 | [diff] [blame] | 145 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 146 | asyncResp->res.result( |
| 147 | boost::beast::http::status::internal_server_error); |
| 148 | asyncResp->res.jsonValue["Description"] = internalServerError; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 149 | BMCWEB_LOG_DEBUG("handleIbmPut: Failed to find if file exists. ec : {}", |
| 150 | ec.message()); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 151 | return; |
Asmitha Karunanithi | 10693fa | 2020-07-27 02:27:49 -0500 | [diff] [blame] | 152 | } |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 153 | |
| 154 | std::uintmax_t newSizeToWrite = 0; |
| 155 | if (fileExists) |
| 156 | { |
| 157 | // File exists. Get the current file size |
| 158 | std::uintmax_t currentFileSize = std::filesystem::file_size(loc, ec); |
| 159 | if (ec) |
| 160 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 161 | asyncResp->res.result( |
| 162 | boost::beast::http::status::internal_server_error); |
| 163 | asyncResp->res.jsonValue["Description"] = internalServerError; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 164 | BMCWEB_LOG_DEBUG("handleIbmPut: Failed to find file size. ec : {}", |
| 165 | ec.message()); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 166 | return; |
| 167 | } |
| 168 | // Calculate the difference in the file size. |
| 169 | // If the data.length is greater than the existing file size, then |
| 170 | // calculate the difference. Else consider the delta size as zero - |
| 171 | // because there is no increase in the total directory size. |
| 172 | // We need to add the diff only if the incoming data is larger than the |
| 173 | // existing filesize |
| 174 | if (data.length() > currentFileSize) |
| 175 | { |
| 176 | newSizeToWrite = data.length() - currentFileSize; |
| 177 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 178 | BMCWEB_LOG_DEBUG("newSizeToWrite: {}", newSizeToWrite); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 179 | } |
| 180 | else |
| 181 | { |
| 182 | // This is a new file upload |
| 183 | newSizeToWrite = data.length(); |
| 184 | } |
| 185 | |
| 186 | // Calculate the total dir size before writing the new file |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 187 | BMCWEB_LOG_DEBUG("total new size: {}", saveAreaDirSize + newSizeToWrite); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 188 | |
| 189 | if ((saveAreaDirSize + newSizeToWrite) > maxSaveareaDirSize) |
| 190 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 191 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 192 | asyncResp->res.jsonValue["Description"] = |
| 193 | "File size does not fit in the savearea " |
Sunitha Harish | f8a4347 | 2022-08-08 02:07:12 -0500 | [diff] [blame] | 194 | "directory maximum allowed size[25MB]"; |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 198 | file.open(loc, std::ofstream::out); |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 199 | |
| 200 | // set the permission of the file to 600 |
| 201 | std::filesystem::perms permission = std::filesystem::perms::owner_write | |
| 202 | std::filesystem::perms::owner_read; |
| 203 | std::filesystem::permissions(loc, permission); |
| 204 | |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 205 | if (file.fail()) |
| 206 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 207 | BMCWEB_LOG_DEBUG("Error while opening the file for writing"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 208 | asyncResp->res.result( |
| 209 | boost::beast::http::status::internal_server_error); |
| 210 | asyncResp->res.jsonValue["Description"] = |
| 211 | "Error while creating the file"; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 212 | return; |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 213 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 214 | file << data; |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 215 | |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 216 | std::string origin = "/ibm/v1/Host/ConfigFiles/" + fileID; |
| 217 | // Push an event |
| 218 | if (fileExists) |
| 219 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 220 | BMCWEB_LOG_DEBUG("config file is updated"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 221 | asyncResp->res.jsonValue["Description"] = "File Updated"; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 222 | } |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 223 | else |
| 224 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 225 | BMCWEB_LOG_DEBUG("config file is created"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 226 | asyncResp->res.jsonValue["Description"] = "File Created"; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 227 | } |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 228 | } |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 229 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 230 | inline void |
| 231 | handleConfigFileList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 232 | { |
| 233 | std::vector<std::string> pathObjList; |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 234 | std::filesystem::path loc( |
| 235 | "/var/lib/bmcweb/ibm-management-console/configfiles"); |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 236 | if (std::filesystem::exists(loc) && std::filesystem::is_directory(loc)) |
| 237 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 238 | for (const auto& file : std::filesystem::directory_iterator(loc)) |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 239 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 240 | const std::filesystem::path& pathObj = file.path(); |
cm-jishnu | 5a19396 | 2022-12-02 03:45:27 -0600 | [diff] [blame] | 241 | if (std::filesystem::is_regular_file(pathObj)) |
| 242 | { |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 243 | pathObjList.emplace_back("/ibm/v1/Host/ConfigFiles/" + |
| 244 | pathObj.filename().string()); |
cm-jishnu | 5a19396 | 2022-12-02 03:45:27 -0600 | [diff] [blame] | 245 | } |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 246 | } |
| 247 | } |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 248 | asyncResp->res.jsonValue["@odata.type"] = |
| 249 | "#IBMConfigFile.v1_0_0.IBMConfigFile"; |
| 250 | asyncResp->res.jsonValue["@odata.id"] = "/ibm/v1/Host/ConfigFiles/"; |
| 251 | asyncResp->res.jsonValue["Id"] = "ConfigFiles"; |
| 252 | asyncResp->res.jsonValue["Name"] = "ConfigFiles"; |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 253 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 254 | asyncResp->res.jsonValue["Members"] = std::move(pathObjList); |
| 255 | asyncResp->res.jsonValue["Actions"]["#IBMConfigFiles.DeleteAll"] = { |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 256 | {"target", |
Sunitha Harish | e56f254 | 2020-07-22 02:38:59 -0500 | [diff] [blame] | 257 | "/ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll"}}; |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 258 | } |
| 259 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 260 | inline void |
| 261 | deleteConfigFiles(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 262 | { |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 263 | std::error_code ec; |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 264 | std::filesystem::path loc( |
| 265 | "/var/lib/bmcweb/ibm-management-console/configfiles"); |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 266 | if (std::filesystem::exists(loc) && std::filesystem::is_directory(loc)) |
| 267 | { |
| 268 | std::filesystem::remove_all(loc, ec); |
| 269 | if (ec) |
| 270 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 271 | asyncResp->res.result( |
| 272 | boost::beast::http::status::internal_server_error); |
| 273 | asyncResp->res.jsonValue["Description"] = internalServerError; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 274 | BMCWEB_LOG_DEBUG("deleteConfigFiles: Failed to delete the " |
| 275 | "config files directory. ec : {}", |
| 276 | ec.message()); |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 277 | } |
| 278 | } |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 279 | } |
| 280 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 281 | inline void |
| 282 | getLockServiceData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 283 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 284 | asyncResp->res.jsonValue["@odata.type"] = "#LockService.v1_0_0.LockService"; |
| 285 | asyncResp->res.jsonValue["@odata.id"] = "/ibm/v1/HMC/LockService/"; |
| 286 | asyncResp->res.jsonValue["Id"] = "LockService"; |
| 287 | asyncResp->res.jsonValue["Name"] = "LockService"; |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 288 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 289 | asyncResp->res.jsonValue["Actions"]["#LockService.AcquireLock"] = { |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 290 | {"target", "/ibm/v1/HMC/LockService/Actions/LockService.AcquireLock"}}; |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 291 | asyncResp->res.jsonValue["Actions"]["#LockService.ReleaseLock"] = { |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 292 | {"target", "/ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock"}}; |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 293 | asyncResp->res.jsonValue["Actions"]["#LockService.GetLockList"] = { |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 294 | {"target", "/ibm/v1/HMC/LockService/Actions/LockService.GetLockList"}}; |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 295 | } |
| 296 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 297 | inline void handleFileGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 298 | const std::string& fileID) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 299 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 300 | BMCWEB_LOG_DEBUG("HandleGet on SaveArea files on path: {}", fileID); |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 301 | std::filesystem::path loc( |
| 302 | "/var/lib/bmcweb/ibm-management-console/configfiles/" + fileID); |
cm-jishnu | 5a19396 | 2022-12-02 03:45:27 -0600 | [diff] [blame] | 303 | if (!std::filesystem::exists(loc) || !std::filesystem::is_regular_file(loc)) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 304 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 305 | BMCWEB_LOG_WARNING("{} Not found", loc.string()); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 306 | asyncResp->res.result(boost::beast::http::status::not_found); |
| 307 | asyncResp->res.jsonValue["Description"] = resourceNotFoundMsg; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 308 | return; |
| 309 | } |
| 310 | |
| 311 | std::ifstream readfile(loc.string()); |
| 312 | if (!readfile) |
| 313 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 314 | BMCWEB_LOG_WARNING("{} Not found", loc.string()); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 315 | asyncResp->res.result(boost::beast::http::status::not_found); |
| 316 | asyncResp->res.jsonValue["Description"] = resourceNotFoundMsg; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 317 | return; |
| 318 | } |
| 319 | |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 320 | std::string contentDispositionParam = "attachment; filename=\"" + fileID + |
| 321 | "\""; |
Ed Tanous | d9f6c62 | 2022-03-17 09:12:17 -0700 | [diff] [blame] | 322 | asyncResp->res.addHeader(boost::beast::http::field::content_disposition, |
| 323 | contentDispositionParam); |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 324 | std::string fileData; |
| 325 | fileData = {std::istreambuf_iterator<char>(readfile), |
| 326 | std::istreambuf_iterator<char>()}; |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 327 | asyncResp->res.jsonValue["Data"] = fileData; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 328 | } |
| 329 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 330 | inline void |
| 331 | handleFileDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 332 | const std::string& fileID) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 333 | { |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 334 | std::string filePath("/var/lib/bmcweb/ibm-management-console/configfiles/" + |
| 335 | fileID); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 336 | BMCWEB_LOG_DEBUG("Removing the file : {}", filePath); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 337 | std::ifstream fileOpen(filePath.c_str()); |
| 338 | if (static_cast<bool>(fileOpen)) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 339 | { |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 340 | if (remove(filePath.c_str()) == 0) |
| 341 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 342 | BMCWEB_LOG_DEBUG("File removed!"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 343 | asyncResp->res.jsonValue["Description"] = "File Deleted"; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 344 | } |
| 345 | else |
| 346 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 347 | BMCWEB_LOG_ERROR("File not removed!"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 348 | asyncResp->res.result( |
| 349 | boost::beast::http::status::internal_server_error); |
| 350 | asyncResp->res.jsonValue["Description"] = internalServerError; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 351 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 352 | } |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 353 | else |
| 354 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 355 | BMCWEB_LOG_WARNING("File not found!"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 356 | asyncResp->res.result(boost::beast::http::status::not_found); |
| 357 | asyncResp->res.jsonValue["Description"] = resourceNotFoundMsg; |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 358 | } |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 359 | } |
| 360 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 361 | inline void |
| 362 | handleBroadcastService(const crow::Request& req, |
| 363 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 364 | { |
| 365 | std::string broadcastMsg; |
| 366 | |
Willy Tu | 15ed678 | 2021-12-14 11:03:16 -0800 | [diff] [blame] | 367 | if (!redfish::json_util::readJsonPatch(req, asyncResp->res, "Message", |
| 368 | broadcastMsg)) |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 369 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 370 | BMCWEB_LOG_DEBUG("Not a Valid JSON"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 371 | asyncResp->res.result(boost::beast::http::status::bad_request); |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 372 | return; |
| 373 | } |
| 374 | if (broadcastMsg.size() > maxBroadcastMsgSize) |
| 375 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 376 | BMCWEB_LOG_ERROR("Message size exceeds maximum allowed size[1KB]"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 377 | asyncResp->res.result(boost::beast::http::status::bad_request); |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 378 | return; |
| 379 | } |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 380 | } |
| 381 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 382 | inline void handleFileUrl(const crow::Request& req, |
| 383 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 384 | const std::string& fileID) |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 385 | { |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 386 | if (req.method() == boost::beast::http::verb::put) |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 387 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 388 | handleFilePut(req, asyncResp, fileID); |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 389 | return; |
| 390 | } |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 391 | if (req.method() == boost::beast::http::verb::get) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 392 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 393 | handleFileGet(asyncResp, fileID); |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 394 | return; |
| 395 | } |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 396 | if (req.method() == boost::beast::http::verb::delete_) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 397 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 398 | handleFileDelete(asyncResp, fileID); |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 399 | return; |
| 400 | } |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 401 | } |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 402 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 403 | inline void |
| 404 | handleAcquireLockAPI(const crow::Request& req, |
| 405 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 406 | std::vector<nlohmann::json> body) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 407 | { |
| 408 | LockRequests lockRequestStructure; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 409 | for (auto& element : body) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 410 | { |
| 411 | std::string lockType; |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 412 | uint64_t resourceId = 0; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 413 | |
| 414 | SegmentFlags segInfo; |
| 415 | std::vector<nlohmann::json> segmentFlags; |
| 416 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 417 | if (!redfish::json_util::readJson(element, asyncResp->res, "LockType", |
| 418 | lockType, "ResourceID", resourceId, |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 419 | "SegmentFlags", segmentFlags)) |
| 420 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 421 | BMCWEB_LOG_DEBUG("Not a Valid JSON"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 422 | asyncResp->res.result(boost::beast::http::status::bad_request); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 423 | return; |
| 424 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 425 | BMCWEB_LOG_DEBUG("{}", lockType); |
| 426 | BMCWEB_LOG_DEBUG("{}", resourceId); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 427 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 428 | BMCWEB_LOG_DEBUG("Segment Flags are present"); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 429 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 430 | for (auto& e : segmentFlags) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 431 | { |
| 432 | std::string lockFlags; |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 433 | uint32_t segmentLength = 0; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 434 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 435 | if (!redfish::json_util::readJson(e, asyncResp->res, "LockFlag", |
| 436 | lockFlags, "SegmentLength", |
| 437 | segmentLength)) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 438 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 439 | asyncResp->res.result(boost::beast::http::status::bad_request); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 440 | return; |
| 441 | } |
| 442 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 443 | BMCWEB_LOG_DEBUG("Lockflag : {}", lockFlags); |
| 444 | BMCWEB_LOG_DEBUG("SegmentLength : {}", segmentLength); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 445 | |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 446 | segInfo.emplace_back(std::make_pair(lockFlags, segmentLength)); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 447 | } |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 448 | |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 449 | lockRequestStructure.emplace_back(make_tuple( |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 450 | req.session->uniqueId, req.session->clientId.value_or(""), lockType, |
| 451 | resourceId, segInfo)); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | // print lock request into journal |
| 455 | |
Ed Tanous | 4e08751 | 2020-09-28 18:41:25 -0700 | [diff] [blame] | 456 | for (auto& i : lockRequestStructure) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 457 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 458 | BMCWEB_LOG_DEBUG("{}", std::get<0>(i)); |
| 459 | BMCWEB_LOG_DEBUG("{}", std::get<1>(i)); |
| 460 | BMCWEB_LOG_DEBUG("{}", std::get<2>(i)); |
| 461 | BMCWEB_LOG_DEBUG("{}", std::get<3>(i)); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 462 | |
Ed Tanous | 4e08751 | 2020-09-28 18:41:25 -0700 | [diff] [blame] | 463 | for (const auto& p : std::get<4>(i)) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 464 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 465 | BMCWEB_LOG_DEBUG("{}, {}", p.first, p.second); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 469 | const LockRequests& t = lockRequestStructure; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 470 | |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 471 | auto varAcquireLock = crow::ibm_mc_lock::Lock::getInstance().acquireLock(t); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 472 | |
| 473 | if (varAcquireLock.first) |
| 474 | { |
| 475 | // Either validity failure of there is a conflict with itself |
| 476 | |
| 477 | auto validityStatus = |
| 478 | std::get<std::pair<bool, int>>(varAcquireLock.second); |
| 479 | |
| 480 | if ((!validityStatus.first) && (validityStatus.second == 0)) |
| 481 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 482 | BMCWEB_LOG_DEBUG("Not a Valid record"); |
| 483 | BMCWEB_LOG_DEBUG("Bad json in request"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 484 | asyncResp->res.result(boost::beast::http::status::bad_request); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 485 | return; |
| 486 | } |
| 487 | if (validityStatus.first && (validityStatus.second == 1)) |
| 488 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 489 | BMCWEB_LOG_ERROR("There is a conflict within itself"); |
Sunitha Harish | f8a4347 | 2022-08-08 02:07:12 -0500 | [diff] [blame] | 490 | asyncResp->res.result(boost::beast::http::status::conflict); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 491 | return; |
| 492 | } |
| 493 | } |
| 494 | else |
| 495 | { |
| 496 | auto conflictStatus = |
| 497 | std::get<crow::ibm_mc_lock::Rc>(varAcquireLock.second); |
| 498 | if (!conflictStatus.first) |
| 499 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 500 | BMCWEB_LOG_DEBUG("There is no conflict with the locktable"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 501 | asyncResp->res.result(boost::beast::http::status::ok); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 502 | |
| 503 | auto var = std::get<uint32_t>(conflictStatus.second); |
| 504 | nlohmann::json returnJson; |
| 505 | returnJson["id"] = var; |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 506 | asyncResp->res.jsonValue["TransactionID"] = var; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 507 | return; |
| 508 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 509 | BMCWEB_LOG_DEBUG("There is a conflict with the lock table"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 510 | asyncResp->res.result(boost::beast::http::status::conflict); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 511 | auto var = |
| 512 | std::get<std::pair<uint32_t, LockRequest>>(conflictStatus.second); |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 513 | nlohmann::json returnJson; |
| 514 | nlohmann::json segments; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 515 | nlohmann::json myarray = nlohmann::json::array(); |
| 516 | returnJson["TransactionID"] = var.first; |
| 517 | returnJson["SessionID"] = std::get<0>(var.second); |
| 518 | returnJson["HMCID"] = std::get<1>(var.second); |
| 519 | returnJson["LockType"] = std::get<2>(var.second); |
| 520 | returnJson["ResourceID"] = std::get<3>(var.second); |
| 521 | |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 522 | for (const auto& i : std::get<4>(var.second)) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 523 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 524 | segments["LockFlag"] = i.first; |
| 525 | segments["SegmentLength"] = i.second; |
| 526 | myarray.push_back(segments); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 527 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 528 | |
| 529 | returnJson["SegmentFlags"] = myarray; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 530 | BMCWEB_LOG_ERROR("Conflicting lock record: {}", returnJson); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 531 | asyncResp->res.jsonValue["Record"] = returnJson; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 532 | return; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 533 | } |
| 534 | } |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 535 | inline void |
| 536 | handleRelaseAllAPI(const crow::Request& req, |
| 537 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Manojkiran Eda | 5bb0ece | 2020-01-20 20:22:36 +0530 | [diff] [blame] | 538 | { |
| 539 | crow::ibm_mc_lock::Lock::getInstance().releaseLock(req.session->uniqueId); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 540 | asyncResp->res.result(boost::beast::http::status::ok); |
Manojkiran Eda | 5bb0ece | 2020-01-20 20:22:36 +0530 | [diff] [blame] | 541 | } |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 542 | |
Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 543 | inline void |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 544 | handleReleaseLockAPI(const crow::Request& req, |
| 545 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 546 | const std::vector<uint32_t>& listTransactionIds) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 547 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 548 | BMCWEB_LOG_DEBUG("{}", listTransactionIds.size()); |
| 549 | BMCWEB_LOG_DEBUG("Data is present"); |
Ed Tanous | 4e08751 | 2020-09-28 18:41:25 -0700 | [diff] [blame] | 550 | for (unsigned int listTransactionId : listTransactionIds) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 551 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 552 | BMCWEB_LOG_DEBUG("{}", listTransactionId); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 553 | } |
| 554 | |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 555 | // validate the request ids |
| 556 | |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 557 | auto varReleaselock = crow::ibm_mc_lock::Lock::getInstance().releaseLock( |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 558 | listTransactionIds, std::make_pair(req.session->clientId.value_or(""), |
| 559 | req.session->uniqueId)); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 560 | |
| 561 | if (!varReleaselock.first) |
| 562 | { |
| 563 | // validation Failed |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 564 | BMCWEB_LOG_ERROR("handleReleaseLockAPI: validation failed"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 565 | asyncResp->res.result(boost::beast::http::status::bad_request); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 566 | return; |
| 567 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 568 | auto statusRelease = |
| 569 | std::get<crow::ibm_mc_lock::RcRelaseLock>(varReleaselock.second); |
| 570 | if (statusRelease.first) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 571 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 572 | // The current hmc owns all the locks, so we already released |
| 573 | // them |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 574 | return; |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 575 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 576 | |
| 577 | // valid rid, but the current hmc does not own all the locks |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 578 | BMCWEB_LOG_DEBUG("Current HMC does not own all the locks"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 579 | asyncResp->res.result(boost::beast::http::status::unauthorized); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 580 | |
| 581 | auto var = statusRelease.second; |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 582 | nlohmann::json returnJson; |
| 583 | nlohmann::json segments; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 584 | nlohmann::json myArray = nlohmann::json::array(); |
| 585 | returnJson["TransactionID"] = var.first; |
| 586 | returnJson["SessionID"] = std::get<0>(var.second); |
| 587 | returnJson["HMCID"] = std::get<1>(var.second); |
| 588 | returnJson["LockType"] = std::get<2>(var.second); |
| 589 | returnJson["ResourceID"] = std::get<3>(var.second); |
| 590 | |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 591 | for (const auto& i : std::get<4>(var.second)) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 592 | { |
| 593 | segments["LockFlag"] = i.first; |
| 594 | segments["SegmentLength"] = i.second; |
| 595 | myArray.push_back(segments); |
| 596 | } |
| 597 | |
| 598 | returnJson["SegmentFlags"] = myArray; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 599 | BMCWEB_LOG_DEBUG("handleReleaseLockAPI: lockrecord: {}", returnJson); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 600 | asyncResp->res.jsonValue["Record"] = returnJson; |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 601 | } |
| 602 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 603 | inline void |
| 604 | handleGetLockListAPI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 605 | const ListOfSessionIds& listSessionIds) |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 606 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 607 | BMCWEB_LOG_DEBUG("{}", listSessionIds.size()); |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 608 | |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 609 | auto status = |
| 610 | crow::ibm_mc_lock::Lock::getInstance().getLockList(listSessionIds); |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 611 | auto var = std::get<std::vector<std::pair<uint32_t, LockRequests>>>(status); |
| 612 | |
| 613 | nlohmann::json lockRecords = nlohmann::json::array(); |
| 614 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 615 | for (const auto& transactionId : var) |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 616 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 617 | for (const auto& lockRecord : transactionId.second) |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 618 | { |
| 619 | nlohmann::json returnJson; |
| 620 | |
| 621 | returnJson["TransactionID"] = transactionId.first; |
| 622 | returnJson["SessionID"] = std::get<0>(lockRecord); |
| 623 | returnJson["HMCID"] = std::get<1>(lockRecord); |
| 624 | returnJson["LockType"] = std::get<2>(lockRecord); |
| 625 | returnJson["ResourceID"] = std::get<3>(lockRecord); |
| 626 | |
| 627 | nlohmann::json segments; |
| 628 | nlohmann::json segmentInfoArray = nlohmann::json::array(); |
| 629 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 630 | for (const auto& segment : std::get<4>(lockRecord)) |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 631 | { |
| 632 | segments["LockFlag"] = segment.first; |
| 633 | segments["SegmentLength"] = segment.second; |
| 634 | segmentInfoArray.push_back(segments); |
| 635 | } |
| 636 | |
| 637 | returnJson["SegmentFlags"] = segmentInfoArray; |
| 638 | lockRecords.push_back(returnJson); |
| 639 | } |
| 640 | } |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 641 | asyncResp->res.result(boost::beast::http::status::ok); |
| 642 | asyncResp->res.jsonValue["Records"] = lockRecords; |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 643 | } |
| 644 | |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 645 | inline bool isValidConfigFileName(const std::string& fileName, |
| 646 | crow::Response& res) |
| 647 | { |
| 648 | if (fileName.empty()) |
| 649 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 650 | BMCWEB_LOG_ERROR("Empty filename"); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 651 | res.jsonValue["Description"] = "Empty file path in the url"; |
| 652 | return false; |
| 653 | } |
| 654 | |
| 655 | // ConfigFile name is allowed to take upper and lowercase letters, |
| 656 | // numbers and hyphen |
| 657 | std::size_t found = fileName.find_first_not_of( |
| 658 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-"); |
| 659 | if (found != std::string::npos) |
| 660 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 661 | BMCWEB_LOG_ERROR("Unsupported character in filename: {}", fileName); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 662 | res.jsonValue["Description"] = "Unsupported character in filename"; |
| 663 | return false; |
| 664 | } |
| 665 | |
| 666 | // Check the filename length |
| 667 | if (fileName.length() > 20) |
| 668 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 669 | BMCWEB_LOG_ERROR("Name must be maximum 20 characters. " |
| 670 | "Input filename length is: {}", |
| 671 | fileName.length()); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 672 | res.jsonValue["Description"] = "Filename must be maximum 20 characters"; |
| 673 | return false; |
| 674 | } |
| 675 | |
| 676 | return true; |
| 677 | } |
| 678 | |
Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 679 | inline void requestRoutes(App& app) |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 680 | { |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 681 | // allowed only for admin |
| 682 | BMCWEB_ROUTE(app, "/ibm/v1/") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 683 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 684 | .methods(boost::beast::http::verb::get)( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 685 | [](const crow::Request&, |
| 686 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 687 | asyncResp->res.jsonValue["@odata.type"] = |
| 688 | "#ibmServiceRoot.v1_0_0.ibmServiceRoot"; |
| 689 | asyncResp->res.jsonValue["@odata.id"] = "/ibm/v1/"; |
| 690 | asyncResp->res.jsonValue["Id"] = "IBM Rest RootService"; |
| 691 | asyncResp->res.jsonValue["Name"] = "IBM Service Root"; |
| 692 | asyncResp->res.jsonValue["ConfigFiles"]["@odata.id"] = |
| 693 | "/ibm/v1/Host/ConfigFiles"; |
| 694 | asyncResp->res.jsonValue["LockService"]["@odata.id"] = |
| 695 | "/ibm/v1/HMC/LockService"; |
| 696 | asyncResp->res.jsonValue["BroadcastService"]["@odata.id"] = |
| 697 | "/ibm/v1/HMC/BroadcastService"; |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 698 | }); |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 699 | |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 700 | BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 701 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 702 | .methods(boost::beast::http::verb::get)( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 703 | [](const crow::Request&, |
| 704 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 705 | handleConfigFileList(asyncResp); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 706 | }); |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 707 | |
| 708 | BMCWEB_ROUTE(app, |
Sunitha Harish | e56f254 | 2020-07-22 02:38:59 -0500 | [diff] [blame] | 709 | "/ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 710 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 711 | .methods(boost::beast::http::verb::post)( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 712 | [](const crow::Request&, |
| 713 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 714 | deleteConfigFiles(asyncResp); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 715 | }); |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 716 | |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 717 | BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles/<str>") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 718 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 719 | .methods(boost::beast::http::verb::put, boost::beast::http::verb::get, |
| 720 | boost::beast::http::verb::delete_)( |
| 721 | [](const crow::Request& req, |
| 722 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 723 | const std::string& fileName) { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 724 | BMCWEB_LOG_DEBUG("ConfigFile : {}", fileName); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 725 | // Validate the incoming fileName |
| 726 | if (!isValidConfigFileName(fileName, asyncResp->res)) |
| 727 | { |
| 728 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 729 | return; |
| 730 | } |
| 731 | handleFileUrl(req, asyncResp, fileName); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 732 | }); |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 733 | |
| 734 | BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 735 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 736 | .methods(boost::beast::http::verb::get)( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 737 | [](const crow::Request&, |
| 738 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 739 | getLockServiceData(asyncResp); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 740 | }); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 741 | |
| 742 | BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.AcquireLock") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 743 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 744 | .methods(boost::beast::http::verb::post)( |
| 745 | [](const crow::Request& req, |
| 746 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 747 | std::vector<nlohmann::json> body; |
| 748 | if (!redfish::json_util::readJsonAction(req, asyncResp->res, "Request", |
| 749 | body)) |
| 750 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 751 | BMCWEB_LOG_DEBUG("Not a Valid JSON"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 752 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 753 | return; |
| 754 | } |
| 755 | handleAcquireLockAPI(req, asyncResp, body); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 756 | }); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 757 | BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 758 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 759 | .methods(boost::beast::http::verb::post)( |
| 760 | [](const crow::Request& req, |
| 761 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 762 | std::string type; |
| 763 | std::vector<uint32_t> listTransactionIds; |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 764 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 765 | if (!redfish::json_util::readJsonPatch(req, asyncResp->res, "Type", |
| 766 | type, "TransactionIDs", |
| 767 | listTransactionIds)) |
| 768 | { |
| 769 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 770 | return; |
| 771 | } |
| 772 | if (type == "Transaction") |
| 773 | { |
| 774 | handleReleaseLockAPI(req, asyncResp, listTransactionIds); |
| 775 | } |
| 776 | else if (type == "Session") |
| 777 | { |
| 778 | handleRelaseAllAPI(req, asyncResp); |
| 779 | } |
| 780 | else |
| 781 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 782 | BMCWEB_LOG_DEBUG(" Value of Type : {}is Not a Valid key", type); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 783 | redfish::messages::propertyValueNotInList(asyncResp->res, type, |
| 784 | "Type"); |
| 785 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 786 | }); |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 787 | BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.GetLockList") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 788 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 789 | .methods(boost::beast::http::verb::post)( |
| 790 | [](const crow::Request& req, |
| 791 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 792 | ListOfSessionIds listSessionIds; |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 793 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 794 | if (!redfish::json_util::readJsonPatch(req, asyncResp->res, |
| 795 | "SessionIDs", listSessionIds)) |
| 796 | { |
| 797 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 798 | return; |
| 799 | } |
| 800 | handleGetLockListAPI(asyncResp, listSessionIds); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 801 | }); |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 802 | |
| 803 | BMCWEB_ROUTE(app, "/ibm/v1/HMC/BroadcastService") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 804 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 805 | .methods(boost::beast::http::verb::post)( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 806 | [](const crow::Request& req, |
| 807 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 808 | handleBroadcastService(req, asyncResp); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 809 | }); |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | } // namespace ibm_mc |
| 813 | } // namespace crow |