feat: filter daemon actions by kind; show registry release detail
This commit is contained in:
1 parent
624016d904
commit
691560a369
11 files changed
+228
-21
No files matched your search
@@ -558,6 +558,66 @@ fetch_binary_variants(std::string_view registry_url, std::string_view package_na
|
||||
return variants;
|
||||
}
|
||||
|
||||
Void::Result::Result<ReleaseInfo, Void::Result::Error>
|
||||
fetch_release_detail(std::string_view registry_url, std::string_view package_name,
|
||||
std::string_view version, 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) + "/" +
|
||||
Void::Encoding::Url::encode(version);
|
||||
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 release 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")};
|
||||
}
|
||||
|
||||
ReleaseInfo info;
|
||||
info.name = get_str(*root, "name");
|
||||
info.version = get_str(*root, "version");
|
||||
info.sha256 = get_str(*root, "sha256");
|
||||
info.size_bytes = static_cast<std::uint64_t>(get_i64(*root, "size_bytes", 0));
|
||||
info.yanked = get_bool(*root, "yanked", false);
|
||||
if (const auto sig = get_str(*root, "signature"); !sig.empty()) {
|
||||
info.signature = sig;
|
||||
}
|
||||
if (const auto key = get_str(*root, "public_key"); !key.empty()) {
|
||||
info.public_key = key;
|
||||
}
|
||||
const auto bit = root->find("binaries");
|
||||
if (bit != root->end()) {
|
||||
if (const auto *binaries = std::get_if<JsonVal::Array>(&bit->second.value)) {
|
||||
info.binary_count = binaries->size();
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
Reference in new issue
Block a user