summaryrefslogtreecommitdiff
path: root/redfish-core/include/redfish_aggregator.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'redfish-core/include/redfish_aggregator.hpp')
-rw-r--r--redfish-core/include/redfish_aggregator.hpp85
1 files changed, 46 insertions, 39 deletions
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index 293dad2491..bd56d680fd 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -72,53 +72,66 @@ static void addPrefixToItem(nlohmann::json& item, std::string_view prefix)
// 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/FirmwareInventory
- // /redfish/v1/UpdateService/SoftwareInventory
- if (crow::utility::readUrlSegments(thisUrl, "redfish", "v1",
- "UpdateService", "FirmwareInventory") ||
- crow::utility::readUrlSegments(thisUrl, "redfish", "v1",
- "UpdateService", "SoftwareInventory"))
+ // The first two segments should be "/redfish/v1". We need to check that
+ // before we can search topCollections
+ if (!crow::utility::readUrlSegments(thisUrl, "redfish", "v1",
+ crow::utility::OrMorePaths()))
{
- BMCWEB_LOG_DEBUG << "Skipping UpdateService URI prefix fixing";
return;
}
- // We need to add a prefix to FirmwareInventory and SoftwareInventory
- // resources:
- // /redfish/v1/UpdateService/FirmwareInventory/<id>
- // /redfish/v1/UpdateService/SoftwareInventory/<id>
- std::string collectionName;
- if (crow::utility::readUrlSegments(
- thisUrl, "redfish", "v1", "UpdateService", std::ref(collectionName),
- std::ref(collectionItem), crow::utility::OrMorePaths()))
+ // Check array adding a segment each time until collection is identified
+ // Add prefix to segment after the collection
+ const boost::urls::segments_view urlSegments = thisUrl.segments();
+ bool addedPrefix = false;
+ boost::urls::url url("/");
+ boost::urls::segments_view::iterator it = urlSegments.begin();
+ const boost::urls::segments_view::const_iterator end = urlSegments.end();
+
+ // Skip past the leading "/redfish/v1"
+ it++;
+ it++;
+ for (; it != end; it++)
{
- collectionItem.insert(0, "_");
- collectionItem.insert(0, prefix);
- item = crow::utility::replaceUrlSegment(thisUrl, 4, collectionItem);
- return;
+ // Trailing "/" will result in an empty segment. In that case we need
+ // to return so we don't apply a prefix to top level collections such
+ // as "/redfish/v1/Chassis/"
+ if ((*it).empty())
+ {
+ return;
+ }
+
+ if (std::binary_search(topCollections.begin(), topCollections.end(),
+ url.buffer()))
+ {
+ std::string collectionItem(prefix);
+ collectionItem += "_" + (*it);
+ url.segments().push_back(collectionItem);
+ it++;
+ addedPrefix = true;
+ break;
+ }
+
+ url.segments().push_back(*it);
+ }
+
+ // Finish constructing the URL here (if needed) to avoid additional checks
+ for (; it != end; it++)
+ {
+ url.segments().push_back(*it);
}
- // 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(collectionItem), crow::utility::OrMorePaths()))
+ if (addedPrefix)
{
- collectionItem.insert(0, "_");
- collectionItem.insert(0, prefix);
- item = crow::utility::replaceUrlSegment(thisUrl, 3, collectionItem);
+ url.segments().insert(url.segments().begin(), {"redfish", "v1"});
+ item = url;
}
}
@@ -164,12 +177,6 @@ class RedfishAggregator
RedfishAggregator()
{
- // TODO: Remove in future patches, this is here to prevent compiler
- // warnings and get an accurate idea of the increase in the size of the
- // binary.
- BMCWEB_LOG_DEBUG << "There are " << topCollections.size()
- << " top level collections:";
-
getSatelliteConfigs(constructorCallback);
// Setup the retry policy to be used by Redfish Aggregation
@@ -776,7 +783,7 @@ class RedfishAggregator
{
using crow::utility::OrMorePaths;
using crow::utility::readUrlSegments;
- const boost::urls::url_view& url = thisReq.urlView;
+ const boost::urls::url_view url = thisReq.urlView;
// UpdateService is the only top level resource that is not a Collection
if (readUrlSegments(url, "redfish", "v1", "UpdateService"))
{