feat(package,daemon): show binary variant details; list installed files
This commit is contained in:
1 parent
b8c362917f
commit
27d909fdad
10 files changed
+145
-1
No files matched your search
+28
-1
@@ -54,7 +54,8 @@
|
||||
// The daemon control socket is a POSIX Unix-domain socket (Linux/macOS). Windows support is
|
||||
// planned (Track C3) and would need a named-pipe transport instead.
|
||||
#if defined(_WIN32)
|
||||
#error "The vbs daemon Unix-socket transport requires a POSIX host (Track C3 Windows port is planned)."
|
||||
#error \
|
||||
"The vbs daemon Unix-socket transport requires a POSIX host (Track C3 Windows port is planned)."
|
||||
#endif
|
||||
#include <vector>
|
||||
|
||||
@@ -75,6 +76,8 @@ constexpr std::size_t kMaxDescribeTargetNames = 128U;
|
||||
constexpr std::size_t kMaxDescribeTargetNameBytes = 200U;
|
||||
constexpr std::size_t kMaxDoctorToolPathBytes = 4096U;
|
||||
constexpr std::size_t kMaxBuildTargets = 64U;
|
||||
constexpr std::size_t kMaxInstallFiles = 128U;
|
||||
constexpr std::size_t kMaxInstallPathBytes = 512U;
|
||||
constexpr std::size_t kMaxCompdbArguments = 256U;
|
||||
constexpr std::size_t kMaxCompdbArgumentBytes = 1024U;
|
||||
constexpr std::size_t kMaxCompdbEntries = 500U;
|
||||
@@ -982,6 +985,30 @@ std::string install_project_op(const DaemonOptions &options, State::StateStore &
|
||||
object.emplace("manifest", JsonValue{installed->manifest_path.string()});
|
||||
object.emplace("files",
|
||||
JsonValue{static_cast<std::int64_t>(installed->installed_files.size())});
|
||||
std::vector<std::string> installed_paths;
|
||||
installed_paths.reserve(installed->installed_files.size());
|
||||
for (const auto &file : installed->installed_files) {
|
||||
installed_paths.push_back(file.string());
|
||||
}
|
||||
std::ranges::sort(installed_paths);
|
||||
bool installed_files_truncated = false;
|
||||
if (installed_paths.size() > kMaxInstallFiles) {
|
||||
installed_paths.resize(kMaxInstallFiles);
|
||||
installed_files_truncated = true;
|
||||
}
|
||||
JsonValue::Array installed_files;
|
||||
installed_files.reserve(installed_paths.size());
|
||||
for (auto &path : installed_paths) {
|
||||
if (path.size() > kMaxInstallPathBytes) {
|
||||
path.resize(kMaxInstallPathBytes);
|
||||
installed_files_truncated = true;
|
||||
}
|
||||
installed_files.emplace_back(std::move(path));
|
||||
}
|
||||
object.emplace("installed_files", JsonValue{std::move(installed_files)});
|
||||
if (installed_files_truncated) {
|
||||
object.emplace("installed_files_truncated", JsonValue{true});
|
||||
}
|
||||
return serialize_response(JsonValue{std::move(object)});
|
||||
}
|
||||
|
||||
|
||||
@@ -1441,6 +1441,25 @@ int execute_binaries_command(std::string_view sub, const BinariesCmdOptions &opt
|
||||
}
|
||||
|
||||
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
||||
if (sub == "show") {
|
||||
if (!opts.variant_arg) {
|
||||
std::cerr << "vbs binaries show: --variant is required\n";
|
||||
return 2;
|
||||
}
|
||||
auto detail = Package::fetch_binary_detail(registry_url, *opts.name_arg, *opts.version_arg,
|
||||
*opts.variant_arg, auth);
|
||||
if (!detail) {
|
||||
std::cerr << "vbs binaries show: " << detail.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << "variant=" << detail->variant_id << " sha256=" << detail->sha256
|
||||
<< " size=" << detail->size_bytes
|
||||
<< " yanked=" << (detail->yanked ? "true" : "false")
|
||||
<< " signed=" << ((detail->signature && detail->public_key) ? "yes" : "no")
|
||||
<< '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Listing shows yanked variants (marked); fetch below only resolves non-yanked ones.
|
||||
auto variants = Package::fetch_binary_variants(registry_url, *opts.name_arg, *opts.version_arg,
|
||||
auth, sub == "list");
|
||||
@@ -2859,6 +2878,9 @@ int main(int argc, char **argv) {
|
||||
};
|
||||
configure_binaries(binaries_cmd.subcommand(
|
||||
"list", "List a release's binary variants (id, digest, size, signature state)"));
|
||||
auto &binaries_show_cmd = binaries_cmd.subcommand("show", "Show one binary variant's metadata");
|
||||
configure_binaries(binaries_show_cmd);
|
||||
binaries_show_cmd.option("--variant", "", "Binary variant id", binaries_opts.variant_arg);
|
||||
auto &binaries_fetch_cmd =
|
||||
binaries_cmd.subcommand("fetch", "Download one binary variant artifact");
|
||||
configure_binaries(binaries_fetch_cmd);
|
||||
|
||||
@@ -431,6 +431,61 @@ download_release_archive(std::string_view registry_url, std::string_view package
|
||||
return dest_file;
|
||||
}
|
||||
|
||||
Void::Result::Result<BinaryReleaseInfo, Void::Result::Error>
|
||||
fetch_binary_detail(std::string_view registry_url, std::string_view package_name,
|
||||
std::string_view version, std::string_view variant_id,
|
||||
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) + "/binaries/" +
|
||||
Void::Encoding::Url::encode(variant_id);
|
||||
auto reply = send_http_request(*parsed_url, "GET", path, headers, {});
|
||||
if (!reply) {
|
||||
return std::unexpected{reply.error()};
|
||||
}
|
||||
if (reply->status != 200) {
|
||||
return std::unexpected{
|
||||
make_error(reply->status == 404 ? Void::System::SystemErrorCode::not_found
|
||||
: reply->status == 401 || reply->status == 403
|
||||
? Void::System::SystemErrorCode::permission_denied
|
||||
: Void::System::SystemErrorCode::io_error,
|
||||
std::format("registry GET {} failed with HTTP {}", path, reply->status))};
|
||||
}
|
||||
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 binary endpoint")};
|
||||
}
|
||||
const auto *object = std::get_if<JsonVal::Object>(&json->value);
|
||||
if (!object) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||
"registry binary response must be a JSON object")};
|
||||
}
|
||||
BinaryReleaseInfo info;
|
||||
info.variant_id = get_str(*object, "variant_id");
|
||||
info.sha256 = get_str(*object, "sha256");
|
||||
info.size_bytes = static_cast<std::uint64_t>(get_i64(*object, "size_bytes", 0));
|
||||
info.yanked = get_bool(*object, "yanked", false);
|
||||
if (const auto sig = get_str(*object, "signature"); !sig.empty()) {
|
||||
info.signature = sig;
|
||||
}
|
||||
if (const auto key = get_str(*object, "public_key"); !key.empty()) {
|
||||
info.public_key = key;
|
||||
}
|
||||
if (info.variant_id.empty()) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||
"registry binary response is missing variant_id")};
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
Void::Result::Result<std::string, Void::Result::Error>
|
||||
publish_binary_variant(const BinaryPublishOptions &options) {
|
||||
if (!Void::Semver::parse_strict(options.version)) {
|
||||
|
||||
Reference in new issue
Block a user