summaryrefslogtreecommitdiff
path: root/redfish-core/lib/virtual_media.hpp
diff options
context:
space:
mode:
authorAnna Platash <anna.platash@intel.com>2020-11-17 12:18:31 +0300
committerEd Tanous <ed@tanous.net>2020-12-04 18:44:03 +0300
commit9e319cf0c5ee714cdd879a1d2a6e5b5ac96c7f1d (patch)
treed8ef4b8a4d1bf33516a48321a91644cc1e2901cb /redfish-core/lib/virtual_media.hpp
parentdba0c291b5bbd8d256387ba43bb48bda82a191dc (diff)
downloadbmcweb-9e319cf0c5ee714cdd879a1d2a6e5b5ac96c7f1d.tar.xz
VirtualMedia doesn't propagate information to WebUI
Information if the image is mounted in read-only mode or not wasn't propagated from VirtualMedia to Web UI. Also TransportProtocolType value wasn't updated. Added the WriteProtected field value update using the WriteProtected property from MountPoint interface. Added TransportProtocolType field value update using image URL. Tested manually on ArcherCity by mounting images via RedFish interface with and without write protection, using HTTP and Samba. Schema validated by Redfish validator. Signed-off-by: Anna Platash <anna.platash@intel.com> Change-Id: I41d4a377d9fe3a978e8a3b654338c7a3d961b1c1
Diffstat (limited to 'redfish-core/lib/virtual_media.hpp')
-rw-r--r--redfish-core/lib/virtual_media.hpp109
1 files changed, 77 insertions, 32 deletions
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 13361904cb..6d1672c66b 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -22,10 +22,34 @@
#include <utils/json_utils.hpp>
// for GetObjectType and ManagedObjectType
#include <account_service.hpp>
+#include <boost/url/url_view.hpp>
namespace redfish
{
+/**
+ * @brief Function extracts transfer protocol name from URI.
+ */
+static std::string getTransferProtocolTypeFromUri(const std::string& imageUri)
+{
+ try
+ {
+ std::string_view scheme = boost::urls::url_view(imageUri).scheme();
+ if (scheme == "smb")
+ {
+ return "CIFS";
+ }
+ else if (scheme == "https")
+ {
+ return "HTTPS";
+ }
+ }
+ catch (std::exception& p)
+ {
+ BMCWEB_LOG_ERROR << p.what();
+ }
+ return "None";
+}
/**
* @brief Read all known properties from VM object interfaces
@@ -89,31 +113,46 @@ static void vmParseInterfaceObject(const DbusInterfaceType& interface,
else
{
// Legacy mode
- const auto imageUrlProperty =
- mountPointIface->second.find("ImageURL");
- if (imageUrlProperty != processIface->second.cend())
+ for (const auto& property : mountPointIface->second)
{
- const std::string* imageUrlValue =
- std::get_if<std::string>(&imageUrlProperty->second);
- if (imageUrlValue && !imageUrlValue->empty())
+ if (property.first == "ImageURL")
{
- std::filesystem::path filePath = *imageUrlValue;
- if (!filePath.has_filename())
+ const std::string* imageUrlValue =
+ std::get_if<std::string>(&property.second);
+ if (imageUrlValue && !imageUrlValue->empty())
{
- // this will handle https share, which not necessarily
- // has to have filename given.
- aResp->res.jsonValue["ImageName"] = "";
- }
- else
- {
- aResp->res.jsonValue["ImageName"] = filePath.filename();
- }
+ std::filesystem::path filePath = *imageUrlValue;
+ if (!filePath.has_filename())
+ {
+ // this will handle https share, which not
+ // necessarily has to have filename given.
+ aResp->res.jsonValue["ImageName"] = "";
+ }
+ else
+ {
+ aResp->res.jsonValue["ImageName"] =
+ filePath.filename();
+ }
+
+ aResp->res.jsonValue["Image"] = *imageUrlValue;
+ aResp->res.jsonValue["Inserted"] = *activeValue;
+ aResp->res.jsonValue["TransferProtocolType"] =
+ getTransferProtocolTypeFromUri(*imageUrlValue);
- aResp->res.jsonValue["Image"] = *imageUrlValue;
- aResp->res.jsonValue["Inserted"] = *activeValue;
- if (*activeValue == true)
+ if (*activeValue == true)
+ {
+ aResp->res.jsonValue["ConnectedVia"] = "URI";
+ }
+ }
+ }
+ else if (property.first == "WriteProtected")
+ {
+ const bool* writeProtectedValue =
+ std::get_if<bool>(&property.second);
+ if (writeProtectedValue)
{
- aResp->res.jsonValue["ConnectedVia"] = "URI";
+ aResp->res.jsonValue["WriteProtected"] =
+ *writeProtectedValue;
}
}
}
@@ -288,22 +327,28 @@ class VirtualMediaActionInsertMedia : public Node
std::optional<TransferProtocol>
getTransferProtocolFromUri(const std::string& imageUri)
{
- if (imageUri.find("smb://") != std::string::npos)
- {
- return TransferProtocol::smb;
- }
- else if (imageUri.find("https://") != std::string::npos)
- {
- return TransferProtocol::https;
- }
- else if (imageUri.find("://") != std::string::npos)
+ try
{
- return TransferProtocol::invalid;
+ std::string_view scheme = boost::urls::url_view(imageUri).scheme();
+ if (scheme == "smb")
+ {
+ return TransferProtocol::smb;
+ }
+ else if (scheme == "https")
+ {
+ return TransferProtocol::https;
+ }
+ else if (!scheme.empty())
+ {
+ return TransferProtocol::invalid;
+ }
}
- else
+ catch (std::exception& p)
{
- return {};
+ BMCWEB_LOG_ERROR << p.what();
}
+
+ return {};
}
/**