summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarson Labrado <clabrado@google.com>2022-09-07 03:14:49 +0300
committerEd Tanous <ed@tanous.net>2022-09-17 04:23:55 +0300
commit411e6a1164855c0ebf04e243f0c8ea20146c1dff (patch)
tree8a43dbd6c0c19e62636c65713ccec2a672a370ec
parent677bb756282b3029ed7c8cbf2c0440b89b0d5928 (diff)
downloadbmcweb-411e6a1164855c0ebf04e243f0c8ea20146c1dff.tar.xz
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
-rw-r--r--redfish-core/include/redfish_aggregator.hpp60
1 files changed, 44 insertions, 16 deletions
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index 4d05c96fac..9620eefba1 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 @@ static void addPrefixToItem(nlohmann::json& item, std::string_view prefix)
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 @@ static void addPrefixToItem(nlohmann::json& item, std::string_view prefix)
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 @@ static void addPrefixes(nlohmann::json& json, std::string_view prefix)
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 @@ class RedfishAggregator
{
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",