Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "account_service.hpp" |
| 19 | #include "app.hpp" |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 20 | #include "async_resp.hpp" |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 21 | #include "dbus_utility.hpp" |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 22 | #include "generated/enums/virtual_media.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 23 | #include "query.hpp" |
| 24 | #include "registries/privilege_registry.hpp" |
| 25 | #include "utils/json_utils.hpp" |
| 26 | |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 27 | #include <boost/process/async_pipe.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame^] | 28 | #include <boost/url/format.hpp> |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 29 | #include <boost/url/url_view.hpp> |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 30 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 31 | #include <array> |
| 32 | #include <string_view> |
| 33 | |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 34 | namespace redfish |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 35 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 36 | |
| 37 | enum class VmMode |
| 38 | { |
| 39 | Invalid, |
| 40 | Legacy, |
| 41 | Proxy |
| 42 | }; |
| 43 | |
| 44 | inline VmMode |
| 45 | parseObjectPathAndGetMode(const sdbusplus::message::object_path& itemPath, |
| 46 | const std::string& resName) |
| 47 | { |
| 48 | std::string thisPath = itemPath.filename(); |
| 49 | BMCWEB_LOG_DEBUG << "Filename: " << itemPath.str |
| 50 | << ", ThisPath: " << thisPath; |
| 51 | |
| 52 | if (thisPath.empty()) |
| 53 | { |
| 54 | return VmMode::Invalid; |
| 55 | } |
| 56 | |
| 57 | if (thisPath != resName) |
| 58 | { |
| 59 | return VmMode::Invalid; |
| 60 | } |
| 61 | |
| 62 | auto mode = itemPath.parent_path(); |
| 63 | auto type = mode.parent_path(); |
| 64 | |
| 65 | if (mode.filename().empty() || type.filename().empty()) |
| 66 | { |
| 67 | return VmMode::Invalid; |
| 68 | } |
| 69 | |
| 70 | if (type.filename() != "VirtualMedia") |
| 71 | { |
| 72 | return VmMode::Invalid; |
| 73 | } |
| 74 | std::string modeStr = mode.filename(); |
| 75 | if (modeStr == "Legacy") |
| 76 | { |
| 77 | return VmMode::Legacy; |
| 78 | } |
| 79 | if (modeStr == "Proxy") |
| 80 | { |
| 81 | return VmMode::Proxy; |
| 82 | } |
| 83 | return VmMode::Invalid; |
| 84 | } |
| 85 | |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 86 | using CheckItemHandler = |
| 87 | std::function<void(const std::string& service, const std::string& resName, |
| 88 | const std::shared_ptr<bmcweb::AsyncResp>&, |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 89 | const std::pair<sdbusplus::message::object_path, |
| 90 | dbus::utility::DBusInteracesMap>&)>; |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 91 | |
| 92 | inline void findAndParseObject(const std::string& service, |
| 93 | const std::string& resName, |
| 94 | const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
| 95 | CheckItemHandler&& handler) |
| 96 | { |
| 97 | crow::connections::systemBus->async_method_call( |
| 98 | [service, resName, aResp, |
Lakshmi Yadlapati | 746c5b8 | 2023-03-06 16:07:28 -0600 | [diff] [blame] | 99 | handler](const boost::system::error_code& ec, |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 100 | const dbus::utility::ManagedObjectType& subtree) { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 101 | if (ec) |
| 102 | { |
| 103 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 104 | |
| 105 | return; |
| 106 | } |
| 107 | |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 108 | for (const auto& item : subtree) |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 109 | { |
| 110 | VmMode mode = parseObjectPathAndGetMode(item.first, resName); |
| 111 | if (mode != VmMode::Invalid) |
| 112 | { |
| 113 | handler(service, resName, aResp, item); |
| 114 | return; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | BMCWEB_LOG_DEBUG << "Parent item not found"; |
| 119 | aResp->res.result(boost::beast::http::status::not_found); |
| 120 | }, |
| 121 | service, "/xyz/openbmc_project/VirtualMedia", |
| 122 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
| 123 | } |
| 124 | |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 125 | /** |
| 126 | * @brief Function extracts transfer protocol name from URI. |
| 127 | */ |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 128 | inline std::string getTransferProtocolTypeFromUri(const std::string& imageUri) |
| 129 | { |
| 130 | boost::urls::result<boost::urls::url_view> url = |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 131 | boost::urls::parse_uri(imageUri); |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 132 | if (!url) |
| 133 | { |
| 134 | return "None"; |
| 135 | } |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 136 | std::string_view scheme = url->scheme(); |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 137 | if (scheme == "smb") |
| 138 | { |
| 139 | return "CIFS"; |
| 140 | } |
| 141 | if (scheme == "https") |
| 142 | { |
| 143 | return "HTTPS"; |
| 144 | } |
| 145 | |
| 146 | return "None"; |
| 147 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * @brief Read all known properties from VM object interfaces |
| 151 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 152 | inline void |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 153 | vmParseInterfaceObject(const dbus::utility::DBusInteracesMap& interfaces, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 154 | const std::shared_ptr<bmcweb::AsyncResp>& aResp) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 155 | { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 156 | for (const auto& [interface, values] : interfaces) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 157 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 158 | if (interface == "xyz.openbmc_project.VirtualMedia.MountPoint") |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 159 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 160 | for (const auto& [property, value] : values) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 161 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 162 | if (property == "EndpointId") |
| 163 | { |
| 164 | const std::string* endpointIdValue = |
| 165 | std::get_if<std::string>(&value); |
| 166 | if (endpointIdValue == nullptr) |
| 167 | { |
| 168 | continue; |
| 169 | } |
| 170 | if (!endpointIdValue->empty()) |
| 171 | { |
| 172 | // Proxy mode |
| 173 | aResp->res |
| 174 | .jsonValue["Oem"]["OpenBMC"]["WebSocketEndpoint"] = |
| 175 | *endpointIdValue; |
| 176 | aResp->res.jsonValue["TransferProtocolType"] = "OEM"; |
| 177 | } |
| 178 | } |
| 179 | if (property == "ImageURL") |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 180 | { |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 181 | const std::string* imageUrlValue = |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 182 | std::get_if<std::string>(&value); |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 183 | if (imageUrlValue != nullptr && !imageUrlValue->empty()) |
Przemyslaw Czarnowski | da4784d | 2020-11-06 09:58:25 +0100 | [diff] [blame] | 184 | { |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 185 | std::filesystem::path filePath = *imageUrlValue; |
| 186 | if (!filePath.has_filename()) |
| 187 | { |
| 188 | // this will handle https share, which not |
| 189 | // necessarily has to have filename given. |
| 190 | aResp->res.jsonValue["ImageName"] = ""; |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | aResp->res.jsonValue["ImageName"] = |
| 195 | filePath.filename(); |
| 196 | } |
Przemyslaw Czarnowski | da4784d | 2020-11-06 09:58:25 +0100 | [diff] [blame] | 197 | |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 198 | aResp->res.jsonValue["Image"] = *imageUrlValue; |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 199 | aResp->res.jsonValue["TransferProtocolType"] = |
| 200 | getTransferProtocolTypeFromUri(*imageUrlValue); |
| 201 | |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 202 | aResp->res.jsonValue["ConnectedVia"] = |
| 203 | virtual_media::ConnectedVia::URI; |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 204 | } |
| 205 | } |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 206 | if (property == "WriteProtected") |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 207 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 208 | const bool* writeProtectedValue = std::get_if<bool>(&value); |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 209 | if (writeProtectedValue != nullptr) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 210 | { |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 211 | aResp->res.jsonValue["WriteProtected"] = |
| 212 | *writeProtectedValue; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | } |
| 216 | } |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 217 | if (interface == "xyz.openbmc_project.VirtualMedia.Process") |
| 218 | { |
| 219 | for (const auto& [property, value] : values) |
| 220 | { |
| 221 | if (property == "Active") |
| 222 | { |
| 223 | const bool* activeValue = std::get_if<bool>(&value); |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 224 | if (activeValue == nullptr) |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 225 | { |
| 226 | BMCWEB_LOG_DEBUG << "Value Active not found"; |
| 227 | return; |
| 228 | } |
| 229 | aResp->res.jsonValue["Inserted"] = *activeValue; |
| 230 | |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 231 | if (*activeValue) |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 232 | { |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 233 | aResp->res.jsonValue["ConnectedVia"] = |
| 234 | virtual_media::ConnectedVia::Applet; |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | } |
| 238 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * @brief Fill template for Virtual Media Item. |
| 244 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 245 | inline nlohmann::json vmItemTemplate(const std::string& name, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 246 | const std::string& resName) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 247 | { |
| 248 | nlohmann::json item; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame^] | 249 | item["@odata.id"] = boost::urls::format( |
| 250 | "/redfish/v1/Managers/{}/VirtualMedia/{}", name, resName); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 251 | |
Przemyslaw Czarnowski | d04ba32 | 2020-01-21 12:41:56 +0100 | [diff] [blame] | 252 | item["@odata.type"] = "#VirtualMedia.v1_3_0.VirtualMedia"; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 253 | item["Name"] = "Virtual Removable Media"; |
| 254 | item["Id"] = resName; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 255 | item["WriteProtected"] = true; |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 256 | item["ConnectedVia"] = virtual_media::ConnectedVia::NotConnected; |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 257 | item["MediaTypes"] = nlohmann::json::array_t({"CD", "USBStick"}); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 258 | item["TransferMethod"] = "Stream"; |
Przemyslaw Czarnowski | d04ba32 | 2020-01-21 12:41:56 +0100 | [diff] [blame] | 259 | item["Oem"]["OpenBMC"]["@odata.type"] = |
| 260 | "#OemVirtualMedia.v1_0_0.VirtualMedia"; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 261 | |
| 262 | return item; |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * @brief Fills collection data |
| 267 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 268 | inline void getVmResourceList(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 269 | const std::string& service, |
| 270 | const std::string& name) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 271 | { |
| 272 | BMCWEB_LOG_DEBUG << "Get available Virtual Media resources."; |
| 273 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 274 | [name, aResp{std::move(aResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 275 | const boost::system::error_code& ec, |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 276 | const dbus::utility::ManagedObjectType& subtree) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 277 | if (ec) |
| 278 | { |
| 279 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 280 | return; |
| 281 | } |
| 282 | nlohmann::json& members = aResp->res.jsonValue["Members"]; |
| 283 | members = nlohmann::json::array(); |
| 284 | |
| 285 | for (const auto& object : subtree) |
| 286 | { |
| 287 | nlohmann::json item; |
| 288 | std::string path = object.first.filename(); |
| 289 | if (path.empty()) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 290 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 291 | continue; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 292 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 293 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame^] | 294 | item["@odata.id"] = boost::urls::format( |
| 295 | "/redfish/v1/Managers/{}/VirtualMedia/{}", name, path); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 296 | members.emplace_back(std::move(item)); |
| 297 | } |
| 298 | aResp->res.jsonValue["Members@odata.count"] = members.size(); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 299 | }, |
| 300 | service, "/xyz/openbmc_project/VirtualMedia", |
| 301 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
| 302 | } |
| 303 | |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 304 | inline void |
| 305 | afterGetVmData(const std::string& name, const std::string& /*service*/, |
| 306 | const std::string& resName, |
| 307 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 308 | const std::pair<sdbusplus::message::object_path, |
| 309 | dbus::utility::DBusInteracesMap>& item) |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 310 | { |
| 311 | VmMode mode = parseObjectPathAndGetMode(item.first, resName); |
| 312 | if (mode == VmMode::Invalid) |
| 313 | { |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | asyncResp->res.jsonValue = vmItemTemplate(name, resName); |
| 318 | |
| 319 | // Check if dbus path is Legacy type |
| 320 | if (mode == VmMode::Legacy) |
| 321 | { |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame^] | 322 | asyncResp->res.jsonValue["Actions"]["#VirtualMedia.InsertMedia"] |
| 323 | ["target"] = boost::urls::format( |
| 324 | "/redfish/v1/Managers/{}/VirtualMedia/{}/Actions/VirtualMedia.InsertMedia", |
| 325 | name, resName); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | vmParseInterfaceObject(item.second, asyncResp); |
| 329 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame^] | 330 | asyncResp->res.jsonValue["Actions"]["#VirtualMedia.EjectMedia"] |
| 331 | ["target"] = boost::urls::format( |
| 332 | "/redfish/v1/Managers/{}/VirtualMedia/{}/Actions/VirtualMedia.EjectMedia", |
| 333 | name, resName); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 334 | } |
| 335 | |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 336 | /** |
| 337 | * @brief Fills data for specific resource |
| 338 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 339 | inline void getVmData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 340 | const std::string& service, const std::string& name, |
| 341 | const std::string& resName) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 342 | { |
| 343 | BMCWEB_LOG_DEBUG << "Get Virtual Media resource data."; |
| 344 | |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 345 | findAndParseObject(service, resName, aResp, |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 346 | std::bind_front(afterGetVmData, name)); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 347 | } |
| 348 | |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 349 | /** |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 350 | * @brief Transfer protocols supported for InsertMedia action. |
| 351 | * |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 352 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 353 | enum class TransferProtocol |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 354 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 355 | https, |
| 356 | smb, |
| 357 | invalid |
| 358 | }; |
| 359 | |
| 360 | /** |
| 361 | * @brief Function extracts transfer protocol type from URI. |
| 362 | * |
| 363 | */ |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 364 | inline std::optional<TransferProtocol> |
Ed Tanous | d9f466b | 2023-03-06 15:04:25 -0800 | [diff] [blame] | 365 | getTransferProtocolFromUri(boost::urls::url_view imageUri) |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 366 | { |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 367 | std::string_view scheme = imageUri.scheme(); |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 368 | if (scheme == "smb") |
| 369 | { |
| 370 | return TransferProtocol::smb; |
| 371 | } |
| 372 | if (scheme == "https") |
| 373 | { |
| 374 | return TransferProtocol::https; |
| 375 | } |
| 376 | if (!scheme.empty()) |
| 377 | { |
| 378 | return TransferProtocol::invalid; |
| 379 | } |
| 380 | |
| 381 | return {}; |
| 382 | } |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 383 | |
| 384 | /** |
| 385 | * @brief Function convert transfer protocol from string param. |
| 386 | * |
| 387 | */ |
| 388 | inline std::optional<TransferProtocol> getTransferProtocolFromParam( |
| 389 | const std::optional<std::string>& transferProtocolType) |
| 390 | { |
| 391 | if (transferProtocolType == std::nullopt) |
Agata Olender | c6f4e01 | 2020-03-11 15:19:07 +0100 | [diff] [blame] | 392 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 393 | return {}; |
Agata Olender | c6f4e01 | 2020-03-11 15:19:07 +0100 | [diff] [blame] | 394 | } |
| 395 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 396 | if (*transferProtocolType == "CIFS") |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 397 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 398 | return TransferProtocol::smb; |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 399 | } |
| 400 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 401 | if (*transferProtocolType == "HTTPS") |
| 402 | { |
| 403 | return TransferProtocol::https; |
| 404 | } |
| 405 | |
| 406 | return TransferProtocol::invalid; |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * @brief Function extends URI with transfer protocol type. |
| 411 | * |
| 412 | */ |
| 413 | inline std::string |
| 414 | getUriWithTransferProtocol(const std::string& imageUri, |
| 415 | const TransferProtocol& transferProtocol) |
| 416 | { |
| 417 | if (transferProtocol == TransferProtocol::smb) |
| 418 | { |
| 419 | return "smb://" + imageUri; |
| 420 | } |
| 421 | |
| 422 | if (transferProtocol == TransferProtocol::https) |
| 423 | { |
| 424 | return "https://" + imageUri; |
| 425 | } |
| 426 | |
| 427 | return imageUri; |
| 428 | } |
| 429 | |
Przemyslaw Czarnowski | 1f2a40c | 2022-06-24 13:47:08 +0200 | [diff] [blame] | 430 | struct InsertMediaActionParams |
| 431 | { |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 432 | std::optional<std::string> imageUrl; |
Przemyslaw Czarnowski | 1f2a40c | 2022-06-24 13:47:08 +0200 | [diff] [blame] | 433 | std::optional<std::string> userName; |
| 434 | std::optional<std::string> password; |
| 435 | std::optional<std::string> transferMethod; |
| 436 | std::optional<std::string> transferProtocolType; |
| 437 | std::optional<bool> writeProtected = true; |
| 438 | std::optional<bool> inserted; |
| 439 | }; |
| 440 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 441 | template <typename T> |
| 442 | static void secureCleanup(T& value) |
| 443 | { |
Ed Tanous | 4ecc618 | 2022-01-07 09:36:26 -0800 | [diff] [blame] | 444 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 445 | auto raw = const_cast<typename T::value_type*>(value.data()); |
| 446 | explicit_bzero(raw, value.size() * sizeof(*raw)); |
| 447 | } |
| 448 | |
| 449 | class Credentials |
| 450 | { |
| 451 | public: |
| 452 | Credentials(std::string&& user, std::string&& password) : |
| 453 | userBuf(std::move(user)), passBuf(std::move(password)) |
| 454 | {} |
| 455 | |
| 456 | ~Credentials() |
| 457 | { |
| 458 | secureCleanup(userBuf); |
| 459 | secureCleanup(passBuf); |
| 460 | } |
| 461 | |
| 462 | const std::string& user() |
| 463 | { |
| 464 | return userBuf; |
| 465 | } |
| 466 | |
| 467 | const std::string& password() |
| 468 | { |
| 469 | return passBuf; |
| 470 | } |
| 471 | |
| 472 | Credentials() = delete; |
| 473 | Credentials(const Credentials&) = delete; |
| 474 | Credentials& operator=(const Credentials&) = delete; |
Ed Tanous | ecd6a3a | 2022-01-07 09:18:40 -0800 | [diff] [blame] | 475 | Credentials(Credentials&&) = delete; |
| 476 | Credentials& operator=(Credentials&&) = delete; |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 477 | |
| 478 | private: |
| 479 | std::string userBuf; |
| 480 | std::string passBuf; |
| 481 | }; |
| 482 | |
| 483 | class CredentialsProvider |
| 484 | { |
| 485 | public: |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 486 | template <typename T> |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 487 | struct Deleter |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 488 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 489 | void operator()(T* buff) const |
| 490 | { |
| 491 | if (buff) |
| 492 | { |
| 493 | secureCleanup(*buff); |
| 494 | delete buff; |
| 495 | } |
| 496 | } |
| 497 | }; |
| 498 | |
| 499 | using Buffer = std::vector<char>; |
| 500 | using SecureBuffer = std::unique_ptr<Buffer, Deleter<Buffer>>; |
| 501 | // Using explicit definition instead of std::function to avoid implicit |
| 502 | // conversions eg. stack copy instead of reference |
| 503 | using FormatterFunc = void(const std::string& username, |
| 504 | const std::string& password, Buffer& dest); |
| 505 | |
| 506 | CredentialsProvider(std::string&& user, std::string&& password) : |
| 507 | credentials(std::move(user), std::move(password)) |
| 508 | {} |
| 509 | |
| 510 | const std::string& user() |
| 511 | { |
| 512 | return credentials.user(); |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 513 | } |
| 514 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 515 | const std::string& password() |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 516 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 517 | return credentials.password(); |
| 518 | } |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 519 | |
Ed Tanous | 1917ee9 | 2022-06-30 22:30:50 -0700 | [diff] [blame] | 520 | SecureBuffer pack(FormatterFunc* formatter) |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 521 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 522 | SecureBuffer packed{new Buffer{}}; |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 523 | if (formatter != nullptr) |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 524 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 525 | formatter(credentials.user(), credentials.password(), *packed); |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 528 | return packed; |
| 529 | } |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 530 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 531 | private: |
| 532 | Credentials credentials; |
| 533 | }; |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 534 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 535 | // Wrapper for boost::async_pipe ensuring proper pipe cleanup |
Ed Tanous | 0a48306 | 2022-07-11 10:18:50 -0700 | [diff] [blame] | 536 | class SecurePipe |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 537 | { |
| 538 | public: |
| 539 | using unix_fd = sdbusplus::message::unix_fd; |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 540 | |
Ed Tanous | 0a48306 | 2022-07-11 10:18:50 -0700 | [diff] [blame] | 541 | SecurePipe(boost::asio::io_context& io, |
| 542 | CredentialsProvider::SecureBuffer&& bufferIn) : |
| 543 | impl(io), |
| 544 | buffer{std::move(bufferIn)} |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 545 | {} |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 546 | |
Ed Tanous | 0a48306 | 2022-07-11 10:18:50 -0700 | [diff] [blame] | 547 | ~SecurePipe() |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 548 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 549 | // Named pipe needs to be explicitly removed |
| 550 | impl.close(); |
| 551 | } |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 552 | |
Ed Tanous | 0a48306 | 2022-07-11 10:18:50 -0700 | [diff] [blame] | 553 | SecurePipe(const SecurePipe&) = delete; |
| 554 | SecurePipe(SecurePipe&&) = delete; |
| 555 | SecurePipe& operator=(const SecurePipe&) = delete; |
| 556 | SecurePipe& operator=(SecurePipe&&) = delete; |
Ed Tanous | ecd6a3a | 2022-01-07 09:18:40 -0800 | [diff] [blame] | 557 | |
Ed Tanous | 0a48306 | 2022-07-11 10:18:50 -0700 | [diff] [blame] | 558 | unix_fd fd() const |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 559 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 560 | return unix_fd{impl.native_source()}; |
| 561 | } |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 562 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 563 | template <typename WriteHandler> |
| 564 | void asyncWrite(WriteHandler&& handler) |
| 565 | { |
Ed Tanous | 0a48306 | 2022-07-11 10:18:50 -0700 | [diff] [blame] | 566 | impl.async_write_some(boost::asio::buffer(*buffer), |
| 567 | std::forward<WriteHandler>(handler)); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | const std::string name; |
| 571 | boost::process::async_pipe impl; |
Ed Tanous | 0a48306 | 2022-07-11 10:18:50 -0700 | [diff] [blame] | 572 | CredentialsProvider::SecureBuffer buffer; |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 573 | }; |
| 574 | |
| 575 | /** |
| 576 | * @brief Function transceives data with dbus directly. |
| 577 | * |
| 578 | * All BMC state properties will be retrieved before sending reset request. |
| 579 | */ |
| 580 | inline void doMountVmLegacy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 581 | const std::string& service, const std::string& name, |
| 582 | const std::string& imageUrl, const bool rw, |
| 583 | std::string&& userName, std::string&& password) |
| 584 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 585 | constexpr const size_t secretLimit = 1024; |
| 586 | |
| 587 | std::shared_ptr<SecurePipe> secretPipe; |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 588 | dbus::utility::DbusVariantType unixFd = -1; |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 589 | |
| 590 | if (!userName.empty() || !password.empty()) |
| 591 | { |
| 592 | // Encapsulate in safe buffer |
| 593 | CredentialsProvider credentials(std::move(userName), |
| 594 | std::move(password)); |
| 595 | |
| 596 | // Payload must contain data + NULL delimiters |
| 597 | if (credentials.user().size() + credentials.password().size() + 2 > |
| 598 | secretLimit) |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 599 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 600 | BMCWEB_LOG_ERROR << "Credentials too long to handle"; |
| 601 | messages::unrecognizedRequestBody(asyncResp->res); |
| 602 | return; |
| 603 | } |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 604 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 605 | // Pack secret |
| 606 | auto secret = credentials.pack( |
| 607 | [](const auto& user, const auto& pass, auto& buff) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 608 | std::copy(user.begin(), user.end(), std::back_inserter(buff)); |
| 609 | buff.push_back('\0'); |
| 610 | std::copy(pass.begin(), pass.end(), std::back_inserter(buff)); |
| 611 | buff.push_back('\0'); |
| 612 | }); |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 613 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 614 | // Open pipe |
| 615 | secretPipe = std::make_shared<SecurePipe>( |
| 616 | crow::connections::systemBus->get_io_context(), std::move(secret)); |
| 617 | unixFd = secretPipe->fd(); |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 618 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 619 | // Pass secret over pipe |
| 620 | secretPipe->asyncWrite( |
| 621 | [asyncResp](const boost::system::error_code& ec, std::size_t) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 622 | if (ec) |
| 623 | { |
| 624 | BMCWEB_LOG_ERROR << "Failed to pass secret: " << ec; |
| 625 | messages::internalError(asyncResp->res); |
| 626 | } |
| 627 | }); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 628 | } |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 629 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 630 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 631 | [asyncResp, secretPipe](const boost::system::error_code& ec, |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 632 | bool success) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 633 | if (ec) |
| 634 | { |
| 635 | BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec; |
| 636 | messages::internalError(asyncResp->res); |
| 637 | } |
| 638 | else if (!success) |
| 639 | { |
| 640 | BMCWEB_LOG_ERROR << "Service responded with error"; |
| 641 | messages::generalError(asyncResp->res); |
| 642 | } |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 643 | }, |
| 644 | service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name, |
| 645 | "xyz.openbmc_project.VirtualMedia.Legacy", "Mount", imageUrl, rw, |
| 646 | unixFd); |
| 647 | } |
| 648 | |
| 649 | /** |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 650 | * @brief Function validate parameters of insert media request. |
| 651 | * |
| 652 | */ |
| 653 | inline void validateParams(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 654 | const std::string& service, |
| 655 | const std::string& resName, |
| 656 | InsertMediaActionParams& actionParams) |
| 657 | { |
| 658 | BMCWEB_LOG_DEBUG << "Validation started"; |
| 659 | // required param imageUrl must not be empty |
| 660 | if (!actionParams.imageUrl) |
| 661 | { |
| 662 | BMCWEB_LOG_ERROR << "Request action parameter Image is empty."; |
| 663 | |
| 664 | messages::propertyValueFormatError(asyncResp->res, "<empty>", "Image"); |
| 665 | |
| 666 | return; |
| 667 | } |
| 668 | |
| 669 | // optional param inserted must be true |
| 670 | if ((actionParams.inserted != std::nullopt) && !*actionParams.inserted) |
| 671 | { |
| 672 | BMCWEB_LOG_ERROR |
| 673 | << "Request action optional parameter Inserted must be true."; |
| 674 | |
| 675 | messages::actionParameterNotSupported(asyncResp->res, "Inserted", |
| 676 | "InsertMedia"); |
| 677 | |
| 678 | return; |
| 679 | } |
| 680 | |
| 681 | // optional param transferMethod must be stream |
| 682 | if ((actionParams.transferMethod != std::nullopt) && |
| 683 | (*actionParams.transferMethod != "Stream")) |
| 684 | { |
| 685 | BMCWEB_LOG_ERROR << "Request action optional parameter " |
| 686 | "TransferMethod must be Stream."; |
| 687 | |
| 688 | messages::actionParameterNotSupported(asyncResp->res, "TransferMethod", |
| 689 | "InsertMedia"); |
| 690 | |
| 691 | return; |
| 692 | } |
| 693 | boost::urls::result<boost::urls::url_view> url = |
| 694 | boost::urls::parse_uri(*actionParams.imageUrl); |
| 695 | if (!url) |
| 696 | { |
| 697 | messages::actionParameterValueFormatError( |
| 698 | asyncResp->res, *actionParams.imageUrl, "Image", "InsertMedia"); |
| 699 | return; |
| 700 | } |
| 701 | std::optional<TransferProtocol> uriTransferProtocolType = |
| 702 | getTransferProtocolFromUri(*url); |
| 703 | |
| 704 | std::optional<TransferProtocol> paramTransferProtocolType = |
| 705 | getTransferProtocolFromParam(actionParams.transferProtocolType); |
| 706 | |
| 707 | // ImageUrl does not contain valid protocol type |
| 708 | if (*uriTransferProtocolType == TransferProtocol::invalid) |
| 709 | { |
| 710 | BMCWEB_LOG_ERROR << "Request action parameter ImageUrl must " |
| 711 | "contain specified protocol type from list: " |
| 712 | "(smb, https)."; |
| 713 | |
| 714 | messages::resourceAtUriInUnknownFormat(asyncResp->res, *url); |
| 715 | |
| 716 | return; |
| 717 | } |
| 718 | |
| 719 | // transferProtocolType should contain value from list |
| 720 | if (*paramTransferProtocolType == TransferProtocol::invalid) |
| 721 | { |
| 722 | BMCWEB_LOG_ERROR << "Request action parameter TransferProtocolType " |
| 723 | "must be provided with value from list: " |
| 724 | "(CIFS, HTTPS)."; |
| 725 | |
| 726 | messages::propertyValueNotInList(asyncResp->res, |
| 727 | *actionParams.transferProtocolType, |
| 728 | "TransferProtocolType"); |
| 729 | return; |
| 730 | } |
| 731 | |
| 732 | // valid transfer protocol not provided either with URI nor param |
| 733 | if ((uriTransferProtocolType == std::nullopt) && |
| 734 | (paramTransferProtocolType == std::nullopt)) |
| 735 | { |
| 736 | BMCWEB_LOG_ERROR << "Request action parameter ImageUrl must " |
| 737 | "contain specified protocol type or param " |
| 738 | "TransferProtocolType must be provided."; |
| 739 | |
| 740 | messages::resourceAtUriInUnknownFormat(asyncResp->res, *url); |
| 741 | |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | // valid transfer protocol provided both with URI and param |
| 746 | if ((paramTransferProtocolType != std::nullopt) && |
| 747 | (uriTransferProtocolType != std::nullopt)) |
| 748 | { |
| 749 | // check if protocol is the same for URI and param |
| 750 | if (*paramTransferProtocolType != *uriTransferProtocolType) |
| 751 | { |
| 752 | BMCWEB_LOG_ERROR << "Request action parameter " |
| 753 | "TransferProtocolType must contain the " |
| 754 | "same protocol type as protocol type " |
| 755 | "provided with param imageUrl."; |
| 756 | |
| 757 | messages::actionParameterValueTypeError( |
| 758 | asyncResp->res, *actionParams.transferProtocolType, |
| 759 | "TransferProtocolType", "InsertMedia"); |
| 760 | |
| 761 | return; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | // validation passed, add protocol to URI if needed |
| 766 | if (uriTransferProtocolType == std::nullopt) |
| 767 | { |
| 768 | actionParams.imageUrl = getUriWithTransferProtocol( |
| 769 | *actionParams.imageUrl, *paramTransferProtocolType); |
| 770 | } |
| 771 | |
Jayaprakash Mutyala | 452bd8d | 2023-04-18 12:28:38 +0000 | [diff] [blame] | 772 | if (!actionParams.userName) |
| 773 | { |
| 774 | actionParams.userName = ""; |
| 775 | } |
| 776 | |
| 777 | if (!actionParams.password) |
| 778 | { |
| 779 | actionParams.password = ""; |
| 780 | } |
| 781 | |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 782 | doMountVmLegacy(asyncResp, service, resName, *actionParams.imageUrl, |
| 783 | !(*actionParams.writeProtected), |
| 784 | std::move(*actionParams.userName), |
| 785 | std::move(*actionParams.password)); |
| 786 | } |
| 787 | |
| 788 | /** |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 789 | * @brief Function transceives data with dbus directly. |
| 790 | * |
| 791 | * All BMC state properties will be retrieved before sending reset request. |
| 792 | */ |
Ed Tanous | 24e740a | 2023-02-24 12:08:58 -0800 | [diff] [blame] | 793 | inline void doEjectAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 794 | const std::string& service, const std::string& name, |
| 795 | bool legacy) |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 796 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 797 | // Legacy mount requires parameter with image |
| 798 | if (legacy) |
| 799 | { |
Adrian Ambrożewicz | d6da5be | 2020-01-13 18:31:01 +0100 | [diff] [blame] | 800 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 801 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 802 | if (ec) |
| 803 | { |
| 804 | BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec; |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 805 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 806 | messages::internalError(asyncResp->res); |
| 807 | return; |
| 808 | } |
Adrian Ambrożewicz | d6da5be | 2020-01-13 18:31:01 +0100 | [diff] [blame] | 809 | }, |
| 810 | service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name, |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 811 | "xyz.openbmc_project.VirtualMedia.Legacy", "Unmount"); |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 812 | } |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 813 | else // proxy |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 814 | { |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 815 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 816 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 817 | if (ec) |
| 818 | { |
| 819 | BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec; |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 820 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 821 | messages::internalError(asyncResp->res); |
| 822 | return; |
| 823 | } |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 824 | }, |
| 825 | service, "/xyz/openbmc_project/VirtualMedia/Proxy/" + name, |
| 826 | "xyz.openbmc_project.VirtualMedia.Proxy", "Unmount"); |
| 827 | } |
| 828 | } |
| 829 | |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 830 | inline void handleManagersVirtualMediaActionInsertPost( |
| 831 | crow::App& app, const crow::Request& req, |
| 832 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 833 | const std::string& name, const std::string& resName) |
| 834 | { |
| 835 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 836 | { |
| 837 | return; |
| 838 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 839 | |
| 840 | constexpr std::string_view action = "VirtualMedia.InsertMedia"; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 841 | if (name != "bmc") |
| 842 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 843 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 844 | |
| 845 | return; |
| 846 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 847 | InsertMediaActionParams actionParams; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 848 | |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 849 | // Read obligatory parameters (url of image) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 850 | if (!json_util::readJsonAction( |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 851 | req, asyncResp->res, "Image", actionParams.imageUrl, |
| 852 | "WriteProtected", actionParams.writeProtected, "UserName", |
| 853 | actionParams.userName, "Password", actionParams.password, |
| 854 | "Inserted", actionParams.inserted, "TransferMethod", |
| 855 | actionParams.transferMethod, "TransferProtocolType", |
| 856 | actionParams.transferProtocolType)) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 857 | { |
| 858 | return; |
| 859 | } |
| 860 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 861 | dbus::utility::getDbusObject( |
| 862 | "/xyz/openbmc_project/VirtualMedia", {}, |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 863 | [asyncResp, action, actionParams, |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 864 | resName](const boost::system::error_code& ec, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 865 | const dbus::utility::MapperGetObject& getObjectType) mutable { |
| 866 | if (ec) |
| 867 | { |
| 868 | BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec; |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 869 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 870 | |
| 871 | return; |
| 872 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 873 | |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 874 | std::string service = getObjectType.begin()->first; |
| 875 | BMCWEB_LOG_DEBUG << "GetObjectType: " << service; |
| 876 | |
| 877 | crow::connections::systemBus->async_method_call( |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 878 | [service, resName, action, actionParams, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 879 | asyncResp](const boost::system::error_code& ec2, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 880 | dbus::utility::ManagedObjectType& subtree) mutable { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 881 | if (ec2) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 882 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 883 | // Not possible in proxy mode |
| 884 | BMCWEB_LOG_DEBUG << "InsertMedia not " |
| 885 | "allowed in proxy mode"; |
| 886 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 887 | |
| 888 | return; |
| 889 | } |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 890 | for (const auto& object : subtree) |
| 891 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 892 | VmMode mode = parseObjectPathAndGetMode(object.first, resName); |
Boleslaw Ogonczyk Makowski | 5880f0c | 2023-04-14 15:32:40 +0200 | [diff] [blame] | 893 | if (mode == VmMode::Legacy) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 894 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 895 | validateParams(asyncResp, service, resName, actionParams); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 896 | |
| 897 | return; |
| 898 | } |
| 899 | } |
| 900 | BMCWEB_LOG_DEBUG << "Parent item not found"; |
| 901 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName); |
| 902 | }, |
| 903 | service, "/xyz/openbmc_project/VirtualMedia", |
| 904 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 905 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | inline void handleManagersVirtualMediaActionEject( |
| 909 | crow::App& app, const crow::Request& req, |
| 910 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 911 | const std::string& managerName, const std::string& resName) |
| 912 | { |
| 913 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 914 | { |
| 915 | return; |
| 916 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 917 | |
| 918 | constexpr std::string_view action = "VirtualMedia.EjectMedia"; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 919 | if (managerName != "bmc") |
| 920 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 921 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 922 | |
| 923 | return; |
| 924 | } |
| 925 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 926 | dbus::utility::getDbusObject( |
| 927 | "/xyz/openbmc_project/VirtualMedia", {}, |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 928 | [asyncResp, action, |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 929 | resName](const boost::system::error_code& ec2, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 930 | const dbus::utility::MapperGetObject& getObjectType) { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 931 | if (ec2) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 932 | { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 933 | BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec2; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 934 | messages::internalError(asyncResp->res); |
| 935 | |
| 936 | return; |
| 937 | } |
| 938 | std::string service = getObjectType.begin()->first; |
| 939 | BMCWEB_LOG_DEBUG << "GetObjectType: " << service; |
| 940 | |
| 941 | crow::connections::systemBus->async_method_call( |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 942 | [resName, service, action, |
| 943 | asyncResp](const boost::system::error_code& ec, |
| 944 | const dbus::utility::ManagedObjectType& subtree) { |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 945 | if (ec) |
| 946 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 947 | BMCWEB_LOG_ERROR << "ObjectMapper : No Service found"; |
| 948 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 949 | return; |
| 950 | } |
| 951 | |
| 952 | for (const auto& object : subtree) |
| 953 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 954 | VmMode mode = parseObjectPathAndGetMode(object.first, resName); |
| 955 | if (mode != VmMode::Invalid) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 956 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 957 | doEjectAction(asyncResp, service, resName, |
| 958 | mode == VmMode::Legacy); |
Boleslaw Ogonczyk Makowski | 5880f0c | 2023-04-14 15:32:40 +0200 | [diff] [blame] | 959 | return; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 960 | } |
| 961 | } |
| 962 | BMCWEB_LOG_DEBUG << "Parent item not found"; |
| 963 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName); |
| 964 | }, |
| 965 | service, "/xyz/openbmc_project/VirtualMedia", |
| 966 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 967 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | inline void handleManagersVirtualMediaCollectionGet( |
| 971 | crow::App& app, const crow::Request& req, |
| 972 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 973 | const std::string& name) |
| 974 | { |
| 975 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 976 | { |
| 977 | return; |
| 978 | } |
| 979 | if (name != "bmc") |
| 980 | { |
| 981 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", name); |
| 982 | |
| 983 | return; |
| 984 | } |
| 985 | |
| 986 | asyncResp->res.jsonValue["@odata.type"] = |
| 987 | "#VirtualMediaCollection.VirtualMediaCollection"; |
| 988 | asyncResp->res.jsonValue["Name"] = "Virtual Media Services"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame^] | 989 | asyncResp->res.jsonValue["@odata.id"] = |
| 990 | boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia", name); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 991 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 992 | dbus::utility::getDbusObject( |
| 993 | "/xyz/openbmc_project/VirtualMedia", {}, |
| 994 | [asyncResp, name](const boost::system::error_code& ec, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 995 | const dbus::utility::MapperGetObject& getObjectType) { |
| 996 | if (ec) |
| 997 | { |
| 998 | BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec; |
| 999 | messages::internalError(asyncResp->res); |
| 1000 | |
| 1001 | return; |
| 1002 | } |
| 1003 | std::string service = getObjectType.begin()->first; |
| 1004 | BMCWEB_LOG_DEBUG << "GetObjectType: " << service; |
| 1005 | |
| 1006 | getVmResourceList(asyncResp, service, name); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 1007 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | inline void |
| 1011 | handleVirtualMediaGet(crow::App& app, const crow::Request& req, |
| 1012 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1013 | const std::string& name, const std::string& resName) |
| 1014 | { |
| 1015 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1016 | { |
| 1017 | return; |
| 1018 | } |
| 1019 | if (name != "bmc") |
| 1020 | { |
| 1021 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName); |
| 1022 | |
| 1023 | return; |
| 1024 | } |
| 1025 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 1026 | dbus::utility::getDbusObject( |
| 1027 | "/xyz/openbmc_project/VirtualMedia", {}, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 1028 | [asyncResp, name, |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 1029 | resName](const boost::system::error_code& ec, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 1030 | const dbus::utility::MapperGetObject& getObjectType) { |
| 1031 | if (ec) |
| 1032 | { |
| 1033 | BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec; |
| 1034 | messages::internalError(asyncResp->res); |
| 1035 | |
| 1036 | return; |
| 1037 | } |
| 1038 | std::string service = getObjectType.begin()->first; |
| 1039 | BMCWEB_LOG_DEBUG << "GetObjectType: " << service; |
| 1040 | |
| 1041 | getVmData(asyncResp, service, name, resName); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 1042 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 1045 | inline void requestNBDVirtualMediaRoutes(App& app) |
| 1046 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1047 | BMCWEB_ROUTE( |
| 1048 | app, |
| 1049 | "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.InsertMedia") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1050 | .privileges(redfish::privileges::postVirtualMedia) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 1051 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 1052 | handleManagersVirtualMediaActionInsertPost, std::ref(app))); |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 1053 | |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1054 | BMCWEB_ROUTE( |
| 1055 | app, |
| 1056 | "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.EjectMedia") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1057 | .privileges(redfish::privileges::postVirtualMedia) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 1058 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 1059 | handleManagersVirtualMediaActionEject, std::ref(app))); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1060 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 1061 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1062 | .privileges(redfish::privileges::getVirtualMediaCollection) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 1063 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1064 | handleManagersVirtualMediaCollectionGet, std::ref(app))); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 1065 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 1066 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1067 | .privileges(redfish::privileges::getVirtualMedia) |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 1068 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 1069 | std::bind_front(handleVirtualMediaGet, std::ref(app))); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 1070 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 1071 | |
| 1072 | } // namespace redfish |