Boost::urls::format
Boost 1.82 dropped a lovely new toy, boost::urls::format, which is a lot
like our urlFromPieces method, but better in that it makes the resulting
uris more readable, and allows doing things like fragments in a single
line instead of multiple. We should prefer it in some cases.
Tested:
Redfish service validator passes.
Spot checks of URLs work as expected.
Unit tests pass.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ia7b38f0a95771c862507e7d5b4aa68aa1c98403c
diff --git a/redfish-core/lib/redfish_sessions.hpp b/redfish-core/lib/redfish_sessions.hpp
index 9fc0832..065878e 100644
--- a/redfish-core/lib/redfish_sessions.hpp
+++ b/redfish-core/lib/redfish_sessions.hpp
@@ -23,6 +23,8 @@
#include "registries/privilege_registry.hpp"
#include "utils/json_utils.hpp"
+#include <boost/url/format.hpp>
+
namespace redfish
{
@@ -31,8 +33,8 @@
{
res.jsonValue["Id"] = session.uniqueId;
res.jsonValue["UserName"] = session.username;
- res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
- "redfish", "v1", "SessionService", "Sessions", session.uniqueId);
+ res.jsonValue["@odata.id"] = boost::urls::format(
+ "/redfish/v1/SessionService/Sessions/{}", session.uniqueId);
res.jsonValue["@odata.type"] = "#Session.v1_5_0.Session";
res.jsonValue["Name"] = "User Session";
res.jsonValue["Description"] = "Manager User Session";
@@ -126,8 +128,8 @@
for (const std::string* uid : sessionIds)
{
nlohmann::json::object_t session;
- session["@odata.id"] = crow::utility::urlFromPieces(
- "redfish", "v1", "SessionService", "Sessions", *uid);
+ session["@odata.id"] =
+ boost::urls::format("/redfish/v1/SessionService/Sessions/{}", *uid);
ret.emplace_back(std::move(session));
}
return ret;
@@ -234,8 +236,8 @@
{
messages::passwordChangeRequired(
asyncResp->res,
- crow::utility::urlFromPieces("redfish", "v1", "AccountService",
- "Accounts", session->username));
+ boost::urls::format("/redfish/v1/AccountService/Accounts/{}",
+ session->username));
}
fillSessionObject(asyncResp->res, *session);