summaryrefslogtreecommitdiff
path: root/redfish-core/lib/log_services.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2021-10-26 22:45:59 +0300
committerEd Tanous <edtanous@google.com>2022-02-28 03:17:20 +0300
commitace85d606dca3e9b6c1dbe1c7ee9a685be169ed6 (patch)
tree30890ae4279c77daffa7344cf44cd3ef2228444c /redfish-core/lib/log_services.hpp
parent30a3c431478584109d6d3a52f4d9541d5275902a (diff)
downloadbmcweb-ace85d606dca3e9b6c1dbe1c7ee9a685be169ed6.tar.xz
Add url type safety to message registry
There are a number of places where we use message registry messages incorrectly. This patchset attempts to fix them, and invoke some type safety when they're used such that they're more obvious to use. Namely, it changes a number of the message registry methods to accept a boost::urls::url_view for its argument instead of a const std::string&. This forces the calling code to correctly encode a URL to use the method, which should make it obvious that it's not for an ID, a property name, or anything else. In the course of doing this, several places were found to be using the first argument incorrectly. Tested: curl --insecure --user root:0penBmc https://192.168.7.2/redfish/v1/Chassis/foobar Returns: { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type #Chassis.v1_16_0.Chassis named foobar was not found.", "MessageArgs": [ "#Chassis.v1_16_0.Chassis", "foobar" ], "MessageId": "Base.1.8.1.ResourceNotFound", "MessageSeverity": "Critical", "Resolution": "Provide a valid resource identifier and resubmit the request." } ], "code": "Base.1.8.1.ResourceNotFound", "message": "The requested resource of type #Chassis.v1_16_0.Chassis named foobar was not found." } Identically to previously. Also tested with IDs that contained % encoded characters, like foobar%10, which gave the same result. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Icbb3bce5d190a260610087c9ef35e7becc5a50c7
Diffstat (limited to 'redfish-core/lib/log_services.hpp')
-rw-r--r--redfish-core/lib/log_services.hpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 94de5a9af7..154de95a7c 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -328,7 +328,8 @@ inline static bool
indexStr.data(), indexStr.data() + indexStr.size(), index);
if (ec != std::errc())
{
- messages::resourceMissingAtURI(asyncResp->res, entryID);
+ messages::resourceMissingAtURI(
+ asyncResp->res, crow::utility::urlFromPieces(entryID));
return false;
}
}
@@ -337,7 +338,8 @@ inline static bool
std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp);
if (ec != std::errc())
{
- messages::resourceMissingAtURI(asyncResp->res, entryID);
+ messages::resourceMissingAtURI(asyncResp->res,
+ crow::utility::urlFromPieces(entryID));
return false;
}
return true;
@@ -812,8 +814,7 @@ inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
(*diagnosticDataType != "OEM"))
{
BMCWEB_LOG_ERROR << "Wrong parameter values passed";
- messages::invalidObject(asyncResp->res,
- "System Dump creation parameters");
+ messages::internalError(asyncResp->res);
return;
}
}
@@ -831,8 +832,7 @@ inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
{
BMCWEB_LOG_ERROR
<< "Wrong parameter value passed for 'DiagnosticDataType'";
- messages::invalidObject(asyncResp->res,
- "BMC Dump creation parameters");
+ messages::internalError(asyncResp->res);
return;
}
}
@@ -1332,7 +1332,8 @@ inline void requestRoutesJournalEventLogEntry(App& app)
}
}
// Requested ID was not found
- messages::resourceMissingAtURI(asyncResp->res, targetID);
+ messages::resourceMissingAtURI(
+ asyncResp->res, crow::utility::urlFromPieces(targetID));
});
}
@@ -1976,7 +1977,7 @@ inline void requestRoutesSystemHostLoggerLogEntry(App& app)
app, "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/<str>/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
+ [](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& param) {
const std::string& targetID = param;
@@ -1989,12 +1990,12 @@ inline void requestRoutesSystemHostLoggerLogEntry(App& app)
auto [ptr, ec] = std::from_chars(targetID.data(), end, idInt);
if (ec == std::errc::invalid_argument)
{
- messages::resourceMissingAtURI(asyncResp->res, targetID);
+ messages::resourceMissingAtURI(asyncResp->res, req.urlView);
return;
}
if (ec == std::errc::result_out_of_range)
{
- messages::resourceMissingAtURI(asyncResp->res, targetID);
+ messages::resourceMissingAtURI(asyncResp->res, req.urlView);
return;
}
@@ -2026,7 +2027,7 @@ inline void requestRoutesSystemHostLoggerLogEntry(App& app)
}
// Requested ID was not found
- messages::resourceMissingAtURI(asyncResp->res, targetID);
+ messages::resourceMissingAtURI(asyncResp->res, req.urlView);
});
}
@@ -2253,7 +2254,7 @@ inline void requestRoutesBMCJournalLogEntry(App& app)
"/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
+ [](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& entryID) {
// Convert the unique ID back to a timestamp to find the entry
@@ -2304,7 +2305,7 @@ inline void requestRoutesBMCJournalLogEntry(App& app)
// Confirm that the entry ID matches what was requested
if (idStr != entryID)
{
- messages::resourceMissingAtURI(asyncResp->res, entryID);
+ messages::resourceMissingAtURI(asyncResp->res, req.urlView);
return;
}
@@ -2642,7 +2643,8 @@ static void
if (filename.empty() || timestamp.empty())
{
- messages::resourceMissingAtURI(asyncResp->res, logID);
+ messages::resourceMissingAtURI(
+ asyncResp->res, crow::utility::urlFromPieces(logID));
return;
}
@@ -2774,11 +2776,12 @@ inline void requestRoutesCrashdumpFile(App& app)
"/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
+ [](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& logID, const std::string& fileName) {
auto getStoredLogCallback =
- [asyncResp, logID, fileName](
+ [asyncResp, logID, fileName,
+ url(boost::urls::url(req.urlView))](
const boost::system::error_code ec,
const std::vector<std::pair<
std::string, dbus::utility::DbusVariantType>>&
@@ -2801,23 +2804,20 @@ inline void requestRoutesCrashdumpFile(App& app)
if (dbusFilename.empty() || dbusTimestamp.empty() ||
dbusFilepath.empty())
{
- messages::resourceMissingAtURI(asyncResp->res,
- fileName);
+ messages::resourceMissingAtURI(asyncResp->res, url);
return;
}
// Verify the file name parameter is correct
if (fileName != dbusFilename)
{
- messages::resourceMissingAtURI(asyncResp->res,
- fileName);
+ messages::resourceMissingAtURI(asyncResp->res, url);
return;
}
if (!std::filesystem::exists(dbusFilepath))
{
- messages::resourceMissingAtURI(asyncResp->res,
- fileName);
+ messages::resourceMissingAtURI(asyncResp->res, url);
return;
}
std::ifstream ifs(dbusFilepath,
@@ -3456,7 +3456,7 @@ inline void requestRoutesPostCodesEntry(App& app)
app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(
- [](const crow::Request&,
+ [](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& targetID) {
uint16_t bootIndex = 0;
@@ -3464,7 +3464,7 @@ inline void requestRoutesPostCodesEntry(App& app)
if (!parsePostCode(targetID, codeIndex, bootIndex))
{
// Requested ID was not found
- messages::resourceMissingAtURI(asyncResp->res, targetID);
+ messages::resourceMissingAtURI(asyncResp->res, req.urlView);
return;
}
if (bootIndex == 0 || codeIndex == 0)