Added constrains to id generator
This commit prevents id with more than one '/'. Slash can be used to
create namespaces to avoid id conflicts between multiple users.
Changed generator logic to take provided id as a name if no name was
provided.
Tested:
- Tested that id and name generates correctly
- It is no longer possible to add id with more than one '/'
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: Ieef32ddb71b5a4870117aab0d624cbd46b5893e6
diff --git a/src/report_manager.cpp b/src/report_manager.cpp
index 18636f8..7ac8537 100644
--- a/src/report_manager.cpp
+++ b/src/report_manager.cpp
@@ -124,16 +124,6 @@
reports.end());
}
-void ReportManager::verifyReportIdLength(const std::string& reportId)
-{
- if (reportId.length() > maxReportIdLength)
- {
- throw sdbusplus::exception::SdBusError(
- static_cast<int>(std::errc::invalid_argument),
- "Report id exceeds maximum length");
- }
-}
-
void ReportManager::verifyAddReport(
const std::string& reportId, const std::string& reportName,
const ReportingType reportingType, Milliseconds interval,
@@ -154,20 +144,6 @@
"Reached maximal report count");
}
- verifyReportIdLength(reportId);
- utils::verifyIdCharacters(reportId);
-
- for (const auto& report : reports)
- {
- if (report->getId() == reportId)
- {
- throw sdbusplus::exception::SdBusError(
- static_cast<int>(std::errc::file_exists), "Duplicate report");
- }
- }
-
- verifyReportUpdates(reportUpdates);
-
if (reportingType == ReportingType::periodic && interval < minInterval)
{
throw sdbusplus::exception::SdBusError(
@@ -222,17 +198,11 @@
std::vector<LabeledMetricParameters> labeledMetricParams,
const bool enabled)
{
- std::string name = reportName;
- if (name.empty())
- {
- name = "Report";
- }
-
const auto existingReportIds = utils::transform(
reports, [](const auto& report) { return report->getId(); });
- std::string id =
- utils::generateId(reportId, name, existingReportIds, maxReportIdLength);
+ auto [id, name] = utils::generateId(reportId, reportName, reportNameDefault,
+ existingReportIds, maxReportIdLength);
verifyAddReport(id, name, reportingType, interval, reportUpdates,
labeledMetricParams);
@@ -304,14 +274,3 @@
}
}
}
-
-void ReportManager::verifyReportUpdates(const ReportUpdates reportUpdates)
-{
- if (std::find(supportedReportUpdates.begin(), supportedReportUpdates.end(),
- reportUpdates) == supportedReportUpdates.end())
- {
- throw sdbusplus::exception::SdBusError(
- static_cast<int>(std::errc::invalid_argument),
- "Invalid ReportUpdates");
- }
-}