feat(package,daemon): list registry tokens; list daemon targets
This commit is contained in:
1 parent
1aaece3231
commit
eb35bb6b6e
11 files changed
+326
-18
No files matched your search
@@ -675,6 +675,73 @@ fetch_package_owners(std::string_view registry_url, std::string_view package_nam
|
||||
return owners;
|
||||
}
|
||||
|
||||
Void::Result::Result<std::vector<TokenInfo>, Void::Result::Error>
|
||||
fetch_tokens(std::string_view registry_url, 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;
|
||||
}
|
||||
auto reply = send_http_request(*parsed_url, "GET", "/api/v1/tokens", headers, {});
|
||||
if (!reply) {
|
||||
return std::unexpected{reply.error()};
|
||||
}
|
||||
if (reply->status != 200) {
|
||||
return std::unexpected{make_error(
|
||||
reply->status == 401 || reply->status == 403
|
||||
? Void::System::SystemErrorCode::permission_denied
|
||||
: Void::System::SystemErrorCode::io_error,
|
||||
std::format("registry GET /api/v1/tokens failed with HTTP {}", 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 tokens 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<TokenInfo> tokens;
|
||||
const auto tit = root->find("tokens");
|
||||
if (tit == root->end()) {
|
||||
return tokens;
|
||||
}
|
||||
const auto *array = std::get_if<JsonVal::Array>(&tit->second.value);
|
||||
if (!array) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||
"registry tokens field must be a JSON array")};
|
||||
}
|
||||
for (const auto &entry : *array) {
|
||||
const auto *object = std::get_if<JsonVal::Object>(&entry.value);
|
||||
if (!object) {
|
||||
continue;
|
||||
}
|
||||
TokenInfo info;
|
||||
info.token_id = get_str(*object, "token_id");
|
||||
info.username = get_str(*object, "username");
|
||||
info.label = get_str(*object, "label");
|
||||
info.revoked = get_bool(*object, "revoked", false);
|
||||
if (const auto sit = object->find("scopes"); sit != object->end()) {
|
||||
if (const auto *scopes = std::get_if<JsonVal::Array>(&sit->second.value)) {
|
||||
for (const auto &scope : *scopes) {
|
||||
if (const auto *text = std::get_if<std::string>(&scope.value)) {
|
||||
info.scopes.push_back(*text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!info.token_id.empty()) {
|
||||
tokens.push_back(std::move(info));
|
||||
}
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
Reference in new issue
Block a user