feat(registry): add a binary-variant listing endpoint
This commit is contained in:
1 parent
349ec257f5
commit
8f68ec56e9
7 files changed
+77
-38
No files matched your search
@@ -459,7 +459,8 @@ fetch_binary_variants(std::string_view registry_url, std::string_view package_na
|
||||
if (!auth.bearer_token.empty()) {
|
||||
headers["Authorization"] = "Bearer " + auth.bearer_token;
|
||||
}
|
||||
const std::string path = "/api/v1/packages/" + Void::Encoding::Url::encode(package_name);
|
||||
const std::string path = "/api/v1/packages/" + Void::Encoding::Url::encode(package_name) + "/" +
|
||||
Void::Encoding::Url::encode(version) + "/binaries";
|
||||
auto reply = send_http_request(*parsed_url, "GET", path, headers, {});
|
||||
if (!reply) {
|
||||
return std::unexpected{reply.error()};
|
||||
@@ -473,7 +474,7 @@ fetch_binary_variants(std::string_view registry_url, std::string_view package_na
|
||||
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 package endpoint")};
|
||||
"invalid JSON returned by registry binaries endpoint")};
|
||||
}
|
||||
const auto *root = std::get_if<JsonVal::Object>(&json->value);
|
||||
if (!root) {
|
||||
@@ -482,48 +483,34 @@ fetch_binary_variants(std::string_view registry_url, std::string_view package_na
|
||||
}
|
||||
|
||||
std::vector<BinaryReleaseInfo> variants;
|
||||
const auto rit = root->find("releases");
|
||||
if (rit == root->end()) {
|
||||
const auto bit = root->find("binaries");
|
||||
if (bit == root->end()) {
|
||||
return variants;
|
||||
}
|
||||
const auto *releases = std::get_if<JsonVal::Array>(&rit->second.value);
|
||||
if (!releases) {
|
||||
const auto *binaries = std::get_if<JsonVal::Array>(&bit->second.value);
|
||||
if (!binaries) {
|
||||
return variants;
|
||||
}
|
||||
for (const auto &rv : *releases) {
|
||||
const auto *ro = std::get_if<JsonVal::Object>(&rv.value);
|
||||
if (!ro || get_str(*ro, "version") != version) {
|
||||
for (const auto &bv : *binaries) {
|
||||
const auto *bo = std::get_if<JsonVal::Object>(&bv.value);
|
||||
if (!bo) {
|
||||
continue;
|
||||
}
|
||||
const auto bit = ro->find("binaries");
|
||||
if (bit == ro->end()) {
|
||||
continue;
|
||||
BinaryReleaseInfo info;
|
||||
info.variant_id = get_str(*bo, "variant_id");
|
||||
info.sha256 = get_str(*bo, "sha256");
|
||||
info.size_bytes = static_cast<std::uint64_t>(get_i64(*bo, "size_bytes", 0));
|
||||
info.yanked = get_bool(*bo, "yanked", false);
|
||||
if (const auto sig = get_str(*bo, "signature"); !sig.empty()) {
|
||||
info.signature = sig;
|
||||
}
|
||||
const auto *binaries = std::get_if<JsonVal::Array>(&bit->second.value);
|
||||
if (!binaries) {
|
||||
continue;
|
||||
if (const auto key = get_str(*bo, "public_key"); !key.empty()) {
|
||||
info.public_key = key;
|
||||
}
|
||||
for (const auto &bv : *binaries) {
|
||||
const auto *bo = std::get_if<JsonVal::Object>(&bv.value);
|
||||
if (!bo) {
|
||||
continue;
|
||||
}
|
||||
BinaryReleaseInfo info;
|
||||
info.variant_id = get_str(*bo, "variant_id");
|
||||
info.sha256 = get_str(*bo, "sha256");
|
||||
info.size_bytes = static_cast<std::uint64_t>(get_i64(*bo, "size_bytes", 0));
|
||||
info.yanked = get_bool(*bo, "yanked", false);
|
||||
if (const auto sig = get_str(*bo, "signature"); !sig.empty()) {
|
||||
info.signature = sig;
|
||||
}
|
||||
if (const auto key = get_str(*bo, "public_key"); !key.empty()) {
|
||||
info.public_key = key;
|
||||
}
|
||||
// Yanked variants are hidden by default so they are never selected for
|
||||
// materialization; listing callers can opt in for inspection.
|
||||
if (!info.variant_id.empty() && (include_yanked || !info.yanked)) {
|
||||
variants.push_back(std::move(info));
|
||||
}
|
||||
// Yanked variants are hidden by default so they are never selected for
|
||||
// materialization; listing callers can opt in for inspection.
|
||||
if (!info.variant_id.empty() && (include_yanked || !info.yanked)) {
|
||||
variants.push_back(std::move(info));
|
||||
}
|
||||
}
|
||||
return variants;
|
||||
|
||||
Reference in new issue
Block a user