From 456cd875f3c56b45605d8a017e91d810876a035c Mon Sep 17 00:00:00 2001 From: Szymon Dompke Date: Tue, 1 Mar 2022 16:34:08 +0100 Subject: Use url_view for telemetry uris This change refactor telemetry code to use bmcweb utility function for uri construction, which is safe and preferred way, instead of string operations. Testing done: - Some basic GET operations done on Telemetry, no regression. Signed-off-by: Szymon Dompke Change-Id: I6de5d79a078944d398357f27dc0c201c130c4302 --- redfish-core/lib/metric_report.hpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'redfish-core/lib/metric_report.hpp') diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp index 89bd8dbe45..2fb8d8225f 100644 --- a/redfish-core/lib/metric_report.hpp +++ b/redfish-core/lib/metric_report.hpp @@ -14,6 +14,9 @@ namespace redfish namespace telemetry { +constexpr const char* metricReportUri = + "/redfish/v1/TelemetryService/MetricReports"; + using Readings = std::vector>; using TimestampReadings = std::tuple; @@ -39,11 +42,16 @@ inline bool fillReport(nlohmann::json& json, const std::string& id, const TimestampReadings& timestampReadings) { json["@odata.type"] = "#MetricReport.v1_3_0.MetricReport"; - json["@odata.id"] = telemetry::metricReportUri + std::string("/") + id; + json["@odata.id"] = + crow::utility::urlFromPieces("redfish", "v1", "TelemetryService", + "MetricReports", id) + .string(); json["Id"] = id; json["Name"] = id; json["MetricReportDefinition"]["@odata.id"] = - telemetry::metricReportDefinitionUri + std::string("/") + id; + crow::utility::urlFromPieces("redfish", "v1", "TelemetryService", + "MetricReportDefinitions", id) + .string(); const auto& [timestamp, readings] = timestampReadings; json["Timestamp"] = crow::utility::getDateTimeUintMs(timestamp); @@ -62,7 +70,7 @@ inline void requestRoutesMetricReportCollection(App& app) asyncResp->res.jsonValue["@odata.type"] = "#MetricReportCollection.MetricReportCollection"; asyncResp->res.jsonValue["@odata.id"] = - "/redfish/v1/TelemetryService/MetricReports"; + telemetry::metricReportUri; asyncResp->res.jsonValue["Name"] = "Metric Report Collection"; const std::vector interfaces{ telemetry::reportInterface}; -- cgit v1.2.3