feat(package): read package owners through the registry client
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 8s

This commit is contained in:
faumaray committed 2026-12-04 04:02:23 +03:00
1 parent eb4af6f3d2
commit 105519924a
7 files changed
+106 -1

No files matched your search

+57
View File
@@ -558,6 +558,63 @@ fetch_binary_variants(std::string_view registry_url, std::string_view package_na
return variants;
}
Void::Result::Result<std::vector<std::string>, Void::Result::Error>
fetch_package_owners(std::string_view registry_url, std::string_view package_name,
const RegistryAuth &auth) {
auto parsed_url = parse_registry_url(registry_url);
if (!parsed_url) {
return std::unexpected{parsed_url.error()};
}
std::map<std::string, std::string, std::less<>> headers;
if (!auth.bearer_token.empty()) {
headers["Authorization"] = "Bearer " + auth.bearer_token;
}
const std::string path =
"/api/v1/packages/" + Void::Encoding::Url::encode(package_name) + "/owners";
auto reply = send_http_request(*parsed_url, "GET", path, headers, {});
if (!reply) {
return std::unexpected{reply.error()};
}
if (reply->status != 200) {
auto code = Void::System::SystemErrorCode::io_error;
if (reply->status == 404) {
code = Void::System::SystemErrorCode::not_found;
} else if (reply->status == 401 || reply->status == 403) {
code = Void::System::SystemErrorCode::permission_denied;
}
return std::unexpected{
make_error(code, std::format("registry GET {} failed with HTTP {}: {}", path,
reply->status, reply->body))};
}
auto json = Void::Json::Strict::parse(reply->body);
if (!json) {
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
"invalid JSON returned by registry owners endpoint")};
}
const auto *root = std::get_if<JsonVal::Object>(&json->value);
if (!root) {
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
"registry response root must be a JSON object")};
}
std::vector<std::string> owners;
const auto oit = root->find("owners");
if (oit == root->end()) {
return owners;
}
const auto *array = std::get_if<JsonVal::Array>(&oit->second.value);
if (!array) {
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
"registry owners field must be a JSON array")};
}
owners.reserve(array->size());
for (const auto &entry : *array) {
if (const auto *name = std::get_if<std::string>(&entry.value); name && !name->empty()) {
owners.push_back(*name);
}
}
return owners;
}
Void::Result::Result<std::filesystem::path, Void::Result::Error>
download_binary_artifact(std::string_view url, std::string_view expected_sha256,
const std::filesystem::path &dest_file, const RegistryAuth &auth) {