feat(package,daemon): revoke registry tokens; allow daemon deps updates
This commit is contained in:
1 parent
eb35bb6b6e
commit
c7d2662cf2
11 files changed
+309
-13
No files matched your search
+31
-9
@@ -1156,18 +1156,34 @@ int execute_publish_binary_command(const PublishBinaryCmdOptions &opts) {
|
||||
|
||||
struct TokensCmdOptions {
|
||||
std::optional<std::string> registry_arg;
|
||||
std::optional<std::string> token_id_arg;
|
||||
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
||||
};
|
||||
|
||||
int execute_tokens_list_command(const TokensCmdOptions &opts) {
|
||||
int execute_tokens_command(std::string_view sub, const TokensCmdOptions &opts) {
|
||||
const std::string registry_url = opts.registry_arg
|
||||
? *opts.registry_arg
|
||||
: Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
|
||||
if (registry_url.empty()) {
|
||||
std::cerr << "vbs tokens list: --registry is required\n";
|
||||
std::cerr << "vbs tokens: --registry is required\n";
|
||||
return 2;
|
||||
}
|
||||
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
||||
|
||||
if (sub == "revoke") {
|
||||
if (!opts.token_id_arg || opts.token_id_arg->empty()) {
|
||||
std::cerr << "vbs tokens revoke: --token-id is required\n";
|
||||
return 2;
|
||||
}
|
||||
auto revoked = Package::revoke_token(registry_url, *opts.token_id_arg, auth);
|
||||
if (!revoked) {
|
||||
std::cerr << "vbs tokens revoke: " << revoked.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << "revoked " << *opts.token_id_arg << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto tokens = Package::fetch_tokens(registry_url, auth);
|
||||
if (!tokens) {
|
||||
std::cerr << "vbs tokens: " << tokens.error().message() << '\n';
|
||||
@@ -2582,13 +2598,19 @@ int main(int argc, char **argv) {
|
||||
add_log_flags(publish_binary_cmd, false); // `-v` is `--version` on publish-binary.
|
||||
|
||||
auto &tokens_cmd = root.subcommand("tokens", "Inspect API tokens in a package registry");
|
||||
auto configure_tokens = [&](Void::Argparse::Parser &parser) {
|
||||
parser
|
||||
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
||||
tokens_opts.registry_arg)
|
||||
.option_default("--token-env", "", "Environment variable holding bearer token",
|
||||
tokens_opts.token_env, "VBS_REGISTRY_TOKEN");
|
||||
add_log_flags(parser);
|
||||
};
|
||||
auto &tokens_list_cmd = tokens_cmd.subcommand("list", "List token metadata");
|
||||
tokens_list_cmd
|
||||
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
||||
tokens_opts.registry_arg)
|
||||
.option_default("--token-env", "", "Environment variable holding bearer token",
|
||||
tokens_opts.token_env, "VBS_REGISTRY_TOKEN");
|
||||
add_log_flags(tokens_list_cmd);
|
||||
configure_tokens(tokens_list_cmd);
|
||||
auto &tokens_revoke_cmd = tokens_cmd.subcommand("revoke", "Revoke an API token");
|
||||
configure_tokens(tokens_revoke_cmd);
|
||||
tokens_revoke_cmd.option("--token-id", "", "Token id to revoke", tokens_opts.token_id_arg);
|
||||
|
||||
auto &releases_cmd =
|
||||
root.subcommand("releases", "List published releases in a package registry");
|
||||
@@ -3008,7 +3030,7 @@ int main(int argc, char **argv) {
|
||||
return execute_releases_list_command(releases_opts);
|
||||
}
|
||||
if (cmd == "tokens") {
|
||||
return execute_tokens_list_command(tokens_opts);
|
||||
return execute_tokens_command(parsed.matched_command_path.at(1), tokens_opts);
|
||||
}
|
||||
if (cmd == "bridge") {
|
||||
return execute_bridge_command(bridge_opts);
|
||||
|
||||
Reference in new issue
Block a user