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
@@ -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