feat(registry,daemon): patch package metadata; report workspace info
This commit is contained in:
1 parent
85ff7a8c75
commit
e7698a411d
8 files changed
+250
-4
No files matched your search
@@ -999,6 +999,64 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
"}\n");
|
||||
}
|
||||
|
||||
// Update mutable package metadata: PATCH /api/v1/packages/<name>
|
||||
if (segs.size() == 4 && req.method == "PATCH") {
|
||||
if (!principal) {
|
||||
return HttpResponse::error_json(401, "unauthorized", "authentication required");
|
||||
}
|
||||
if (!check_csrf_locked(req, *principal)) {
|
||||
return HttpResponse::error_json(403, "csrf_failed",
|
||||
"missing or invalid CSRF token");
|
||||
}
|
||||
const auto pit = packages_.find(pkg_name);
|
||||
if (pit == packages_.end()) {
|
||||
return HttpResponse::error_json(404, "not_found", "package not found");
|
||||
}
|
||||
if (!can_publish_pkg(&pit->second)) {
|
||||
return HttpResponse::error_json(403, "forbidden",
|
||||
"insufficient publish authority or ownership");
|
||||
}
|
||||
auto parsed = Void::Json::Strict::parse(req.body);
|
||||
const auto *obj = parsed ? std::get_if<JsonVal::Object>(&parsed->value) : nullptr;
|
||||
if (!obj) {
|
||||
return HttpResponse::error_json(400, "invalid_request",
|
||||
"PATCH body must be a JSON object");
|
||||
}
|
||||
bool changed = false;
|
||||
if (const auto it = obj->find("description"); it != obj->end()) {
|
||||
const auto *value = std::get_if<std::string>(&it->second.value);
|
||||
if (!value || value->size() > 4096) {
|
||||
return HttpResponse::error_json(
|
||||
400, "invalid_description",
|
||||
"description must be a string of at most 4096 bytes");
|
||||
}
|
||||
pit->second.description = *value;
|
||||
changed = true;
|
||||
}
|
||||
if (const auto it = obj->find("private"); it != obj->end()) {
|
||||
const auto *value = std::get_if<bool>(&it->second.value);
|
||||
if (!value) {
|
||||
return HttpResponse::error_json(400, "invalid_private",
|
||||
"private must be a boolean");
|
||||
}
|
||||
pit->second.is_private = *value;
|
||||
changed = true;
|
||||
}
|
||||
if (!changed) {
|
||||
return HttpResponse::error_json(400, "invalid_request",
|
||||
"no updatable fields (description, private)");
|
||||
}
|
||||
append_audit_locked(principal->username, "package.update", pkg_name, "ok", "");
|
||||
if (auto saved = save_locked(); !saved) {
|
||||
return HttpResponse::error_json(500, "metadata_commit_failed",
|
||||
saved.error().message());
|
||||
}
|
||||
return HttpResponse::json(
|
||||
200, "{\"name\":" + json_quote(pkg_name) + ",\"description\":" +
|
||||
json_quote(pit->second.description) + ",\"is_private\":" +
|
||||
std::string{pit->second.is_private ? "true" : "false"} + "}\n");
|
||||
}
|
||||
|
||||
// Owners: GET/PUT/DELETE /api/v1/packages/<name>/owners[/<user>]
|
||||
if ((segs.size() == 5 || segs.size() == 6) && segs[4] == "owners") {
|
||||
const auto pit = packages_.find(pkg_name);
|
||||
|
||||
Reference in new issue
Block a user