Make routes start matching Redfish
This is preliminary patch to set up the route handling such that it's
ready for the addition of multiple hosts, multiple managers in the
future. Routes previously took the form of
/redfish/v1/Systems/system
which essentially hardcoded the name "system" into a number of places.
As the stack evolves to support multiple systems, this needs to change.
This patchset changes all the ComputerSystem resources to the form:
/redfish/v1/Systems/<str>
and adds 404 checks to each route such that they will be handled
properly still. This means that as we evolve our multi-host support,
each individual route can be moved one at a time to support multi-host.
In the future, moving these to redfish-spec-defined routing would likely
mean that we could generate this code in the future at some point, which
reduces the likelihood that people do it incorrectly.
This patch currently sets the resource id and resource type in the
resourceNotFound message to empty string (""). This handling is still
arguably more correct than what we had before, which just returned 404
with an empty payload, although this will be corrected in the future.
Tested: None yet. RFC to see if this is a pattern we'd like to
propogate
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: If9c07ad69f5287bb054645f460d7e370d433dc27
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
index 65a3e9c..8bc8cf0 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -1156,15 +1156,23 @@
/**
* Functions triggers appropriate requests on DBus
*/
- BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Processors/")
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/")
.privileges(redfish::privileges::getProcessorCollection)
.methods(boost::beast::http::verb::get)(
[&app](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& systemName) {
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
{
return;
}
+ if (systemName != "system")
+ {
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+
asyncResp->res.jsonValue["@odata.type"] =
"#ProcessorCollection.ProcessorCollection";
asyncResp->res.jsonValue["Name"] = "Processor Collection";
@@ -1185,16 +1193,24 @@
* Functions triggers appropriate requests on DBus
*/
- BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Processors/<str>/")
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
.privileges(redfish::privileges::getProcessor)
.methods(boost::beast::http::verb::get)(
[&app](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& systemName,
const std::string& processorId) {
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
{
return;
}
+ if (systemName != "system")
+ {
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+
asyncResp->res.jsonValue["@odata.type"] =
"#Processor.v1_11_0.Processor";
asyncResp->res.jsonValue["@odata.id"] =
@@ -1205,16 +1221,24 @@
std::bind_front(getProcessorData, asyncResp, processorId));
});
- BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Processors/<str>/")
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Processors/<str>/")
.privileges(redfish::privileges::patchProcessor)
.methods(boost::beast::http::verb::patch)(
[&app](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& systemName,
const std::string& processorId) {
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
{
return;
}
+ if (systemName != "system")
+ {
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+
std::optional<nlohmann::json> appliedConfigJson;
if (!json_util::readJsonPatch(req, asyncResp->res,
"AppliedOperatingConfig",