feat(cli,registry): expose install options; paginate user listings
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 2s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 7s

This commit is contained in:
faumaray committed 2026-12-04 07:36:06 +03:00
1 parent c7d2662cf2
commit eabcb92d0b
8 files changed
+154 -15

No files matched your search

+40 -7
View File
@@ -1774,8 +1774,8 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
}
// Admin endpoints: users, audit, storage.
if (req.path == "/api/v1/users" || req.path == "/api/v1/audit" ||
req.path == "/api/v1/stats" || req.path == "/api/v1/admin/storage") {
if (req.path == "/api/v1/users" || req.path == "/api/v1/audit" || req.path == "/api/v1/stats" ||
req.path == "/api/v1/admin/storage") {
if (!principal) {
return HttpResponse::error_json(401, "unauthorized", "authentication required");
}
@@ -1783,15 +1783,48 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
return HttpResponse::error_json(403, "forbidden", "admin role required");
}
if (req.path == "/api/v1/users" && req.method == "GET") {
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 auto it = req.query.find("limit");
it != req.query.end() && !parse_size(it->second, 500, limit)) {
return HttpResponse::error_json(400, "invalid_limit",
"limit must be an integer in [0, 500]");
}
if (const auto it = req.query.find("offset");
it != req.query.end() && !parse_size(it->second, 1000000, offset)) {
return HttpResponse::error_json(400, "invalid_offset",
"offset must be a non-negative integer");
}
std::vector<const UserRecord *> ulist;
for (const auto &[k, v] : users_)
ulist.push_back(&v);
const std::size_t total = ulist.size();
std::vector<const UserRecord *> page;
for (std::size_t i = offset; i < total && page.size() < limit; ++i) {
page.push_back(ulist[i]);
}
return HttpResponse::json(
200, "{\"users\":" + json_array(ulist, [](const UserRecord *u) {
return "{\"username\":" + json_quote(u->username) +
",\"role\":" + json_quote(role_name(u->role)) +
",\"active\":" + std::string{u->active ? "true" : "false"} + '}';
}) + "}\n");
200, "{\"users\":" +
json_array(page,
[](const UserRecord *u) {
return "{\"username\":" + json_quote(u->username) +
",\"role\":" + json_quote(role_name(u->role)) +
",\"active\":" +
std::string{u->active ? "true" : "false"} + '}';
}) +
",\"total\":" + std::to_string(total) + ",\"limit\":" +
std::to_string(limit) + ",\"offset\":" + std::to_string(offset) + "}\n");
}
if (req.path == "/api/v1/users" && req.method == "POST") {
if (!check_csrf_locked(req, *principal)) {