feat(package,daemon): yank releases from the CLI; report workspace and lockfile in info
This commit is contained in:
1 parent
f5eb489e79
commit
1a4c062021
11 files changed
+249
-20
No files matched your search
+10
-4
@@ -2118,10 +2118,16 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
object.emplace("backends", JsonValue{std::move(backends)});
|
||||
object.emplace("project_root", JsonValue{options.project_root.string()});
|
||||
object.emplace("build_root", JsonValue{options.build_root.string()});
|
||||
object.emplace(
|
||||
"lock_root",
|
||||
JsonValue{
|
||||
(options.lock_root.empty() ? options.project_root : options.lock_root).string()});
|
||||
const auto lock_root = options.lock_root.empty() ? options.project_root : options.lock_root;
|
||||
object.emplace("lock_root", JsonValue{lock_root.string()});
|
||||
object.emplace("workspace", JsonValue{Config::is_workspace_root(options.project_root)});
|
||||
const auto lockfile_path = lock_root / "vbs.lock";
|
||||
std::error_code lockfile_ec;
|
||||
JsonValue::Object lockfile;
|
||||
lockfile.emplace("path", JsonValue{lockfile_path.string()});
|
||||
lockfile.emplace("exists",
|
||||
JsonValue{std::filesystem::is_regular_file(lockfile_path, lockfile_ec)});
|
||||
object.emplace("lockfile", JsonValue{std::move(lockfile)});
|
||||
object.emplace("socket", JsonValue{socket_path.string()});
|
||||
return {serialize_response(JsonValue{std::move(object)}), false};
|
||||
}
|
||||
|
||||
+42
-7
@@ -1297,8 +1297,8 @@ int execute_verify_command(const VerifyCmdOptions &opts) {
|
||||
<< *opts.version_arg << " sha256=" << *digest << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << "verified " << *opts.name_arg << '@' << *opts.version_arg
|
||||
<< " sha256=" << *digest << '\n';
|
||||
std::cout << "verified " << *opts.name_arg << '@' << *opts.version_arg << " sha256=" << *digest
|
||||
<< '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1347,6 +1347,26 @@ struct ReleasesCmdOptions {
|
||||
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
||||
};
|
||||
|
||||
int execute_releases_yank_command(const ReleasesCmdOptions &opts, bool unyank) {
|
||||
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) {
|
||||
std::cerr << "vbs releases yank: --registry, --name, and --version are required\n";
|
||||
return 2;
|
||||
}
|
||||
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
||||
auto state =
|
||||
Package::set_release_yanked(registry_url, *opts.name_arg, *opts.version_arg, !unyank, auth);
|
||||
if (!state) {
|
||||
std::cerr << "vbs releases yank: " << state.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << (*state ? "yanked " : "unyanked ") << *opts.name_arg << '@' << *opts.version_arg
|
||||
<< '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
int execute_releases_list_command(const ReleasesCmdOptions &opts) {
|
||||
const std::string registry_url = opts.registry_arg
|
||||
? *opts.registry_arg
|
||||
@@ -2558,6 +2578,7 @@ int execute_ide_command(std::string_view sub, const IdeCmdOptions &opts) {
|
||||
int main(int argc, char **argv) {
|
||||
const std::string cwd = std::filesystem::current_path().string();
|
||||
bool show_version = false;
|
||||
bool releases_unyank = false;
|
||||
bool verbose = false;
|
||||
bool quiet = false;
|
||||
|
||||
@@ -2747,8 +2768,8 @@ int main(int argc, char **argv) {
|
||||
publish_binary_opts.token_env, "VBS_REGISTRY_TOKEN");
|
||||
add_log_flags(publish_binary_cmd, false); // `-v` is `--version` on publish-binary.
|
||||
|
||||
auto &compdb_entries_root_cmd =
|
||||
root.subcommand("compdb-entries", "Query bounded entries from the published compile database");
|
||||
auto &compdb_entries_root_cmd = root.subcommand(
|
||||
"compdb-entries", "Query bounded entries from the published compile database");
|
||||
compdb_entries_root_cmd
|
||||
.option_default("--project", "-C", "Project directory", compdb_entries_opts.project_arg,
|
||||
cwd)
|
||||
@@ -2761,8 +2782,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
auto &verify_cmd =
|
||||
root.subcommand("verify", "Verify a detached Ed25519 signature over a package artifact");
|
||||
verify_cmd
|
||||
.option("--name", "-n", "Package name", verify_opts.name_arg)
|
||||
verify_cmd.option("--name", "-n", "Package name", verify_opts.name_arg)
|
||||
.option("--version", "-v", "Package version", verify_opts.version_arg)
|
||||
.option("--file", "-f", "Artifact file whose SHA-256 is signed", verify_opts.file_arg)
|
||||
.option("--signature", "", "Detached signature hex", verify_opts.signature_arg)
|
||||
@@ -2811,6 +2831,17 @@ int main(int argc, char **argv) {
|
||||
releases_opts.token_env, "VBS_REGISTRY_TOKEN");
|
||||
add_log_flags(releases_show_cmd, false); // `-v` is `--version` on releases show.
|
||||
|
||||
auto &releases_yank_cmd = releases_cmd.subcommand("yank", "Yank or unyank a release");
|
||||
releases_yank_cmd
|
||||
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
||||
releases_opts.registry_arg)
|
||||
.option("--name", "-n", "Package name", releases_opts.name_arg)
|
||||
.option("--version", "-v", "Release version", releases_opts.version_arg)
|
||||
.option_default("--token-env", "", "Environment variable holding bearer token",
|
||||
releases_opts.token_env, "VBS_REGISTRY_TOKEN")
|
||||
.flag("--unyank", "", "Restore a yanked release", releases_unyank);
|
||||
add_log_flags(releases_yank_cmd, false); // `-v` is `--version` on releases yank.
|
||||
|
||||
auto &binaries_cmd =
|
||||
root.subcommand("binaries", "Inspect prebuilt binary variants in a package registry");
|
||||
auto configure_binaries = [&](Void::Argparse::Parser &p) {
|
||||
@@ -3207,9 +3238,13 @@ int main(int argc, char **argv) {
|
||||
return execute_binaries_command(parsed.matched_command_path.at(1), binaries_opts);
|
||||
}
|
||||
if (cmd == "releases") {
|
||||
if (parsed.matched_command_path.at(1) == "show") {
|
||||
const std::string releases_sub = parsed.matched_command_path.at(1);
|
||||
if (releases_sub == "show") {
|
||||
return execute_releases_show_command(releases_opts);
|
||||
}
|
||||
if (releases_sub == "yank") {
|
||||
return execute_releases_yank_command(releases_opts, releases_unyank);
|
||||
}
|
||||
return execute_releases_list_command(releases_opts);
|
||||
}
|
||||
if (cmd == "tokens") {
|
||||
|
||||
@@ -742,9 +742,59 @@ fetch_tokens(std::string_view registry_url, const RegistryAuth &auth) {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
headers["Content-Type"] = "application/json";
|
||||
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) + "/yank";
|
||||
const std::string body = std::format("{{\"yanked\":{}}}", yanked ? "true" : "false");
|
||||
auto reply = send_http_request(*parsed_url, "POST", path, headers, body);
|
||||
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 POST {} 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 yank endpoint")};
|
||||
}
|
||||
const auto *object = std::get_if<JsonVal::Object>(&json->value);
|
||||
if (!object) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||
"registry yank response must be a JSON object")};
|
||||
}
|
||||
const auto it = object->find("yanked");
|
||||
if (it == object->end()) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||
"registry yank response is missing 'yanked'")};
|
||||
}
|
||||
const auto *flag = std::get_if<bool>(&it->second.value);
|
||||
if (!flag) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||
"registry yank 'yanked' must be a boolean")};
|
||||
}
|
||||
return *flag;
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
revoke_token(std::string_view registry_url, std::string_view token_id,
|
||||
const RegistryAuth &auth) {
|
||||
revoke_token(std::string_view registry_url, std::string_view token_id, const RegistryAuth &auth) {
|
||||
auto parsed_url = parse_registry_url(registry_url);
|
||||
if (!parsed_url) {
|
||||
return std::unexpected{parsed_url.error()};
|
||||
@@ -759,12 +809,12 @@ revoke_token(std::string_view registry_url, std::string_view token_id,
|
||||
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 DELETE {} failed with HTTP {}", path, reply->status))};
|
||||
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 DELETE {} failed with HTTP {}", path, reply->status))};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user