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
+56
-15
@@ -1154,6 +1154,36 @@ int execute_publish_binary_command(const PublishBinaryCmdOptions &opts) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct TokensCmdOptions {
|
||||
std::optional<std::string> registry_arg;
|
||||
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
||||
};
|
||||
|
||||
int execute_tokens_list_command(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";
|
||||
return 2;
|
||||
}
|
||||
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
||||
auto tokens = Package::fetch_tokens(registry_url, auth);
|
||||
if (!tokens) {
|
||||
std::cerr << "vbs tokens: " << tokens.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
for (const auto &token : *tokens) {
|
||||
std::cout << token.token_id << ' ' << (token.label.empty() ? "-" : token.label) << ' '
|
||||
<< token.username << ' ';
|
||||
for (std::size_t i = 0; i < token.scopes.size(); ++i) {
|
||||
std::cout << (i > 0 ? "," : "") << token.scopes[i];
|
||||
}
|
||||
std::cout << ' ' << (token.revoked ? "revoked" : "active") << '\n';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ReleasesCmdOptions {
|
||||
std::optional<std::string> registry_arg;
|
||||
std::optional<std::string> name_arg;
|
||||
@@ -1659,12 +1689,12 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
Util::json_quote(opts.profile_arg),
|
||||
Util::json_quote(opts.graph_format_arg));
|
||||
} else if (sub == "actions") {
|
||||
request_json = std::format(
|
||||
R"({{"op":"actions","profile":{},"limit":{}{}}})", Util::json_quote(opts.profile_arg),
|
||||
opts.limit_arg,
|
||||
opts.action_kind_arg
|
||||
? std::format(",\"kind\":{}", Util::json_quote(*opts.action_kind_arg))
|
||||
: std::string{});
|
||||
request_json =
|
||||
std::format(R"({{"op":"actions","profile":{},"limit":{}{}}})",
|
||||
Util::json_quote(opts.profile_arg), opts.limit_arg,
|
||||
opts.action_kind_arg
|
||||
? std::format(",\"kind\":{}", Util::json_quote(*opts.action_kind_arg))
|
||||
: std::string{});
|
||||
} else if (sub == "target_flags") {
|
||||
if (!opts.target_arg || opts.target_arg->empty()) {
|
||||
std::cerr << "vbs daemon target flags: --name must not be empty\n";
|
||||
@@ -1747,11 +1777,9 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
? std::format(",\"file\":{}", Util::json_quote(*opts.file_filter_arg))
|
||||
: std::string{});
|
||||
} else if (sub == "watch_poll") {
|
||||
request_json =
|
||||
opts.prefix_arg
|
||||
? std::format(R"({{"op":"watch_poll","prefix":{}}})",
|
||||
Util::json_quote(*opts.prefix_arg))
|
||||
: std::string{R"({"op":"watch_poll"})"};
|
||||
request_json = opts.prefix_arg ? std::format(R"({{"op":"watch_poll","prefix":{}}})",
|
||||
Util::json_quote(*opts.prefix_arg))
|
||||
: std::string{R"({"op":"watch_poll"})"};
|
||||
} else if (sub == "watch_wait") {
|
||||
std::int64_t timeout_ms = 0;
|
||||
const auto [ptr, ec] =
|
||||
@@ -2389,6 +2417,7 @@ int main(int argc, char **argv) {
|
||||
PublishBinaryCmdOptions publish_binary_opts;
|
||||
BinariesCmdOptions binaries_opts;
|
||||
ReleasesCmdOptions releases_opts;
|
||||
TokensCmdOptions tokens_opts;
|
||||
publish_opts.project_arg = cwd;
|
||||
BridgeCmdOptions bridge_opts;
|
||||
GcCmdOptions gc_opts;
|
||||
@@ -2552,6 +2581,15 @@ 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 &tokens_cmd = root.subcommand("tokens", "Inspect API tokens in a package registry");
|
||||
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);
|
||||
|
||||
auto &releases_cmd =
|
||||
root.subcommand("releases", "List published releases in a package registry");
|
||||
auto &releases_list_cmd = releases_cmd.subcommand("list", "List a package's releases");
|
||||
@@ -2838,9 +2876,9 @@ int main(int argc, char **argv) {
|
||||
daemon_cmd.subcommand("actions", "List lowered build actions via the daemon");
|
||||
configure_daemon_common(daemon_actions_cmd);
|
||||
daemon_actions_cmd
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg,
|
||||
"debug")
|
||||
.option("--kind", "", "Only actions of this kind (compile|link|archive|...)", daemon_opts.action_kind_arg)
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
||||
.option("--kind", "", "Only actions of this kind (compile|link|archive|...)",
|
||||
daemon_opts.action_kind_arg)
|
||||
.option_default("--limit", "", "Maximum actions returned (0-1000)", daemon_opts.limit_arg,
|
||||
"100");
|
||||
auto &daemon_graph_cmd =
|
||||
@@ -2871,7 +2909,7 @@ int main(int argc, char **argv) {
|
||||
"poll", "Poll pending project file changes (editor extension protocol)");
|
||||
configure_daemon_common(daemon_ide_poll_cmd);
|
||||
daemon_ide_poll_cmd.option("--prefix", "", "Only report changed paths under this prefix",
|
||||
daemon_opts.prefix_arg);
|
||||
daemon_opts.prefix_arg);
|
||||
auto &daemon_ide_wait_cmd = daemon_ide_cmd.subcommand(
|
||||
"wait", "Long-poll for project file changes (bounded, editor extension protocol)");
|
||||
configure_daemon_common(daemon_ide_wait_cmd);
|
||||
@@ -2969,6 +3007,9 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
return execute_releases_list_command(releases_opts);
|
||||
}
|
||||
if (cmd == "tokens") {
|
||||
return execute_tokens_list_command(tokens_opts);
|
||||
}
|
||||
if (cmd == "bridge") {
|
||||
return execute_bridge_command(bridge_opts);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user