feat(state,registry): back StateStore with Void::Sqlite when available and filter audit queries
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s

This commit is contained in:
faumaray committed 2026-12-04 01:02:18 +03:00
1 parent 9a6f209f5b
commit e990f44037
8 files changed
+387 -34

No files matched your search

+57 -9
View File
@@ -1505,15 +1505,63 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
",\"role\":" + json_quote(role_name(role)) + "}\n");
}
if (req.path == "/api/v1/audit" && req.method == "GET") {
return HttpResponse::json(200,
"{\"audits\":" + json_array(audits_, [](const AuditEntry &a) {
return "{\"timestamp\":" + std::to_string(a.timestamp) +
",\"actor\":" + json_quote(a.actor) +
",\"action\":" + json_quote(a.action) +
",\"target\":" + json_quote(a.target) +
",\"outcome\":" + json_quote(a.outcome) +
",\"detail\":" + json_quote(a.detail) + '}';
}) + "}\n");
const auto query_value = [&](std::string_view key) {
const auto it = req.query.find(std::string{key});
return it == req.query.end() ? std::string{} : it->second;
};
const std::string actor_filter = query_value("actor");
const std::string action_filter = query_value("action");
const std::string outcome_filter = query_value("outcome");
std::size_t limit = 100;
std::size_t offset = 0;
const auto parse_size = [](const std::string &text, std::size_t max, std::size_t &out) {
std::size_t value = 0;
const auto [ptr, ec] =
std::from_chars(text.data(), text.data() + text.size(), value);
if (ec != std::errc{} || ptr != text.data() + text.size() || value > max) {
return false;
}
out = value;
return true;
};
if (const std::string limit_text = query_value("limit");
!limit_text.empty() && !parse_size(limit_text, 2000, limit)) {
return HttpResponse::error_json(400, "invalid_limit",
"limit must be an integer in [0, 2000]");
}
if (const std::string offset_text = query_value("offset");
!offset_text.empty() && !parse_size(offset_text, 100000, offset)) {
return HttpResponse::error_json(400, "invalid_offset",
"offset must be a non-negative integer");
}
std::vector<const AuditEntry *> matched;
for (const auto &entry : audits_) {
if (!actor_filter.empty() && entry.actor != actor_filter)
continue;
if (!action_filter.empty() && entry.action.find(action_filter) == std::string::npos)
continue;
if (!outcome_filter.empty() && entry.outcome != outcome_filter)
continue;
matched.push_back(&entry);
}
const std::size_t total = matched.size();
std::vector<const AuditEntry *> page;
for (std::size_t i = offset; i < total && page.size() < limit; ++i)
page.push_back(matched[i]);
return HttpResponse::json(
200, "{\"audits\":" +
json_array(page,
[](const AuditEntry *a) {
return "{\"timestamp\":" + std::to_string(a->timestamp) +
",\"actor\":" + json_quote(a->actor) +
",\"action\":" + json_quote(a->action) +
",\"target\":" + json_quote(a->target) +
",\"outcome\":" + json_quote(a->outcome) +
",\"detail\":" + json_quote(a->detail) + '}';
}) +
",\"total\":" + std::to_string(total) + ",\"limit\":" +
std::to_string(limit) + ",\"offset\":" + std::to_string(offset) + "}\n");
}
if (req.path == "/api/v1/admin/storage" && req.method == "GET") {
return HttpResponse::json(