143 lines
6.0 KiB
C++
143 lines
6.0 KiB
C++
#pragma once
|
|
|
|
#include <Void/Build/Package/Solver.hpp>
|
|
#include <Void/Functional/Error.hpp>
|
|
#include <Void/Functional/Result.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace Void::Build::Package {
|
|
|
|
struct RegistryAuth {
|
|
std::string bearer_token; // Runtime-only; never written to locks or logs.
|
|
};
|
|
|
|
struct PublishOptions {
|
|
std::string registry_url;
|
|
std::string package_name;
|
|
std::string version;
|
|
std::filesystem::path archive_path;
|
|
std::string description;
|
|
bool is_private{false};
|
|
RegistryAuth auth;
|
|
// Optional Ed25519 signing seed (64 hex chars). When set, the published release carries
|
|
// X-Package-Signature / X-Package-Public-Key over the canonical package message.
|
|
std::optional<std::filesystem::path> signing_seed_path;
|
|
};
|
|
|
|
struct PublishReceipt {
|
|
std::string sha256;
|
|
bool already_published{false};
|
|
};
|
|
|
|
struct TokenInfo {
|
|
std::string token_id;
|
|
std::string username;
|
|
std::string label;
|
|
std::vector<std::string> scopes;
|
|
bool revoked{false};
|
|
};
|
|
|
|
// Lists the caller's (or, for admins, all) API token metadata from GET /api/v1/tokens.
|
|
// The plaintext secret is never returned by the registry after creation.
|
|
[[nodiscard]] Void::Result::Result<std::vector<TokenInfo>, Void::Result::Error>
|
|
fetch_tokens(std::string_view registry_url, const RegistryAuth &auth = {});
|
|
|
|
// Marks a release yanked or unyanked via POST .../<version>/yank (bearer tokens are exempt
|
|
// from CSRF; owner or admin authority required). Returns the resulting yank state.
|
|
[[nodiscard]] Void::Result::Result<bool, Void::Result::Error>
|
|
set_release_yanked(std::string_view registry_url, std::string_view package_name,
|
|
std::string_view version, bool yanked, const RegistryAuth &auth = {});
|
|
|
|
// Revokes one API token via DELETE /api/v1/tokens/<token_id> (owner or admin only).
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
|
revoke_token(std::string_view registry_url, std::string_view token_id,
|
|
const RegistryAuth &auth = {});
|
|
|
|
// Queries GET /api/v1/packages/<name> on a VBS registry and parses all release records
|
|
// into Package::ReleaseRecord entries ready for PackageIndex + PubGrub solving.
|
|
[[nodiscard]] Void::Result::Result<std::vector<ReleaseRecord>, Void::Result::Error>
|
|
fetch_package_releases(std::string_view registry_url, std::string_view package_name,
|
|
const RegistryAuth &auth = {});
|
|
|
|
// Downloads GET /api/v1/packages/<name>/<version>/download, verifies SHA-256 against
|
|
// `expected_sha256` before atomic publication to `dest_file`.
|
|
[[nodiscard]] Void::Result::Result<std::filesystem::path, Void::Result::Error>
|
|
download_release_archive(std::string_view registry_url, std::string_view package_name,
|
|
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};
|
|
bool yanked{false};
|
|
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. Yanked variants are hidden by default so
|
|
// callers never select them; pass `include_yanked` for inspection/listing.
|
|
[[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 = {},
|
|
bool include_yanked = false);
|
|
|
|
struct ReleaseInfo {
|
|
std::string name;
|
|
std::string version;
|
|
std::string sha256;
|
|
std::uint64_t size_bytes{0};
|
|
bool yanked{false};
|
|
std::optional<std::string> signature;
|
|
std::optional<std::string> public_key;
|
|
std::size_t binary_count{0};
|
|
};
|
|
|
|
// Queries GET /api/v1/packages/<name>/<version> on a VBS registry and returns the release
|
|
// metadata (digest, size, yank state, signature presence, binary variant count). A missing
|
|
// package or release is not_found; private packages without credentials are permission_denied.
|
|
[[nodiscard]] 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 = {});
|
|
|
|
// Lists package owners from GET /api/v1/packages/<name>/owners. Requires read permission on
|
|
// the package (or ownership): a missing package is not_found, missing credentials are
|
|
// permission_denied.
|
|
[[nodiscard]] 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 = {});
|
|
|
|
// 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>
|
|
download_binary_artifact(std::string_view url, std::string_view expected_sha256,
|
|
const std::filesystem::path &dest_file, const RegistryAuth &auth = {});
|
|
|
|
// Publishes a verified deterministic archive via PUT /api/v1/packages/<name>/<version>.
|
|
[[nodiscard]] Void::Result::Result<PublishReceipt, Void::Result::Error>
|
|
publish_package_archive(const PublishOptions &options);
|
|
|
|
} // namespace Void::Build::Package
|