Make virtual media use urlFromPieces
urlFromPieces is the new way to construct "correct" urls. It also
cleans up quite a bit of this code. Use it.
Tested: Code compiles. No backend in upstream yet.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ic43c257613061708e96a5449e0b3d57f288fbffa
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 4f6fad9..69040a6 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -148,12 +148,8 @@
const std::string& resName)
{
nlohmann::json item;
-
- std::string id = "/redfish/v1/Managers/";
- id += name;
- id += "/VirtualMedia/";
- id += resName;
- item["@odata.id"] = std::move(id);
+ item["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Managers", name, "VirtualMedia", resName);
item["@odata.type"] = "#VirtualMedia.v1_3_0.VirtualMedia";
item["Name"] = "Virtual Removable Media";
@@ -196,12 +192,8 @@
continue;
}
- std::string id = "/redfish/v1/Managers/";
- id += name;
- id += "/VirtualMedia/";
- id += path;
-
- item["@odata.id"] = std::move(id);
+ item["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Managers", name, "VirtualMedia", path);
members.emplace_back(std::move(item));
}
aResp->res.jsonValue["Members@odata.count"] = members.size();
@@ -258,26 +250,23 @@
}
aResp->res.jsonValue = vmItemTemplate(name, resName);
- std::string actionsId = "/redfish/v1/Managers/";
- actionsId += name;
- actionsId += "/VirtualMedia/";
- actionsId += resName;
- actionsId += "/Actions";
// Check if dbus path is Legacy type
if (mode.filename() == "Legacy")
{
aResp->res.jsonValue["Actions"]["#VirtualMedia.InsertMedia"]
- ["target"] =
- actionsId + "/VirtualMedia.InsertMedia";
+ ["target"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Managers", name, "VirtualMedia", resName,
+ "Actions", "VirtualMedia.InsertMedia");
}
vmParseInterfaceObject(item.second, aResp);
aResp->res
.jsonValue["Actions"]["#VirtualMedia.EjectMedia"]["target"] =
- actionsId + "/VirtualMedia.EjectMedia";
-
+ crow::utility::urlFromPieces("redfish", "v1", "Managers", name,
+ "VirtualMedia", resName, "Actions",
+ "VirtualMedia.EjectMedia");
return;
}
@@ -1001,8 +990,8 @@
asyncResp->res.jsonValue["@odata.type"] =
"#VirtualMediaCollection.VirtualMediaCollection";
asyncResp->res.jsonValue["Name"] = "Virtual Media Services";
- asyncResp->res.jsonValue["@odata.id"] =
- "/redfish/v1/Managers/" + name + "/VirtualMedia";
+ asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Managers", name, "VirtualMedia");
crow::connections::systemBus->async_method_call(
[asyncResp, name](const boost::system::error_code ec,