feat(package): add registry binary-variant client API and vbs publish-binary
This commit is contained in:
1 parent
663215f7f3
commit
8245a209a5
10 files changed
+290
-2
No files matched your search
@@ -102,7 +102,8 @@ All CLI help text (`vbs --help`, `vbs <command> --help`, `vbs compdb --help`, `v
|
||||
- `vbs install --prefix DIR [--project DIR] [--build-dir DIR] [--profile NAME] [--compiler gcc|clang] [--package-name NAME] [--package-version VER] [--component NAME] [--no-cmake-export] [--no-native-export]`
|
||||
- `vbs uninstall --prefix DIR`
|
||||
- `vbs pack [--project DIR] [--output FILE]`
|
||||
- `vbs publish --registry URL --name PKG --version X.Y.Z [--project DIR] [--description TEXT] [--token-env VAR] [--private]`
|
||||
- `vbs publish --registry URL --name PKG --version X.Y.Z [--project DIR] [--description TEXT] [--token-env VAR] [--signing-key FILE] [--private]`
|
||||
- `vbs publish-binary --registry URL --name PKG --version X.Y.Z --variant ID --file ARTIFACT [--signing-key FILE] [--token-env VAR]`
|
||||
- `vbs bridge --request FILE --output FILE` (backend for [cmake/bridge/VbsDeps.cmake](cmake/bridge/VbsDeps.cmake))
|
||||
- `vbs gc [--build-dir DIR] [--max-bytes N]`
|
||||
- `vbs daemon run|status|stop|gc|recover|describe|build|ide query|ide generate|ide poll|ide wait|compdb export [--project DIR] [--build-dir DIR] [--socket PATH]` (Unix-socket daemon holding a warm state store and project watcher; `run` serves in the foreground, the rest are client requests)
|
||||
|
||||
@@ -132,6 +132,10 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
|
||||
- `vbs-registry` now stores per-release binary variants (`BinaryReleaseMeta` in `ReleaseMeta`): `PUT /api/v1/packages/<name>/<version>/binaries/<variant>` (publish scope + CSRF, 128-byte bounded variant ids, upload/quota limits, optional `X-Binary-Signature`/`X-Binary-Public-Key` with 128/64-hex validation, idempotent same-digest and 409 immutable conflicts) and `GET .../binaries/<variant>/download` (read permission, CAS integrity re-verification). Metadata persists in the registry database and is listed in package detail JSON.
|
||||
- `RegistryTests.registry_binary_variant_publish_download_and_materialize`: unauthorized publish rejected, malformed signature rejected, signed artifact published and listed, downloaded byte-for-byte, conflicting digest rejected, and the registry-served artifact materialized through the signed `materialize_binary_variant` path.
|
||||
|
||||
- **Wave 29 (RegistryClient Binary-Variant API & Signed CLI Publish)**:
|
||||
- Added `Package::publish_binary_variant` (reads the artifact, computes SHA-256, optionally signs the canonical binary message with `--signing-key`, sends `X-Binary-Signature`/`X-Binary-Public-Key`) and `Package::fetch_binary_variants` (parses a release's binary list from the registry detail JSON) in `RegistryClient`.
|
||||
- Wired `vbs publish-binary --registry --name --version --variant --file [--signing-key] [--token-env]` into `src/Main.cpp`; the registry binary-variant test now publishes/lists through the client API in addition to the loopback endpoint checks.
|
||||
|
||||
## Remaining future scope
|
||||
|
||||
- **Post-v1 Expansion Roadmap ([21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md) & [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md))**: Live `conan` CLI verification (Track B3), Track C (macOS/Windows ports + dual-profile cross-compilation), Track D3 signing (SBOM, Ed25519 primitives, trusted-key enforcement and distribution, binary-variant signing and distribution materialization, the #52 built-in-backend capability probe, and the VoidLibrary pin bump to `0002e74` done), Track E3 (daemon core, bounded `describe`, build-serving, dependency materialization, daemon-backed IDE metadata, compdb export, IDE config generation, editor watch poll and bounded long-poll done; dedicated external editor plugins remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope.
|
||||
|
||||
@@ -35,4 +35,5 @@ Base HEAD: `fe0d1a6`
|
||||
| Wave 26 (Track E3 editor watch protocol) | `watch_poll` daemon request + `vbs daemon ide poll`: drains the warm watcher, buffers bounded changed paths, returns sequence/events/changed/overflow state | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 12/12, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs |
|
||||
| Wave 27 (Track E3 editor long-poll watch) | `watch_wait` daemon request + `vbs daemon ide wait --timeout-ms`: bounded 0-5000 ms long poll over the warm watcher returning changed paths/sequence/timed_out | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 13/13, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs |
|
||||
| Wave 28 (Registry binary-variant endpoints) | `BinaryReleaseMeta` storage, `PUT .../binaries/<variant>` + `GET .../binaries/<variant>/download`, metadata persistence/detail listing, signature header validation, immutable conflicts | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry suite 6/6, full CTest 8/8) | `registry/include/Void/Build/Registry/RegistryService.hpp`, `registry/service/RegistryService.cpp`, `tests/RegistryTests.cpp`, docs |
|
||||
| Wave 29 (RegistryClient binary API + signed CLI) | `publish_binary_variant`/`fetch_binary_variants` in RegistryClient; `vbs publish-binary` CLI with optional signing; registry test extended | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry suite 6/6, full CTest 8/8) | `include/Void/Build/Package/RegistryClient.hpp`, `src/Package/RegistryClient.cpp`, `src/Main.cpp`, `tests/RegistryTests.cpp`, `tests/CliContracts.cmake`, docs |
|
||||
| Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions, E4, live `conan`) | Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) |
|
||||
@@ -523,6 +523,21 @@ dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure
|
||||
- Full CTest: **8 / 8 passed** in 223.58 s.
|
||||
- `clang-format --dry-run --Werror` passes on the changed C++ files.
|
||||
|
||||
## RegistryClient Binary-Variant API & `vbs publish-binary` (GCC 16.2, pin `0002e74`)
|
||||
|
||||
```sh
|
||||
dev cpp-gcc -c cmake --build build/pinned --parallel 8
|
||||
dev cpp-gcc -c build/pinned/bin/vbs_registry_tests --no-color
|
||||
dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure
|
||||
```
|
||||
|
||||
- Build: exit 0. Registry suite: **6 / 6 passed** in 11.96 s; the binary-variant test now also
|
||||
publishes a signed variant through `Package::publish_binary_variant` and lists it back with
|
||||
`Package::fetch_binary_variants` (matching SHA-256, signature and public key present).
|
||||
- `vbs publish-binary --help` and the missing-argument error are covered by `vbs_cli_contract`.
|
||||
- Full CTest: **8 / 8 passed** in 206.08 s.
|
||||
- `clang-format --dry-run --Werror` passes on the changed C++ files.
|
||||
|
||||
## Limits and Unrun Checks
|
||||
|
||||
1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified).
|
||||
|
||||
@@ -61,7 +61,7 @@ flowchart LR
|
||||
| --- | --- | --- |
|
||||
| **D1 — Shared HTTP Content-Addressed Action Cache (CAS)** *(verified: cross-build-directory 100% cache hit)* | Push/pull action records and output blobs (`PUT/GET /api/v1/cas/blobs/{sha256}`, `/api/v1/cas/actions/{action_key}`) against `vbs-registry` or any compatible HTTP CAS server with bearer auth and digest verification on every read. Action keys are normalized to be build-directory independent; `vbs build/test --remote-cache URL [--remote-cache-token-env VAR]` (or `VBS_REMOTE_CACHE` / `VBS_REMOTE_CACHE_TOKEN`). | Cold CI build populates remote CAS; second clean machine achieves 100% cache hit with verified SHA-256 outputs. |
|
||||
| **D2 — Fast Hashing & Parallel Snapshot Pipeline** *(verified: 5,001-file warm no-op 374 ms)* | Adopt `Void::Crypto` BLAKE2b / hardware-accelerated SHA-256 (when available) + parallel snapshot hashing across `Void::Concurrency::ThreadPool` + optional `Void::Sqlite` indexed state store for >10k-file monorepos. Snapshot capture revalidation now hashes on a bounded thread pool for trees of 32+ files. | Sub-second warm no-op on 5,000-file synthetic benchmark fixture (`vbs_benchmarks`). |
|
||||
| **D3 — Supply-Chain Provenance & Signed Packages** *(SBOM, Ed25519 signing primitives, and trusted-key enforcement implemented; OpenSSL or the built-in Ed25519 backend)* | Emit SPDX/CycloneDX SBOM JSON from `vbs.lock` + `BuildGraph` (`vbs build/test --sbom FILE --sbom-format spdx\|cyclonedx`, `src/Provenance/Sbom.cpp`); Ed25519 detached-signature primitives in `Void::Build::Provenance::Signing` (`include/Void/Build/Provenance/Signing.hpp`, `src/Provenance/Signing.cpp`): 0600 seed generation, public-key derivation, canonical `vbs-package-v1` package message, and sign/verify; package signature/public-key metadata persisted in `vbs.lock` and registry releases; `vbs publish --signing-key FILE`; `vbs build\|test --trusted-public-key HEX` enforced before extraction via `Provenance::verify_trusted_package_signature` (`include/Void/Build/Provenance/Verification.hpp`); trusted keys can also come from `--trusted-key-file`, a project `vbs.keys` ring, or `VBS_TRUSTED_PUBLIC_KEYS` (`Provenance::load_trusted_keys`); prebuilt binary variants carry optional signatures verified by `select_compatible_signed_binary` over the canonical `vbs-binary-v1` message, `materialize_binary_variant` downloads digest-verified artifacts with cached-digest revalidation, and `vbs-registry` stores/serves per-release binary variants with optional signature metadata. | SBOM is deterministic and valid JSON; signing primitives pass round-trip/tamper/malformed tests (`tests/SigningTests.cpp`); trusted-key policy tests pass with and without OpenSSL (`tests/SignatureEnforcementTests.cpp`); a signed publish -> deps update -> `--locked` trusted build succeeds and an untrusted/unsigned package fails closed before extraction (`RegistryTests.cpp`). |
|
||||
| **D3 — Supply-Chain Provenance & Signed Packages** *(SBOM, Ed25519 signing primitives, and trusted-key enforcement implemented; OpenSSL or the built-in Ed25519 backend)* | Emit SPDX/CycloneDX SBOM JSON from `vbs.lock` + `BuildGraph` (`vbs build/test --sbom FILE --sbom-format spdx\|cyclonedx`, `src/Provenance/Sbom.cpp`); Ed25519 detached-signature primitives in `Void::Build::Provenance::Signing` (`include/Void/Build/Provenance/Signing.hpp`, `src/Provenance/Signing.cpp`): 0600 seed generation, public-key derivation, canonical `vbs-package-v1` package message, and sign/verify; package signature/public-key metadata persisted in `vbs.lock` and registry releases; `vbs publish --signing-key FILE`; `vbs build\|test --trusted-public-key HEX` enforced before extraction via `Provenance::verify_trusted_package_signature` (`include/Void/Build/Provenance/Verification.hpp`); trusted keys can also come from `--trusted-key-file`, a project `vbs.keys` ring, or `VBS_TRUSTED_PUBLIC_KEYS` (`Provenance::load_trusted_keys`); prebuilt binary variants carry optional signatures verified by `select_compatible_signed_binary` over the canonical `vbs-binary-v1` message, `materialize_binary_variant` downloads digest-verified artifacts with cached-digest revalidation, `vbs-registry` stores/serves per-release binary variants with optional signature metadata, and `vbs publish-binary` publishes signed variants through `RegistryClient`. | SBOM is deterministic and valid JSON; signing primitives pass round-trip/tamper/malformed tests (`tests/SigningTests.cpp`); trusted-key policy tests pass with and without OpenSSL (`tests/SignatureEnforcementTests.cpp`); a signed publish -> deps update -> `--locked` trusted build succeeds and an untrusted/unsigned package fails closed before extraction (`RegistryTests.cpp`). |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -47,6 +47,34 @@ download_release_archive(std::string_view registry_url, std::string_view package
|
||||
std::string_view version, std::string_view expected_sha256,
|
||||
const std::filesystem::path &dest_file, const RegistryAuth &auth = {});
|
||||
|
||||
struct BinaryPublishOptions {
|
||||
std::string registry_url;
|
||||
std::string package_name;
|
||||
std::string version;
|
||||
std::string variant_id;
|
||||
std::filesystem::path artifact_path;
|
||||
std::optional<std::filesystem::path> signing_seed_path;
|
||||
RegistryAuth auth;
|
||||
};
|
||||
|
||||
struct BinaryReleaseInfo {
|
||||
std::string variant_id;
|
||||
std::string sha256;
|
||||
std::uint64_t size_bytes{0};
|
||||
std::optional<std::string> signature;
|
||||
std::optional<std::string> public_key;
|
||||
};
|
||||
|
||||
// Publishes a prebuilt binary variant for an existing release (optionally Ed25519-signed over
|
||||
// the canonical binary message) and returns the artifact SHA-256.
|
||||
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
|
||||
publish_binary_variant(const BinaryPublishOptions &options);
|
||||
|
||||
// Lists the binary variants stored for one release.
|
||||
[[nodiscard]] Void::Result::Result<std::vector<BinaryReleaseInfo>, Void::Result::Error>
|
||||
fetch_binary_variants(std::string_view registry_url, std::string_view package_name,
|
||||
std::string_view version, const RegistryAuth &auth = {});
|
||||
|
||||
// Downloads a prebuilt binary artifact from an absolute http(s) URL into `dest_file`,
|
||||
// rejecting any content whose SHA-256 differs from `expected_sha256` (verified before writing).
|
||||
[[nodiscard]] Void::Result::Result<std::filesystem::path, Void::Result::Error>
|
||||
|
||||
@@ -1109,6 +1109,48 @@ int execute_bridge_command(const BridgeCmdOptions &opts) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct PublishBinaryCmdOptions {
|
||||
std::optional<std::string> registry_arg;
|
||||
std::optional<std::string> name_arg;
|
||||
std::optional<std::string> version_arg;
|
||||
std::optional<std::string> variant_arg;
|
||||
std::optional<std::string> file_arg;
|
||||
std::optional<std::string> signing_key_arg;
|
||||
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
||||
};
|
||||
|
||||
int execute_publish_binary_command(const PublishBinaryCmdOptions &opts) {
|
||||
const std::string registry_url = opts.registry_arg
|
||||
? *opts.registry_arg
|
||||
: Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
|
||||
if (registry_url.empty() || !opts.name_arg || !opts.version_arg || !opts.variant_arg ||
|
||||
!opts.file_arg) {
|
||||
std::cerr << "vbs publish-binary: --registry, --name, --version, --variant, and --file "
|
||||
"are required\n";
|
||||
return 2;
|
||||
}
|
||||
Package::BinaryPublishOptions popts;
|
||||
popts.registry_url = registry_url;
|
||||
popts.package_name = *opts.name_arg;
|
||||
popts.version = *opts.version_arg;
|
||||
popts.variant_id = *opts.variant_arg;
|
||||
popts.artifact_path = std::filesystem::path{*opts.file_arg};
|
||||
popts.auth.bearer_token = Void::Configuration::get_env_or(opts.token_env, "");
|
||||
if (opts.signing_key_arg) {
|
||||
popts.signing_seed_path = std::filesystem::path{*opts.signing_key_arg};
|
||||
}
|
||||
Void::Log::info("Publish", "Uploading binary variant {}@{}/{} to {}...", popts.package_name,
|
||||
popts.version, popts.variant_id, registry_url);
|
||||
auto sha = Package::publish_binary_variant(popts);
|
||||
if (!sha) {
|
||||
std::cerr << "vbs publish-binary: " << sha.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << "published binary " << popts.package_name << '@' << popts.version << '/'
|
||||
<< popts.variant_id << " sha256=" << *sha << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct PackCmdOptions {
|
||||
std::string project_arg;
|
||||
std::string out_arg{"package.tar"};
|
||||
@@ -2179,6 +2221,7 @@ int main(int argc, char **argv) {
|
||||
PackCmdOptions pack_opts;
|
||||
pack_opts.project_arg = cwd;
|
||||
PublishCmdOptions publish_opts;
|
||||
PublishBinaryCmdOptions publish_binary_opts;
|
||||
publish_opts.project_arg = cwd;
|
||||
BridgeCmdOptions bridge_opts;
|
||||
GcCmdOptions gc_opts;
|
||||
@@ -2327,6 +2370,21 @@ int main(int argc, char **argv) {
|
||||
uninstall_opts.prefix_arg);
|
||||
add_log_flags(uninstall_cmd);
|
||||
|
||||
auto &publish_binary_cmd = root.subcommand(
|
||||
"publish-binary", "Publish a prebuilt binary variant to a VBS package registry");
|
||||
publish_binary_cmd
|
||||
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
||||
publish_binary_opts.registry_arg)
|
||||
.option("--name", "-n", "Package name", publish_binary_opts.name_arg)
|
||||
.option("--version", "-v", "Release version", publish_binary_opts.version_arg)
|
||||
.option("--variant", "", "Binary variant id", publish_binary_opts.variant_arg)
|
||||
.option("--file", "-f", "Prebuilt artifact file", publish_binary_opts.file_arg)
|
||||
.option("--signing-key", "", "Ed25519 signing seed file (64 hex characters)",
|
||||
publish_binary_opts.signing_key_arg)
|
||||
.option_default("--token-env", "", "Environment variable holding bearer token",
|
||||
publish_binary_opts.token_env, "VBS_REGISTRY_TOKEN");
|
||||
add_log_flags(publish_binary_cmd, false); // `-v` is `--version` on publish-binary.
|
||||
|
||||
auto &pack_cmd = root.subcommand("pack", "Create a deterministic USTAR source archive (.tar)");
|
||||
pack_cmd.option_default("--project", "-C", "Project directory", pack_opts.project_arg, cwd)
|
||||
.option_default("--output", "-o", "Output archive path", pack_opts.out_arg, "package.tar");
|
||||
@@ -2553,6 +2611,9 @@ int main(int argc, char **argv) {
|
||||
if (cmd == "publish") {
|
||||
return execute_publish_command(publish_opts);
|
||||
}
|
||||
if (cmd == "publish-binary") {
|
||||
return execute_publish_binary_command(publish_binary_opts);
|
||||
}
|
||||
if (cmd == "bridge") {
|
||||
return execute_bridge_command(bridge_opts);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Provenance/Signing.hpp>
|
||||
#include <Void/Build/Provenance/Verification.hpp>
|
||||
#include <Void/Build/Util/Sha256.hpp>
|
||||
#include <Void/Core/Scope.hpp>
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
@@ -268,6 +269,15 @@ bool get_bool(const JsonVal::Object &obj, const std::string &k, bool def = false
|
||||
return b ? *b : def;
|
||||
}
|
||||
|
||||
std::int64_t get_i64(const JsonVal::Object &obj, const std::string &k, std::int64_t def = 0) {
|
||||
const auto it = obj.find(k);
|
||||
if (it == obj.end()) {
|
||||
return def;
|
||||
}
|
||||
const auto *i = std::get_if<std::int64_t>(&it->second.value);
|
||||
return i ? *i : def;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Void::Result::Result<std::vector<ReleaseRecord>, Void::Result::Error>
|
||||
@@ -379,6 +389,143 @@ download_release_archive(std::string_view registry_url, std::string_view package
|
||||
return dest_file;
|
||||
}
|
||||
|
||||
Void::Result::Result<std::string, Void::Result::Error>
|
||||
publish_binary_variant(const BinaryPublishOptions &options) {
|
||||
if (!Void::Semver::parse_strict(options.version)) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::invalid_argument,
|
||||
"binary variant version must be strict SemVer")};
|
||||
}
|
||||
if (options.variant_id.empty()) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::invalid_argument,
|
||||
"binary variant id must not be empty")};
|
||||
}
|
||||
auto parsed_url = parse_registry_url(options.registry_url);
|
||||
if (!parsed_url) {
|
||||
return std::unexpected{parsed_url.error()};
|
||||
}
|
||||
auto bytes = Void::FileSystem::read_file(options.artifact_path);
|
||||
if (!bytes) {
|
||||
return std::unexpected{bytes.error()};
|
||||
}
|
||||
const std::string sha = Util::sha256_hex(*bytes);
|
||||
|
||||
std::map<std::string, std::string, std::less<>> headers;
|
||||
headers["X-Content-SHA256"] = sha;
|
||||
if (!options.auth.bearer_token.empty()) {
|
||||
headers["Authorization"] = "Bearer " + options.auth.bearer_token;
|
||||
}
|
||||
if (options.signing_seed_path) {
|
||||
const std::string message = Provenance::canonical_binary_message(options.variant_id, sha);
|
||||
auto signature = Provenance::sign_message(
|
||||
std::as_bytes(std::span<const char>{message.data(), message.size()}),
|
||||
*options.signing_seed_path);
|
||||
if (!signature) {
|
||||
return std::unexpected{signature.error()};
|
||||
}
|
||||
auto public_key = Provenance::public_key_from_seed(*options.signing_seed_path);
|
||||
if (!public_key) {
|
||||
return std::unexpected{public_key.error()};
|
||||
}
|
||||
headers["X-Binary-Signature"] = *signature;
|
||||
headers["X-Binary-Public-Key"] = *public_key;
|
||||
}
|
||||
|
||||
const std::string path = "/api/v1/packages/" +
|
||||
Void::Encoding::Url::encode(options.package_name) + "/" +
|
||||
Void::Encoding::Url::encode(options.version) + "/binaries/" +
|
||||
Void::Encoding::Url::encode(options.variant_id);
|
||||
auto reply = send_http_request(*parsed_url, "PUT", path, headers, *bytes);
|
||||
if (!reply) {
|
||||
return std::unexpected{reply.error()};
|
||||
}
|
||||
if (reply->status != 200 && reply->status != 201) {
|
||||
return std::unexpected{make_error(
|
||||
reply->status == 409 ? Void::System::SystemErrorCode::already_exists
|
||||
: Void::System::SystemErrorCode::permission_denied,
|
||||
std::format("registry binary publish {}@{}/{} failed with HTTP {}",
|
||||
options.package_name, options.version, options.variant_id, reply->status))};
|
||||
}
|
||||
return sha;
|
||||
}
|
||||
|
||||
Void::Result::Result<std::vector<BinaryReleaseInfo>, Void::Result::Error>
|
||||
fetch_binary_variants(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);
|
||||
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
|
||||
: 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 package 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<BinaryReleaseInfo> variants;
|
||||
const auto rit = root->find("releases");
|
||||
if (rit == root->end()) {
|
||||
return variants;
|
||||
}
|
||||
const auto *releases = std::get_if<JsonVal::Array>(&rit->second.value);
|
||||
if (!releases) {
|
||||
return variants;
|
||||
}
|
||||
for (const auto &rv : *releases) {
|
||||
const auto *ro = std::get_if<JsonVal::Object>(&rv.value);
|
||||
if (!ro || get_str(*ro, "version") != version) {
|
||||
continue;
|
||||
}
|
||||
const auto bit = ro->find("binaries");
|
||||
if (bit == ro->end()) {
|
||||
continue;
|
||||
}
|
||||
const auto *binaries = std::get_if<JsonVal::Array>(&bit->second.value);
|
||||
if (!binaries) {
|
||||
continue;
|
||||
}
|
||||
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));
|
||||
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;
|
||||
}
|
||||
if (!info.variant_id.empty()) {
|
||||
variants.push_back(std::move(info));
|
||||
}
|
||||
}
|
||||
}
|
||||
return variants;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -44,6 +44,8 @@ check_process(2 "" "--prefix is required" install)
|
||||
check_process(2 "" "--prefix is required" uninstall)
|
||||
check_process(2 "" "--input and --output-dir are required" gen-tests)
|
||||
check_process(0 "Usage: vbs publish " "" publish --help)
|
||||
check_process(0 "Usage: vbs publish-binary " "" publish-binary --help)
|
||||
check_process(2 "" "--registry, --name, --version, --variant, and --file are required" publish-binary)
|
||||
check_process(2 "" "--registry, --name, and --version are required" publish)
|
||||
check_process(0 "Usage: vbs daemon <command>.*Commands:.*run.*status.*stop.*recover.*gc.*describe" "" daemon --help)
|
||||
check_process(0 "Usage: vbs daemon run " "" daemon run --help)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <Void/Build/BootstrapConfig.hpp>
|
||||
#include <Void/Build/Package/Archive.hpp>
|
||||
#include <Void/Build/Package/Fetch.hpp>
|
||||
#include <Void/Build/Package/RegistryClient.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Provenance/Signing.hpp>
|
||||
@@ -615,6 +616,34 @@ VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materializ
|
||||
Void::Testing::require(cached.has_value());
|
||||
Void::Testing::expect(*cached == artifact);
|
||||
|
||||
// Client API: publish a signed variant and list it back.
|
||||
const auto client_artifact = tmp / "client-artifact.bin";
|
||||
(void)Platform::atomic_write_file(client_artifact, "CLIENT_BINARY_ARTIFACT", false);
|
||||
Package::BinaryPublishOptions binary_publish;
|
||||
binary_publish.registry_url = reg_url;
|
||||
binary_publish.package_name = "demo-bin";
|
||||
binary_publish.version = "1.0.0";
|
||||
binary_publish.variant_id = "client-variant";
|
||||
binary_publish.artifact_path = client_artifact;
|
||||
binary_publish.signing_seed_path = seed_path;
|
||||
binary_publish.auth = Package::RegistryAuth{*tok};
|
||||
auto client_sha = Package::publish_binary_variant(binary_publish);
|
||||
Void::Testing::require(client_sha.has_value());
|
||||
|
||||
auto variants =
|
||||
Package::fetch_binary_variants(reg_url, "demo-bin", "1.0.0", Package::RegistryAuth{*tok});
|
||||
Void::Testing::require(variants.has_value());
|
||||
bool found_client_variant = false;
|
||||
for (const auto &info : *variants) {
|
||||
if (info.variant_id == "client-variant") {
|
||||
found_client_variant = true;
|
||||
Void::Testing::expect(info.sha256 == *client_sha);
|
||||
Void::Testing::expect(info.signature.has_value());
|
||||
Void::Testing::expect(info.public_key.has_value());
|
||||
}
|
||||
}
|
||||
Void::Testing::expect(found_client_variant);
|
||||
|
||||
(*svc)->stop_http();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user