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