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 | // Push an event |
| 217 | if (fileExists) |
| 218 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 219 | BMCWEB_LOG_DEBUG("config file is updated"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 220 | asyncResp->res.jsonValue["Description"] = "File Updated"; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 221 | } |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 222 | else |
| 223 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 224 | BMCWEB_LOG_DEBUG("config file is created"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 225 | asyncResp->res.jsonValue["Description"] = "File Created"; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 226 | } |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 227 | } |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 228 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 229 | inline void |
| 230 | handleConfigFileList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 231 | { |
| 232 | std::vector<std::string> pathObjList; |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 233 | std::filesystem::path loc( |
| 234 | "/var/lib/bmcweb/ibm-management-console/configfiles"); |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 235 | if (std::filesystem::exists(loc) && std::filesystem::is_directory(loc)) |
| 236 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 237 | for (const auto& file : std::filesystem::directory_iterator(loc)) |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 238 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 239 | const std::filesystem::path& pathObj = file.path(); |
cm-jishnu | 5a19396 | 2022-12-02 03:45:27 -0600 | [diff] [blame] | 240 | if (std::filesystem::is_regular_file(pathObj)) |
| 241 | { |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 242 | pathObjList.emplace_back("/ibm/v1/Host/ConfigFiles/" + |
| 243 | pathObj.filename().string()); |
cm-jishnu | 5a19396 | 2022-12-02 03:45:27 -0600 | [diff] [blame] | 244 | } |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 245 | } |
| 246 | } |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 247 | asyncResp->res.jsonValue["@odata.type"] = |
| 248 | "#IBMConfigFile.v1_0_0.IBMConfigFile"; |
| 249 | asyncResp->res.jsonValue["@odata.id"] = "/ibm/v1/Host/ConfigFiles/"; |
| 250 | asyncResp->res.jsonValue["Id"] = "ConfigFiles"; |
| 251 | asyncResp->res.jsonValue["Name"] = "ConfigFiles"; |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 252 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 253 | asyncResp->res.jsonValue["Members"] = std::move(pathObjList); |
| 254 | asyncResp->res.jsonValue["Actions"]["#IBMConfigFiles.DeleteAll"] = { |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 255 | {"target", |
Sunitha Harish | e56f254 | 2020-07-22 02:38:59 -0500 | [diff] [blame] | 256 | "/ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll"}}; |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 257 | } |
| 258 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 259 | inline void |
| 260 | deleteConfigFiles(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 261 | { |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 262 | std::error_code ec; |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 263 | std::filesystem::path loc( |
| 264 | "/var/lib/bmcweb/ibm-management-console/configfiles"); |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 265 | if (std::filesystem::exists(loc) && std::filesystem::is_directory(loc)) |
| 266 | { |
| 267 | std::filesystem::remove_all(loc, ec); |
| 268 | if (ec) |
| 269 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 270 | asyncResp->res.result( |
| 271 | boost::beast::http::status::internal_server_error); |
| 272 | asyncResp->res.jsonValue["Description"] = internalServerError; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 273 | BMCWEB_LOG_DEBUG("deleteConfigFiles: Failed to delete the " |
| 274 | "config files directory. ec : {}", |
| 275 | ec.message()); |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 276 | } |
| 277 | } |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 278 | } |
| 279 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 280 | inline void |
| 281 | getLockServiceData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 282 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 283 | asyncResp->res.jsonValue["@odata.type"] = "#LockService.v1_0_0.LockService"; |
| 284 | asyncResp->res.jsonValue["@odata.id"] = "/ibm/v1/HMC/LockService/"; |
| 285 | asyncResp->res.jsonValue["Id"] = "LockService"; |
| 286 | asyncResp->res.jsonValue["Name"] = "LockService"; |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 287 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 288 | asyncResp->res.jsonValue["Actions"]["#LockService.AcquireLock"] = { |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 289 | {"target", "/ibm/v1/HMC/LockService/Actions/LockService.AcquireLock"}}; |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 290 | asyncResp->res.jsonValue["Actions"]["#LockService.ReleaseLock"] = { |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 291 | {"target", "/ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock"}}; |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 292 | asyncResp->res.jsonValue["Actions"]["#LockService.GetLockList"] = { |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 293 | {"target", "/ibm/v1/HMC/LockService/Actions/LockService.GetLockList"}}; |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 294 | } |
| 295 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 296 | inline void handleFileGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 297 | const std::string& fileID) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 298 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 299 | BMCWEB_LOG_DEBUG("HandleGet on SaveArea files on path: {}", fileID); |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 300 | std::filesystem::path loc( |
| 301 | "/var/lib/bmcweb/ibm-management-console/configfiles/" + fileID); |
cm-jishnu | 5a19396 | 2022-12-02 03:45:27 -0600 | [diff] [blame] | 302 | if (!std::filesystem::exists(loc) || !std::filesystem::is_regular_file(loc)) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 303 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 304 | BMCWEB_LOG_WARNING("{} Not found", loc.string()); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 305 | asyncResp->res.result(boost::beast::http::status::not_found); |
| 306 | asyncResp->res.jsonValue["Description"] = resourceNotFoundMsg; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 307 | return; |
| 308 | } |
| 309 | |
| 310 | std::ifstream readfile(loc.string()); |
| 311 | if (!readfile) |
| 312 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 313 | BMCWEB_LOG_WARNING("{} Not found", loc.string()); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 314 | asyncResp->res.result(boost::beast::http::status::not_found); |
| 315 | asyncResp->res.jsonValue["Description"] = resourceNotFoundMsg; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 316 | return; |
| 317 | } |
| 318 | |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 319 | std::string contentDispositionParam = "attachment; filename=\"" + fileID + |
| 320 | "\""; |
Ed Tanous | d9f6c62 | 2022-03-17 09:12:17 -0700 | [diff] [blame] | 321 | asyncResp->res.addHeader(boost::beast::http::field::content_disposition, |
| 322 | contentDispositionParam); |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 323 | std::string fileData; |
| 324 | fileData = {std::istreambuf_iterator<char>(readfile), |
| 325 | std::istreambuf_iterator<char>()}; |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 326 | asyncResp->res.jsonValue["Data"] = fileData; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 329 | inline void |
| 330 | handleFileDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 331 | const std::string& fileID) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 332 | { |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 333 | std::string filePath("/var/lib/bmcweb/ibm-management-console/configfiles/" + |
| 334 | fileID); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 335 | BMCWEB_LOG_DEBUG("Removing the file : {}", filePath); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 336 | std::ifstream fileOpen(filePath.c_str()); |
| 337 | if (static_cast<bool>(fileOpen)) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 338 | { |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 339 | if (remove(filePath.c_str()) == 0) |
| 340 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 341 | BMCWEB_LOG_DEBUG("File removed!"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 342 | asyncResp->res.jsonValue["Description"] = "File Deleted"; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 343 | } |
| 344 | else |
| 345 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 346 | BMCWEB_LOG_ERROR("File not removed!"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 347 | asyncResp->res.result( |
| 348 | boost::beast::http::status::internal_server_error); |
| 349 | asyncResp->res.jsonValue["Description"] = internalServerError; |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 350 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 351 | } |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 352 | else |
| 353 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 354 | BMCWEB_LOG_WARNING("File not found!"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 355 | asyncResp->res.result(boost::beast::http::status::not_found); |
| 356 | asyncResp->res.jsonValue["Description"] = resourceNotFoundMsg; |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 357 | } |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 358 | } |
| 359 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 360 | inline void |
| 361 | handleBroadcastService(const crow::Request& req, |
| 362 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 363 | { |
| 364 | std::string broadcastMsg; |
| 365 | |
Willy Tu | 15ed678 | 2021-12-14 11:03:16 -0800 | [diff] [blame] | 366 | if (!redfish::json_util::readJsonPatch(req, asyncResp->res, "Message", |
| 367 | broadcastMsg)) |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 368 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 369 | BMCWEB_LOG_DEBUG("Not a Valid JSON"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 370 | asyncResp->res.result(boost::beast::http::status::bad_request); |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 371 | return; |
| 372 | } |
| 373 | if (broadcastMsg.size() > maxBroadcastMsgSize) |
| 374 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 375 | BMCWEB_LOG_ERROR("Message size exceeds maximum allowed size[1KB]"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 376 | asyncResp->res.result(boost::beast::http::status::bad_request); |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 377 | return; |
| 378 | } |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 379 | } |
| 380 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 381 | inline void handleFileUrl(const crow::Request& req, |
| 382 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 383 | const std::string& fileID) |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 384 | { |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 385 | if (req.method() == boost::beast::http::verb::put) |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 386 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 387 | handleFilePut(req, asyncResp, fileID); |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 388 | return; |
| 389 | } |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 390 | if (req.method() == boost::beast::http::verb::get) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 391 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 392 | handleFileGet(asyncResp, fileID); |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 393 | return; |
| 394 | } |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 395 | if (req.method() == boost::beast::http::verb::delete_) |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 396 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 397 | handleFileDelete(asyncResp, fileID); |
asmithakarun | 1c7b07c | 2019-09-09 03:42:59 -0500 | [diff] [blame] | 398 | return; |
| 399 | } |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 400 | } |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 401 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 402 | inline void |
| 403 | handleAcquireLockAPI(const crow::Request& req, |
| 404 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 425e81c | 2024-03-06 17:39:13 -0800 | [diff] [blame] | 405 | std::vector<nlohmann::json::object_t> body) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 406 | { |
| 407 | LockRequests lockRequestStructure; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 408 | for (auto& element : body) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 409 | { |
| 410 | std::string lockType; |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 411 | uint64_t resourceId = 0; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 412 | |
| 413 | SegmentFlags segInfo; |
Ed Tanous | 425e81c | 2024-03-06 17:39:13 -0800 | [diff] [blame] | 414 | std::vector<nlohmann::json::object_t> segmentFlags; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 415 | |
Ed Tanous | 425e81c | 2024-03-06 17:39:13 -0800 | [diff] [blame] | 416 | if (!redfish::json_util::readJsonObject( |
| 417 | element, asyncResp->res, "LockType", lockType, "ResourceID", |
| 418 | resourceId, "SegmentFlags", segmentFlags)) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 419 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 420 | BMCWEB_LOG_DEBUG("Not a Valid JSON"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 421 | asyncResp->res.result(boost::beast::http::status::bad_request); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 422 | return; |
| 423 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 424 | BMCWEB_LOG_DEBUG("{}", lockType); |
| 425 | BMCWEB_LOG_DEBUG("{}", resourceId); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 426 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 427 | BMCWEB_LOG_DEBUG("Segment Flags are present"); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 428 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 429 | for (auto& e : segmentFlags) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 430 | { |
| 431 | std::string lockFlags; |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 432 | uint32_t segmentLength = 0; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 433 | |
Ed Tanous | 425e81c | 2024-03-06 17:39:13 -0800 | [diff] [blame] | 434 | if (!redfish::json_util::readJsonObject( |
| 435 | e, asyncResp->res, "LockFlag", lockFlags, "SegmentLength", |
| 436 | segmentLength)) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 437 | { |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 438 | asyncResp->res.result(boost::beast::http::status::bad_request); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 439 | return; |
| 440 | } |
| 441 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 442 | BMCWEB_LOG_DEBUG("Lockflag : {}", lockFlags); |
| 443 | BMCWEB_LOG_DEBUG("SegmentLength : {}", segmentLength); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 444 | |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 445 | segInfo.emplace_back(std::make_pair(lockFlags, segmentLength)); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 446 | } |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 447 | |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 448 | lockRequestStructure.emplace_back(make_tuple( |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 449 | req.session->uniqueId, req.session->clientId.value_or(""), lockType, |
| 450 | resourceId, segInfo)); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | // print lock request into journal |
| 454 | |
Ed Tanous | 4e08751 | 2020-09-28 18:41:25 -0700 | [diff] [blame] | 455 | for (auto& i : lockRequestStructure) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 456 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 457 | BMCWEB_LOG_DEBUG("{}", std::get<0>(i)); |
| 458 | BMCWEB_LOG_DEBUG("{}", std::get<1>(i)); |
| 459 | BMCWEB_LOG_DEBUG("{}", std::get<2>(i)); |
| 460 | BMCWEB_LOG_DEBUG("{}", std::get<3>(i)); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 461 | |
Ed Tanous | 4e08751 | 2020-09-28 18:41:25 -0700 | [diff] [blame] | 462 | for (const auto& p : std::get<4>(i)) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 463 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 464 | BMCWEB_LOG_DEBUG("{}, {}", p.first, p.second); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 468 | const LockRequests& t = lockRequestStructure; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 469 | |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 470 | auto varAcquireLock = crow::ibm_mc_lock::Lock::getInstance().acquireLock(t); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 471 | |
| 472 | if (varAcquireLock.first) |
| 473 | { |
| 474 | // Either validity failure of there is a conflict with itself |
| 475 | |
| 476 | auto validityStatus = |
| 477 | std::get<std::pair<bool, int>>(varAcquireLock.second); |
| 478 | |
| 479 | if ((!validityStatus.first) && (validityStatus.second == 0)) |
| 480 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 481 | BMCWEB_LOG_DEBUG("Not a Valid record"); |
| 482 | BMCWEB_LOG_DEBUG("Bad json in request"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 483 | asyncResp->res.result(boost::beast::http::status::bad_request); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 484 | return; |
| 485 | } |
| 486 | if (validityStatus.first && (validityStatus.second == 1)) |
| 487 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 488 | BMCWEB_LOG_ERROR("There is a conflict within itself"); |
Sunitha Harish | f8a4347 | 2022-08-08 02:07:12 -0500 | [diff] [blame] | 489 | asyncResp->res.result(boost::beast::http::status::conflict); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 490 | return; |
| 491 | } |
| 492 | } |
| 493 | else |
| 494 | { |
| 495 | auto conflictStatus = |
| 496 | std::get<crow::ibm_mc_lock::Rc>(varAcquireLock.second); |
| 497 | if (!conflictStatus.first) |
| 498 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 499 | BMCWEB_LOG_DEBUG("There is no conflict with the locktable"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 500 | asyncResp->res.result(boost::beast::http::status::ok); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 501 | |
| 502 | auto var = std::get<uint32_t>(conflictStatus.second); |
| 503 | nlohmann::json returnJson; |
| 504 | returnJson["id"] = var; |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 505 | asyncResp->res.jsonValue["TransactionID"] = var; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 506 | return; |
| 507 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 508 | BMCWEB_LOG_DEBUG("There is a conflict with the lock table"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 509 | asyncResp->res.result(boost::beast::http::status::conflict); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 510 | auto var = |
| 511 | std::get<std::pair<uint32_t, LockRequest>>(conflictStatus.second); |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 512 | nlohmann::json returnJson; |
| 513 | nlohmann::json segments; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 514 | nlohmann::json myarray = nlohmann::json::array(); |
| 515 | returnJson["TransactionID"] = var.first; |
| 516 | returnJson["SessionID"] = std::get<0>(var.second); |
| 517 | returnJson["HMCID"] = std::get<1>(var.second); |
| 518 | returnJson["LockType"] = std::get<2>(var.second); |
| 519 | returnJson["ResourceID"] = std::get<3>(var.second); |
| 520 | |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 521 | for (const auto& i : std::get<4>(var.second)) |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 522 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 523 | segments["LockFlag"] = i.first; |
| 524 | segments["SegmentLength"] = i.second; |
| 525 | myarray.push_back(segments); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 526 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 527 | |
| 528 | returnJson["SegmentFlags"] = myarray; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 529 | BMCWEB_LOG_ERROR("Conflicting lock record: {}", returnJson); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 530 | asyncResp->res.jsonValue["Record"] = returnJson; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 531 | return; |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 532 | } |
| 533 | } |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 534 | inline void |
| 535 | handleRelaseAllAPI(const crow::Request& req, |
| 536 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Manojkiran Eda | 5bb0ece | 2020-01-20 20:22:36 +0530 | [diff] [blame] | 537 | { |
| 538 | crow::ibm_mc_lock::Lock::getInstance().releaseLock(req.session->uniqueId); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 539 | asyncResp->res.result(boost::beast::http::status::ok); |
Manojkiran Eda | 5bb0ece | 2020-01-20 20:22:36 +0530 | [diff] [blame] | 540 | } |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 541 | |
Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 542 | inline void |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 543 | handleReleaseLockAPI(const crow::Request& req, |
| 544 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 545 | const std::vector<uint32_t>& listTransactionIds) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 546 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 547 | BMCWEB_LOG_DEBUG("{}", listTransactionIds.size()); |
| 548 | BMCWEB_LOG_DEBUG("Data is present"); |
Ed Tanous | 4e08751 | 2020-09-28 18:41:25 -0700 | [diff] [blame] | 549 | for (unsigned int listTransactionId : listTransactionIds) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 550 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 551 | BMCWEB_LOG_DEBUG("{}", listTransactionId); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 552 | } |
| 553 | |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 554 | // validate the request ids |
| 555 | |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 556 | auto varReleaselock = crow::ibm_mc_lock::Lock::getInstance().releaseLock( |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 557 | listTransactionIds, std::make_pair(req.session->clientId.value_or(""), |
| 558 | req.session->uniqueId)); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 559 | |
| 560 | if (!varReleaselock.first) |
| 561 | { |
| 562 | // validation Failed |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 563 | BMCWEB_LOG_ERROR("handleReleaseLockAPI: validation failed"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 564 | asyncResp->res.result(boost::beast::http::status::bad_request); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 565 | return; |
| 566 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 567 | auto statusRelease = |
| 568 | std::get<crow::ibm_mc_lock::RcRelaseLock>(varReleaselock.second); |
| 569 | if (statusRelease.first) |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 570 | { |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 571 | // The current hmc owns all the locks, so we already released |
| 572 | // them |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 573 | return; |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 574 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 575 | |
| 576 | // valid rid, but the current hmc does not own all the locks |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 577 | BMCWEB_LOG_DEBUG("Current HMC does not own all the locks"); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 578 | asyncResp->res.result(boost::beast::http::status::unauthorized); |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 579 | |
| 580 | auto var = statusRelease.second; |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 581 | nlohmann::json returnJson; |
| 582 | nlohmann::json segments; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 583 | nlohmann::json myArray = nlohmann::json::array(); |
| 584 | returnJson["TransactionID"] = var.first; |
| 585 | returnJson["SessionID"] = std::get<0>(var.second); |
| 586 | returnJson["HMCID"] = std::get<1>(var.second); |
| 587 | returnJson["LockType"] = std::get<2>(var.second); |
| 588 | returnJson["ResourceID"] = std::get<3>(var.second); |
| 589 | |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 590 | for (const auto& i : std::get<4>(var.second)) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 591 | { |
| 592 | segments["LockFlag"] = i.first; |
| 593 | segments["SegmentLength"] = i.second; |
| 594 | myArray.push_back(segments); |
| 595 | } |
| 596 | |
| 597 | returnJson["SegmentFlags"] = myArray; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 598 | BMCWEB_LOG_DEBUG("handleReleaseLockAPI: lockrecord: {}", returnJson); |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 599 | asyncResp->res.jsonValue["Record"] = returnJson; |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 600 | } |
| 601 | |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 602 | inline void |
| 603 | handleGetLockListAPI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 604 | const ListOfSessionIds& listSessionIds) |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 605 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 606 | BMCWEB_LOG_DEBUG("{}", listSessionIds.size()); |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 607 | |
Ratan Gupta | 07386c6 | 2019-12-14 14:06:09 +0530 | [diff] [blame] | 608 | auto status = |
| 609 | crow::ibm_mc_lock::Lock::getInstance().getLockList(listSessionIds); |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 610 | auto var = std::get<std::vector<std::pair<uint32_t, LockRequests>>>(status); |
| 611 | |
| 612 | nlohmann::json lockRecords = nlohmann::json::array(); |
| 613 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 614 | for (const auto& transactionId : var) |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 615 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 616 | for (const auto& lockRecord : transactionId.second) |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 617 | { |
| 618 | nlohmann::json returnJson; |
| 619 | |
| 620 | returnJson["TransactionID"] = transactionId.first; |
| 621 | returnJson["SessionID"] = std::get<0>(lockRecord); |
| 622 | returnJson["HMCID"] = std::get<1>(lockRecord); |
| 623 | returnJson["LockType"] = std::get<2>(lockRecord); |
| 624 | returnJson["ResourceID"] = std::get<3>(lockRecord); |
| 625 | |
| 626 | nlohmann::json segments; |
| 627 | nlohmann::json segmentInfoArray = nlohmann::json::array(); |
| 628 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 629 | for (const auto& segment : std::get<4>(lockRecord)) |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 630 | { |
| 631 | segments["LockFlag"] = segment.first; |
| 632 | segments["SegmentLength"] = segment.second; |
| 633 | segmentInfoArray.push_back(segments); |
| 634 | } |
| 635 | |
| 636 | returnJson["SegmentFlags"] = segmentInfoArray; |
| 637 | lockRecords.push_back(returnJson); |
| 638 | } |
| 639 | } |
Sunitha Harish | db81c07 | 2021-01-21 23:33:21 -0600 | [diff] [blame] | 640 | asyncResp->res.result(boost::beast::http::status::ok); |
| 641 | asyncResp->res.jsonValue["Records"] = lockRecords; |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 642 | } |
| 643 | |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 644 | inline bool isValidConfigFileName(const std::string& fileName, |
| 645 | crow::Response& res) |
| 646 | { |
| 647 | if (fileName.empty()) |
| 648 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 649 | BMCWEB_LOG_ERROR("Empty filename"); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 650 | res.jsonValue["Description"] = "Empty file path in the url"; |
| 651 | return false; |
| 652 | } |
| 653 | |
| 654 | // ConfigFile name is allowed to take upper and lowercase letters, |
| 655 | // numbers and hyphen |
| 656 | std::size_t found = fileName.find_first_not_of( |
| 657 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-"); |
| 658 | if (found != std::string::npos) |
| 659 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 660 | BMCWEB_LOG_ERROR("Unsupported character in filename: {}", fileName); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 661 | res.jsonValue["Description"] = "Unsupported character in filename"; |
| 662 | return false; |
| 663 | } |
| 664 | |
| 665 | // Check the filename length |
| 666 | if (fileName.length() > 20) |
| 667 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 668 | BMCWEB_LOG_ERROR("Name must be maximum 20 characters. " |
| 669 | "Input filename length is: {}", |
| 670 | fileName.length()); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 671 | res.jsonValue["Description"] = "Filename must be maximum 20 characters"; |
| 672 | return false; |
| 673 | } |
| 674 | |
| 675 | return true; |
| 676 | } |
| 677 | |
Ed Tanous | 02379d3 | 2020-09-15 21:15:44 -0700 | [diff] [blame] | 678 | inline void requestRoutes(App& app) |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 679 | { |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 680 | // allowed only for admin |
| 681 | BMCWEB_ROUTE(app, "/ibm/v1/") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 682 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 683 | .methods(boost::beast::http::verb::get)( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 684 | [](const crow::Request&, |
| 685 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 686 | asyncResp->res.jsonValue["@odata.type"] = |
| 687 | "#ibmServiceRoot.v1_0_0.ibmServiceRoot"; |
| 688 | asyncResp->res.jsonValue["@odata.id"] = "/ibm/v1/"; |
| 689 | asyncResp->res.jsonValue["Id"] = "IBM Rest RootService"; |
| 690 | asyncResp->res.jsonValue["Name"] = "IBM Service Root"; |
| 691 | asyncResp->res.jsonValue["ConfigFiles"]["@odata.id"] = |
| 692 | "/ibm/v1/Host/ConfigFiles"; |
| 693 | asyncResp->res.jsonValue["LockService"]["@odata.id"] = |
| 694 | "/ibm/v1/HMC/LockService"; |
| 695 | asyncResp->res.jsonValue["BroadcastService"]["@odata.id"] = |
| 696 | "/ibm/v1/HMC/BroadcastService"; |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 697 | }); |
Sunitha Harish | 97b0e43 | 2019-11-21 04:59:29 -0600 | [diff] [blame] | 698 | |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 699 | BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 700 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 701 | .methods(boost::beast::http::verb::get)( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 702 | [](const crow::Request&, |
| 703 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 704 | handleConfigFileList(asyncResp); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 705 | }); |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 706 | |
| 707 | BMCWEB_ROUTE(app, |
Sunitha Harish | e56f254 | 2020-07-22 02:38:59 -0500 | [diff] [blame] | 708 | "/ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 709 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 710 | .methods(boost::beast::http::verb::post)( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 711 | [](const crow::Request&, |
| 712 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 713 | deleteConfigFiles(asyncResp); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 714 | }); |
Ratan Gupta | d3630cb | 2019-12-14 11:21:35 +0530 | [diff] [blame] | 715 | |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 716 | BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles/<str>") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 717 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 718 | .methods(boost::beast::http::verb::put, boost::beast::http::verb::get, |
| 719 | boost::beast::http::verb::delete_)( |
| 720 | [](const crow::Request& req, |
| 721 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 722 | const std::string& fileName) { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 723 | BMCWEB_LOG_DEBUG("ConfigFile : {}", fileName); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 724 | // Validate the incoming fileName |
| 725 | if (!isValidConfigFileName(fileName, asyncResp->res)) |
| 726 | { |
| 727 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 728 | return; |
| 729 | } |
| 730 | handleFileUrl(req, asyncResp, fileName); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 731 | }); |
Ratan Gupta | 734a1c3 | 2019-12-14 11:53:48 +0530 | [diff] [blame] | 732 | |
| 733 | BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 734 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
Ed Tanous | b41187f | 2019-10-24 16:30:02 -0700 | [diff] [blame] | 735 | .methods(boost::beast::http::verb::get)( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 736 | [](const crow::Request&, |
| 737 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 738 | getLockServiceData(asyncResp); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 739 | }); |
manojkiraneda | 0b631ae | 2019-12-03 17:54:28 +0530 | [diff] [blame] | 740 | |
| 741 | BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.AcquireLock") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 742 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 743 | .methods(boost::beast::http::verb::post)( |
| 744 | [](const crow::Request& req, |
| 745 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 425e81c | 2024-03-06 17:39:13 -0800 | [diff] [blame] | 746 | std::vector<nlohmann::json::object_t> body; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 747 | if (!redfish::json_util::readJsonAction(req, asyncResp->res, "Request", |
| 748 | body)) |
| 749 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 750 | BMCWEB_LOG_DEBUG("Not a Valid JSON"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 751 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 752 | return; |
| 753 | } |
| 754 | handleAcquireLockAPI(req, asyncResp, body); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 755 | }); |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 756 | BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 757 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 758 | .methods(boost::beast::http::verb::post)( |
| 759 | [](const crow::Request& req, |
| 760 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 761 | std::string type; |
| 762 | std::vector<uint32_t> listTransactionIds; |
manojkiraneda | 3b6dea6 | 2019-12-13 17:05:36 +0530 | [diff] [blame] | 763 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 764 | if (!redfish::json_util::readJsonPatch(req, asyncResp->res, "Type", |
| 765 | type, "TransactionIDs", |
| 766 | listTransactionIds)) |
| 767 | { |
| 768 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 769 | return; |
| 770 | } |
| 771 | if (type == "Transaction") |
| 772 | { |
| 773 | handleReleaseLockAPI(req, asyncResp, listTransactionIds); |
| 774 | } |
| 775 | else if (type == "Session") |
| 776 | { |
| 777 | handleRelaseAllAPI(req, asyncResp); |
| 778 | } |
| 779 | else |
| 780 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 781 | BMCWEB_LOG_DEBUG(" Value of Type : {}is Not a Valid key", type); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 782 | redfish::messages::propertyValueNotInList(asyncResp->res, type, |
| 783 | "Type"); |
| 784 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 785 | }); |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 786 | BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.GetLockList") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 787 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 788 | .methods(boost::beast::http::verb::post)( |
| 789 | [](const crow::Request& req, |
| 790 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 791 | ListOfSessionIds listSessionIds; |
manojkiraneda | 402b571 | 2019-12-13 17:07:09 +0530 | [diff] [blame] | 792 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 793 | if (!redfish::json_util::readJsonPatch(req, asyncResp->res, |
| 794 | "SessionIDs", listSessionIds)) |
| 795 | { |
| 796 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 797 | return; |
| 798 | } |
| 799 | handleGetLockListAPI(asyncResp, listSessionIds); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 800 | }); |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 801 | |
| 802 | BMCWEB_ROUTE(app, "/ibm/v1/HMC/BroadcastService") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame] | 803 | .privileges({{"ConfigureComponents", "ConfigureManager"}}) |
Asmitha Karunanithi | 5738de5 | 2020-07-17 02:03:31 -0500 | [diff] [blame] | 804 | .methods(boost::beast::http::verb::post)( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 805 | [](const crow::Request& req, |
| 806 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 807 | handleBroadcastService(req, asyncResp); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 808 | }); |
Ratan Gupta | 453fed0 | 2019-12-14 09:39:47 +0530 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | } // namespace ibm_mc |
| 812 | } // namespace crow |