feat(registry): yank binary variants and exclude them from selection
This commit is contained in:
1 parent
502f2b0c51
commit
66d2fa6a2e
9 files changed
+116
-7
No files matched your search
@@ -46,6 +46,7 @@ struct BinaryReleaseMeta {
|
||||
std::string variant_id;
|
||||
std::string sha256;
|
||||
std::uint64_t size_bytes{0};
|
||||
bool yanked{false};
|
||||
std::string signature; // Ed25519 signature hex; empty = unsigned artifact.
|
||||
std::string public_key; // Ed25519 public key hex; empty = unsigned artifact.
|
||||
std::string publisher;
|
||||
|
||||
@@ -310,6 +310,7 @@ Void::Result::Result<void, Void::Result::Error> RegistryService::load_locked() {
|
||||
bm.sha256 = get_str(*bo, "sha256");
|
||||
bm.size_bytes = static_cast<std::uint64_t>(
|
||||
get_i64(*bo, "size_bytes", 0));
|
||||
bm.yanked = get_bool(*bo, "yanked", false);
|
||||
bm.signature = get_str(*bo, "signature");
|
||||
bm.public_key = get_str(*bo, "public_key");
|
||||
bm.publisher = get_str(*bo, "publisher");
|
||||
@@ -413,7 +414,8 @@ Void::Result::Result<void, Void::Result::Error> RegistryService::save_locked() {
|
||||
return "{\"variant_id\":" + json_quote(b.variant_id) +
|
||||
",\"sha256\":" + json_quote(b.sha256) +
|
||||
",\"size_bytes\":" +
|
||||
std::to_string(b.size_bytes) +
|
||||
std::to_string(b.size_bytes) + ",\"yanked\":" +
|
||||
std::string{b.yanked ? "true" : "false"} +
|
||||
",\"signature\":" + json_quote(b.signature) +
|
||||
",\"public_key\":" + json_quote(b.public_key) +
|
||||
",\"publisher\":" + json_quote(b.publisher) +
|
||||
@@ -852,7 +854,8 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
return "{\"variant_id\":" + json_quote(b.variant_id) +
|
||||
",\"sha256\":" + json_quote(b.sha256) +
|
||||
",\"size_bytes\":" +
|
||||
std::to_string(b.size_bytes) +
|
||||
std::to_string(b.size_bytes) + ",\"yanked\":" +
|
||||
std::string{b.yanked ? "true" : "false"} +
|
||||
",\"signature\":" + json_quote(b.signature) +
|
||||
",\"public_key\":" + json_quote(b.public_key) +
|
||||
'}';
|
||||
@@ -1131,9 +1134,15 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
copied.error().message());
|
||||
}
|
||||
}
|
||||
rit->second.binaries[variant_id] = BinaryReleaseMeta{
|
||||
variant_id, actual_sha, req.body.size(), binary_signature,
|
||||
binary_public_key, principal->username, now_epoch()};
|
||||
BinaryReleaseMeta binary_meta;
|
||||
binary_meta.variant_id = variant_id;
|
||||
binary_meta.sha256 = actual_sha;
|
||||
binary_meta.size_bytes = req.body.size();
|
||||
binary_meta.signature = binary_signature;
|
||||
binary_meta.public_key = binary_public_key;
|
||||
binary_meta.publisher = principal->username;
|
||||
binary_meta.published_epoch = now_epoch();
|
||||
rit->second.binaries[variant_id] = std::move(binary_meta);
|
||||
append_audit_locked(principal->username, "binary.publish",
|
||||
pkg_name + "@" + ver_str + "/" + variant_id, "ok",
|
||||
"sha256=" + actual_sha);
|
||||
@@ -1178,6 +1187,49 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
return resp;
|
||||
}
|
||||
|
||||
// Yank/unyank a binary variant:
|
||||
// POST /api/v1/packages/<name>/<version>/binaries/<variant>/yank
|
||||
if (segs.size() == 8 && segs[5] == "binaries" && segs[7] == "yank" &&
|
||||
req.method == "POST") {
|
||||
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 yank authority");
|
||||
}
|
||||
const auto rit = pit->second.releases.find(segs[4]);
|
||||
if (rit == pit->second.releases.end()) {
|
||||
return HttpResponse::error_json(404, "not_found", "release not found");
|
||||
}
|
||||
const auto bit = rit->second.binaries.find(segs[6]);
|
||||
if (bit == rit->second.binaries.end()) {
|
||||
return HttpResponse::error_json(404, "not_found", "binary variant not found");
|
||||
}
|
||||
bool yanked = true;
|
||||
if (!req.body.empty()) {
|
||||
if (auto parsed = Void::Json::Strict::parse(req.body); parsed) {
|
||||
if (const auto *obj = std::get_if<JsonVal::Object>(&parsed->value)) {
|
||||
yanked = get_bool(*obj, "yanked", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
bit->second.yanked = yanked;
|
||||
append_audit_locked(principal->username, yanked ? "binary.yank" : "binary.unyank",
|
||||
pkg_name + "@" + segs[4] + "/" + segs[6], "ok", "");
|
||||
(void)save_locked();
|
||||
return HttpResponse::json(
|
||||
200, "{\"variant_id\":" + json_quote(segs[6]) +
|
||||
",\"yanked\":" + std::string{yanked ? "true" : "false"} + "}\n");
|
||||
}
|
||||
|
||||
// Yank/unyank release: POST /api/v1/packages/<name>/<version>/yank
|
||||
if (segs.size() == 6 && segs[5] == "yank" && req.method == "POST") {
|
||||
if (!principal) {
|
||||
|
||||
Reference in new issue
Block a user