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
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 1336190..6d1672c 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 @@
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;
- if (*activeValue == true)
+ aResp->res.jsonValue["Image"] = *imageUrlValue;
+ aResp->res.jsonValue["Inserted"] = *activeValue;
+ aResp->res.jsonValue["TransferProtocolType"] =
+ getTransferProtocolTypeFromUri(*imageUrlValue);
+
+ 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 @@
std::optional<TransferProtocol>
getTransferProtocolFromUri(const std::string& imageUri)
{
- if (imageUri.find("smb://") != std::string::npos)
+ try
{
- return TransferProtocol::smb;
+ 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 if (imageUri.find("https://") != std::string::npos)
+ catch (std::exception& p)
{
- return TransferProtocol::https;
+ BMCWEB_LOG_ERROR << p.what();
}
- else if (imageUri.find("://") != std::string::npos)
- {
- return TransferProtocol::invalid;
- }
- else
- {
- return {};
- }
+
+ return {};
}
/**