Aggregation: Ignore JsonSchemas and fix prefixes
We don't want to aggregate JsonSchemas as-is since it can introduce
problems related to inconsistent versions between the aggregating and
satellite BMCs. For now we will just assume that the aggregating BMC
will match all satellite BMCs in terms of schemas and versions.
There was also an edge case where we are not adding prefixes to "Uri"
keys. These are used by Registries resources. Now we make a case-
insensitive check to see if a key ends with "uri" in order to
determine if we need to add the prefix to the resource ID.
Tested:
Requests to /redfish/v1/JsonSchemas only show schemas on the
aggregating BMC.
Responses from /redfish/v1/Registries/<id> now contain the
aggregation prefix in the value associated with the "Uri" key.
~# curl localhost/redfish/v1/Registries/5B247A_TaskEvent
{
...
"Location": [
{
...
"Uri": "/redfish/v1/Registries/5B247A_TaskEvent/TaskEvent"
}
],
...
}
Signed-off-by: Carson Labrado <clabrado@google.com>
Change-Id: I935785740c05ad0ac3e8c682a72ae1d1419054a8
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index 4d05c96..9620eef 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <boost/algorithm/string/predicate.hpp>
#include <dbus_utility.hpp>
#include <error_messages.hpp>
#include <http_client.hpp>
@@ -32,8 +33,21 @@
boost::urls::url_view thisUrl = *parsed;
+ // We don't need to aggregate JsonSchemas due to potential issues such as
+ // version mismatches between aggregator and satellite BMCs. For now
+ // assume that the aggregator has all the schemas and versions that the
+ // aggregated server has.
+ std::string collectionItem;
+ if (crow::utility::readUrlSegments(thisUrl, "redfish", "v1", "JsonSchemas",
+ std::ref(collectionItem),
+ crow::utility::OrMorePaths()))
+ {
+ BMCWEB_LOG_DEBUG << "Skipping JsonSchemas URI prefix fixing";
+ return;
+ }
+
// We don't need to add prefixes to these URIs since
- // /redfish/v1/UpdateService/ itself is not a collection
+ // /redfish/v1/UpdateService/ itself is not a collection:
// /redfish/v1/UpdateService/FirmwareInventory
// /redfish/v1/UpdateService/SoftwareInventory
if (crow::utility::readUrlSegments(thisUrl, "redfish", "v1",
@@ -45,31 +59,31 @@
return;
}
- // We also need to aggregate FirmwareInventory and
- // SoftwareInventory so add an extra offset
+ // We need to add a prefix to FirmwareInventory and SoftwareInventory
+ // resources:
// /redfish/v1/UpdateService/FirmwareInventory/<id>
// /redfish/v1/UpdateService/SoftwareInventory/<id>
std::string collectionName;
- std::string softwareItem;
if (crow::utility::readUrlSegments(
thisUrl, "redfish", "v1", "UpdateService", std::ref(collectionName),
- std::ref(softwareItem), crow::utility::OrMorePaths()))
+ std::ref(collectionItem), crow::utility::OrMorePaths()))
{
- softwareItem.insert(0, "_");
- softwareItem.insert(0, prefix);
- item = crow::utility::replaceUrlSegment(thisUrl, 4, softwareItem);
+ collectionItem.insert(0, "_");
+ collectionItem.insert(0, prefix);
+ item = crow::utility::replaceUrlSegment(thisUrl, 4, collectionItem);
+ return;
}
- // A collection URI that ends with "/" such as
- // "/redfish/v1/Chassis/" will have 4 segments so we need to
- // make sure we don't try to add a prefix to an empty segment
+ // If we reach here then we need to add a prefix to resource IDs that take
+ // the general form of "/redfish/v1/<collection>/<id> such as:
+ // /redfish/v1/Chassis/foo
if (crow::utility::readUrlSegments(
thisUrl, "redfish", "v1", std::ref(collectionName),
- std::ref(softwareItem), crow::utility::OrMorePaths()))
+ std::ref(collectionItem), crow::utility::OrMorePaths()))
{
- softwareItem.insert(0, "_");
- softwareItem.insert(0, prefix);
- item = crow::utility::replaceUrlSegment(thisUrl, 3, softwareItem);
+ collectionItem.insert(0, "_");
+ collectionItem.insert(0, prefix);
+ item = crow::utility::replaceUrlSegment(thisUrl, 3, collectionItem);
}
}
@@ -111,7 +125,10 @@
continue;
}
- if ((item.first == "@odata.id") || (item.first.ends_with("URI")))
+ // TODO: Update with the uri naming language from the specification
+ // when it gets released in 1.17
+ if ((item.first == "@odata.id") ||
+ boost::algorithm::iends_with(item.first, "uri"))
{
addPrefixToItem(item.second, prefix);
}
@@ -761,6 +778,17 @@
{
return Result::LocalHandle;
}
+
+ // We don't need to aggregate JsonSchemas due to potential issues such
+ // as version mismatches between aggregator and satellite BMCs. For
+ // now assume that the aggregator has all the schemas and versions that
+ // the aggregated server has.
+ if (crow::utility::readUrlSegments(url, "redfish", "v1", "JsonSchemas",
+ crow::utility::OrMorePaths()))
+ {
+ return Result::LocalHandle;
+ }
+
if (readUrlSegments(url, "redfish", "v1", "UpdateService",
"SoftwareInventory") ||
readUrlSegments(url, "redfish", "v1", "UpdateService",